ptest.c
Go to the documentation of this file.
00001 /*
00002  * File: ptest.c
00003  * Desc: Player test program for use with libstageplugin
00004  * Author: Richard Vaughan
00005  * License: GPL v2
00006  * CVS info:
00007  *  $Source: /home/tcollett/stagecvs/playerstage-cvs/code/stage/examples/libplayerc/ptest.c,v $
00008  *  $Author: pooya $
00009  *  $Revision: 1.1 $
00010  */
00011 
00012 #include <stdio.h>
00013 #include <string.h>
00014 #include <libplayerc/playerc.h>
00015 
00016 const char* USAGE = \
00017 "Usage: ptest <string>\n"
00018 " where <string> is comprised of any number of the following characters:\n"
00019 "  'p' - position\n"
00020 "  'l' - laser";
00021  
00022 int test_laser( playerc_client_t* client )
00023 {
00024   // Create and subscribe to a laser device.
00025   playerc_laser_t *laser = 
00026     playerc_laser_create(client, 0);
00027   if (playerc_laser_subscribe(laser, PLAYER_OPEN_MODE))
00028     return -1;
00029   
00030   int i;  
00031   for(i = 0; i < 100; i++)
00032     {
00033       // Wait for new data from server
00034       playerc_client_read(client);      
00035     } 
00036   
00037   playerc_laser_unsubscribe(laser);
00038   playerc_laser_destroy(laser);
00039   
00040   return 0;
00041 }
00042 
00043 int test_position( playerc_client_t* client )
00044 {
00045   // Create and subscribe to a position device.
00046   playerc_position2d_t *position = 
00047     playerc_position2d_create(client, 0);
00048   if (playerc_position2d_subscribe(position, PLAYER_OPEN_MODE))
00049     return -1;
00050   
00051   // Make the robot spin!
00052   if (playerc_position2d_set_cmd_vel(position, 0, 0, DTOR(40.0), 1) != 0)
00053     return -1;
00054   
00055   int i;
00056   for( i = 0; i < 100; i++)
00057     {
00058       // Wait for new data from server
00059       playerc_client_read(client);
00060       
00061       // Print current robot pose
00062       printf("position : %f %f %f\n",
00063              position->px, position->py, position->pa);
00064     } 
00065   
00066   playerc_position2d_unsubscribe(position);
00067   playerc_position2d_destroy(position);
00068 
00069   return 0;
00070 }
00071 
00072 int main(int argc, const char **argv)
00073 {
00074   const char *host;
00075   int port;
00076   playerc_client_t *client;
00077 
00078   host = "localhost";
00079   port = 6665;
00080   
00081   if( argc != 2 )
00082     {
00083       puts( USAGE );
00084       return(-1);
00085     }
00086   
00087   printf( "Attempting to connect to a Player server on %s:%d\n",
00088               host, port );
00089 
00090   // Create a client and connect it to the server.
00091   client = playerc_client_create(NULL, host, port);
00092   if (playerc_client_connect(client) != 0)
00093     {
00094       puts( "Failed. Quitting." );
00095       return -1;
00096     }
00097   
00098   puts( "Connected. Running tests." );
00099 
00100   // run through the input string 
00101   size_t len = strlen( argv[1] );
00102   size_t i;
00103   for( i=0; i<len; i++ )
00104     switch( argv[1][i] )
00105       {
00106       case 'p':
00107         test_position(client);
00108         break;
00109         
00110       case 'l':
00111         test_laser(client);
00112         break;
00113 
00114       default:
00115         printf( "unrecognized test '%c'\n",  argv[1][i] );
00116       }
00117 
00118   puts( "Disconnecting" );
00119   // Shutdown
00120   playerc_client_disconnect(client);
00121   playerc_client_destroy(client);
00122 
00123   puts( "Done." );
00124   return 0;
00125 }


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57