Proper Segway Client

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Proper Segway Client

Brandon Sights
I have been trying for days to get our Segway RMP to accept position
commands.  Can anyone give me an example of the proper way to write a
C++ Client to send commands to the segwayrmp driver?

This is what I have:

PlayerClient robot("localhost");
   
   int check = 0;
   double turnrate = 20.0;

   if(robot.SetFrequency(1000))
     printf("Frequency not set.\n");

   if(robot.SetDataMode(PLAYER_DATAMODE_PUSH_ASYNC))
     printf("Data Mode Not Set.\n");
 
   /* Request access to the position interface. */
   PositionProxy segway(&robot, 0, 'a');
   
   /* Not sure if this has any effect, but it won't move. */
   check = segway.SetStatus(PLAYER_POSITION_MOTOR_POWER_REQ, 1);
   if( check < 0)
      printf("Error Setting Motor State using SetStatus.\n");

   check = segway.SetMotorState(1);
   if( check < 0)
      printf("Error Setting Motor State.\n");

   check = segway.SetSpeed(0, DTOR(turn_speed));    
   if( check < 0)
      printf("Error setting segway speed!!!\n");



Thank you,
Brandon



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Playerstage-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-users
Reply | Threaded
Open this post in threaded view
|

Re: Proper Segway Client

Brian Gerkey

On Sep 29, 2005, at 4:14 PM, Brandon Sights wrote:

> I have been trying for days to get our Segway RMP to accept position
> commands.  Can anyone give me an example of the proper way to write a
> C++ Client to send commands to the segwayrmp driver?

As noted here:

http://playerstage.sourceforge.net/doc/Player-current/player-html/ 
group__player__driver__segwayrmp.php

the segwayrmp driver has a watchdog timer.  It will stop the robot if  
a command hasn't been received in the last 1/2 second or so.  So you  
need to continuously send commands to get the robot to move.

     brian.

--
Brian Gerkey
[hidden email]
http://gerkey.org





-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Playerstage-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-users
Reply | Threaded
Open this post in threaded view
|

Re: Proper Segway Client

Brandon Sights
In reply to this post by Brandon Sights
In the example that I put here I left out the continuous loop that
writes data to the segway at ~10Hz.  Since I wrote this email, I updated
my client as follows:

  int check = 0;
  double turn_speed = 20.0;
 
  player_device_id_t segway_id;
 
  struct player_position_cmd segway_pos_cmd;
  memset(&segway_pos_cmd, 0, sizeof(segway_pos_cmd));
 
  struct timeval current;
  struct timeval last;
  double dt = 0;
 
  memset(&current, 0, sizeof(current));
  memset(&last, 0, sizeof(last));
 
   /* Connect to the Player server at "localhost" on default port 6665. */  
   PlayerClient robot("localhost");
   
   if(robot.SetFrequency(1000))
     printf("Frequency not set.\n");

   if(robot.SetDataMode(PLAYER_DATAMODE_PUSH_ASYNC))
     printf("Data Mode Not Set.\n");
 
   /* Request access to the position interface. */
   PositionProxy segway(&robot, 0, 'a');
   
   check = segway.SetStatus(PLAYER_POSITION_MOTOR_POWER_REQ, 1);
   
   check = segway.SetMotorState(1);
   if( check < 0)
      printf("Error Setting Motor State.\n");
 
   //check = segway.SetSpeed(0, turn_speed);
   
   if( check < 0)
      printf("Error setting segway speed!!!\n");
   
   int i = 0;
   
   /* Find the segway id number */
   for(int j = 0; j < robot.id_count; j++)
   {
      if( (strncmp( "segwayrmp", robot.drivernames[j], 9)) == 0 )
      {
         segway_id = robot.ids[j];
         printf("segway is in position %d\n", j);
      }
   }
   
   while(true)
   {
       i++;
       last = current;
       gettimeofday(&current, NULL);
       dt = (current.tv_sec - last.tv_sec) + (.000001*(current.tv_usec -
      last.tv_usec));
       printf("dt = %f\r", dt);
       
       
       segway_pos_cmd.xpos = (int32_t)htonl(0);
       segway_pos_cmd.ypos = (int32_t)htonl(0);
       segway_pos_cmd.yaw  = (int32_t)htonl(0);
       segway_pos_cmd.xspeed = (int32_t)htonl(0);
       segway_pos_cmd.yspeed = (int32_t)htonl(0);
       segway_pos_cmd.yawspeed = htonl((int32_t)DTOR(turn_speed));
       segway_pos_cmd.state = (uint8_t)1;
       segway_pos_cmd.type = (uint8_t)0;
       
       check = robot.Write(segway_id, (const char*)&segway_pos_cmd,
sizeof(segway_pos_cmd));
       
       //check = segway.SetSpeed(0, DTOR(turn_speed));
       
       if( check < 0)
         printf("Error setting segway speed.\n");
       
      /* Read the latest data from the Player server. */
      if (robot.Read())
      {
         printf("err: could not read data from Player server");
         exit(1);
      }

      if( !(i%10))
      {
         segway.Print();
      }
     
      usleep(5000);
     
     
  } /* End of forever . . . */


And it still does not move....Any tips?  Also, we tried to make it work
using playerjoy without any luck. Could it simply be our CAN card (we
are using a kvaser card)? We were able to get it to work with an older
version of player and playerjoy, maybe we should get an older version again?

Thank you again,
Brandon

----- Original Message -----
From: Brian Gerkey <[hidden email]>
Date: Thursday, September 29, 2005 4:24 pm
Subject: Re: [Playerstage-users] Proper Segway Client

>
> On Sep 29, 2005, at 4:14 PM, Brandon Sights wrote:
>
> > I have been trying for days to get our Segway RMP to accept position
> > commands.  Can anyone give me an example of the proper way to
> write a
> > C++ Client to send commands to the segwayrmp driver?
>
> As noted here:
>
> http://playerstage.sourceforge.net/doc/Player-current/player-html/ 
> group__player__driver__segwayrmp.php
>
> the segwayrmp driver has a watchdog timer.  It will stop the robot
> if  
> a command hasn't been received in the last 1/2 second or so.  So
> you  
> need to continuously send commands to get the robot to move.
>
>     brian.
>
> --
> Brian Gerkey
> [hidden email]
> http://gerkey.org
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads,
> discussions,and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Playerstage-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/playerstage-users
>



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Playerstage-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-users
Reply | Threaded
Open this post in threaded view
|

Re: Proper Segway Client

Brian Gerkey

On Sep 29, 2005, at 4:58 PM, Brandon Sights wrote:

> In the example that I put here I left out the continuous loop that
> writes data to the segway at ~10Hz.
>
> And it still does not move....Any tips?  Also, we tried to make it  
> work
> using playerjoy without any luck. Could it simply be our CAN card (we
> are using a kvaser card)? We were able to get it to work with an older
> version of player and playerjoy, maybe we should get an older  
> version again?

That's odd.  Which older version works?  Perhaps you could diff the  
driver (server/drivers/mixed/rmp/segwayrmp.cc) to see what, if  
anything changed between the two versions.

     brian.

--
Brian Gerkey
[hidden email]
http://gerkey.org





-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Playerstage-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-users