player_kerl.cpp File Reference
Functions to control a robot in Player.
More...
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
#include <libplayerc/playerc.h>
#include "common_kerl.h"
#include "player_kerl.h"
#include <string>
#include <sstream>
#include <iostream>
#include <map>
|
Functions |
int | createRobot (char *address, int port, int index, char *robotID) |
int | destroyRobot (char *robotID) |
int | move (char *robotID, double speed, double rotation) |
int | rotateDegrees (char *robotID, double degrees) |
int | update (char *robotID) |
int | getPosition (char *robotID, double *px, double *py, double *pa) |
int | laserResultsSize (char *robotID, int *numberOfResults) |
int | readLaserResults (char *robotID, double *laserResults, double *laserBearings, int *size) |
int | moveCoordinate (char *robotID, double px, double py, double pa) |
int | travelDistance (char *robotID, double distance) |
int | queryRobot (char *robotID, ClientQuery *query) |
PlayerClient * | _getClient (char *robotID) |
Variables |
map< string, PlayerClient * > | clients |
| A map containing all our bots identifing them by their name.
|
Detailed Description
Functions to control a robot in Player.
- Author:
- Thomas Lorentsen, Sten Gruener
This holds the player side of the code. Provides functions to control a player robot This should not contain any erlang related code
Each robot will be contained in a map where there key is its name or robot identification. Using a name provides a more user friendly way of identifiying robots as a user could choose a name they wish to use.
Function Documentation
- Parameters:
-
| robotID | an identification for the robot returns a client with this name |
| robotID | an identification for the robot returns a client with this name returns null if client does not exist |
int createRobot |
( |
char * |
address, |
|
|
int |
port, |
|
|
int |
index, |
|
|
char * |
robotID | |
|
) |
| | |
- Parameters:
-
| address | the address player is listening on |
| port | the port player is listening on |
| index | is the internal playerstage id |
| robotID | an identification for the robot |
- Returns:
- 0 on success Use this to create a new robot connection. Once the robot has been created it can then be controlled with any other function. A robotID identifies the robot created so it can be controlled. It must be a unique id otherwise this function will return a none zero. Function will need to allocate memory needed and add the robot to a map of robots.
If needed this function will also initate devices so that they can be used
int destroyRobot |
( |
char * |
robotID |
) |
|
- Parameters:
-
| robotID | an identification for the robot |
- Returns:
- 0 on success This will destroy the robot so it can no longer be controlled until it is recreated. Function will need to reallocate the memory used by the robot after it has been stopped.
int getPosition |
( |
char * |
robotID, |
|
|
double * |
px, |
|
|
double * |
py, |
|
|
double * |
pa | |
|
) |
| | |
- Parameters:
-
| robotID | an identification for the robot |
| px | the x position read |
| py | the y position read |
| pa | the angle read |
- Returns:
- 0 if successfully set values Sets the values pass to the positions read from the odometer
int laserResultsSize |
( |
char * |
robotID, |
|
|
int * |
numberOfResults | |
|
) |
| | |
- Parameters:
-
| robotID | an identification for the robot |
| numberOfResults | sets this value to the number of lasers Simply sets the amount of lasers there are to read. This will need to be called before calling readLaserResults so you can allocate memory for lasers |
int move |
( |
char * |
robotID, |
|
|
double |
speed, |
|
|
double |
rotation | |
|
) |
| | |
- Parameters:
-
| robotID | an identification for the robot |
| speed | The speed the robot will move in m/s |
| rotation | in rad/s |
- Returns:
- 0 on success Tells the robot to move forward at a certain speed. To stop the robot moving forward pass 0 as the speed.
- Parameters:
-
| robotID | an identification for the robot |
| speed | The speed the robot will move in m/s |
| rotation | in deg/s |
- Returns:
- 0 on success Tells the robot to move forward at a certain speed. To stop the robot moving forward pass 0 as the speed.
int moveCoordinate |
( |
char * |
robotID, |
|
|
double |
px, |
|
|
double |
py, |
|
|
double |
pa | |
|
) |
| | |
- Parameters:
-
| robotID | an identification for the robot |
| px | the wished x position |
| py | the wished y position |
| pa | the wished angle in radiants |
Moves robot to wished coordinates.
- Parameters:
-
| robotID | Robot identifier |
| query | Query to run Runs a query on a robot and returns a tuple containing useful information about it. |
Runs a query on a robot and returns a tuple containing useful information about it.
int readLaserResults |
( |
char * |
robotID, |
|
|
double * |
laserResults, |
|
|
double * |
laserBearings, |
|
|
int * |
size | |
|
) |
| | |
- Parameters:
-
| robotID | an identification for the robot |
| laserResults | the array to put laser results into |
| laserBearings | the bearings of each laser |
| size | the number of laser results to read, use laserResultsSize to find this value Sets both the laser result and the bearing Remember to allocate sizeof(double)*size in laserResults and laserBearings before passing them through |
int rotateDegrees |
( |
char * |
robotID, |
|
|
double |
degrees | |
|
) |
| | |
- Parameters:
-
| robotID | an identification for the robot |
| degrees | the amount of degrees to rotate by Rotates the robot by this amount of degrees. This is relative to robot current position This function is none blocking so you will have to detect when the robot has stopped rotating. |
int travelDistance |
( |
char * |
robotID, |
|
|
double |
distance | |
|
) |
| | |
- Parameters:
-
| robotID | an identification for the robot |
| distance | distance to go |
Lets robot move in current direction for given distance.
int update |
( |
char * |
robotID |
) |
|
- Parameters:
-
| robotID | an identification for the robot |
- Returns:
- 0 on success Notifies Player to update devices. This function is none blocking so you may not get updated results as soon as you read a device.