Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

C++ client library
[Client Libraries]


Detailed Description

The C++ client (client_libs/c++) is generally the most comprehensive library, since it is used to test new features as they are implemented in the server. It is also the most widely used client library and thus the best debugged. Having said that, this client is not perfect, but should be straightforward to use by anyone familiar with C++.

The C++ library is built on a "service proxy" model in which the client maintains local objects that are proxies for remote services. There are two kinds of proxies: the special server proxy PlayerClient and the various device-specific proxies. Each kind of proxy is implemented as a separate class. The user first creates a PlayerClient proxy and uses it to establish a connection to a Player server. Next, the proxies of the appropriate device-specific types are created and initialized using the existing PlayerClient proxy. To make this process concrete, consider the following simple example (for clarity, we omit some error-checking):

#include <playerclient.h>
#include <stdlib.h> /* for exit() */

int main(int argc, char *argv[]) 
{
  PlayerClient robot("localhost");
  SonarProxy sp(&robot,0,'r');
  PositionProxy pp(&robot,0,'w');

  double newturnrate,newspeed;

  for(int i=0;i<1000;i++)  
  {
    if(robot.Read())
      exit(1);

    // print out sonars for fun
    sp.Print();

    // do simple collision avoidance
    if((sp.ranges[0] + sp.ranges[1]) < 
       (sp.ranges[6] + sp.ranges[7])) 
      newturnrate = DTOR(-20); // turn 20 degrees per second
    else
      newturnrate = DTOR(20);

    if(sp.ranges[3] < 0.500) 
      newspeed = 0;
    else 
      newspeed = 0.100;

    // command the motors
    pp.SetSpeed(newspeed,newturnrate);
  }
}

This program performs simple (and bad) sonar-based obstacle avoidance with a mobile robot . First, a PlayerClient proxy is created, using the default constructor to connect to the server listening at localhost:6665. Next, a SonarProxy is created to control the sonars and a PositionProxy to control the robot's motors. The constructors for these objects use the existing PlayerClient proxy to establish read ('r') access and write ('w') access to the 0th sonar and position devices, respectively. Finally, we enter a simple loop that reads the current sonar state and writes appropriate commands to the motors.


Modules

group Core functionality
group Proxies

Defines

#define RTOD(r)   ((r) * 180 / M_PI)
#define DTOR(d)   ((d) * M_PI / 180)
#define NORMALIZE(z)   atan2(sin(z), cos(z))


Define Documentation

#define RTOD  )     ((r) * 180 / M_PI)
 

Convert radians to degrees

#define DTOR  )     ((d) * M_PI / 180)
 

Convert degrees to radians

#define NORMALIZE  )     atan2(sin(z), cos(z))
 

Normalize angle to domain -pi, pi


Generated on Tue May 3 14:16:15 2005 for Player by doxygen 1.3.6