ptest.c
Go to the documentation of this file.
1 /*
2  * File: ptest.c
3  * Desc: Player test program for use with libstageplugin
4  * Author: Richard Vaughan
5  * License: GPL v2
6  * CVS info:
7  * $Source: /home/tcollett/stagecvs/playerstage-cvs/code/stage/examples/libplayerc/ptest.c,v $
8  * $Author: pooya $
9  * $Revision: 1.1 $
10  */
11 
12 #include <stdio.h>
13 #include <string.h>
14 #include <libplayerc/playerc.h>
15 
16 const char* USAGE = \
17 "Usage: ptest <string>\n"
18 " where <string> is comprised of any number of the following characters:\n"
19 " 'p' - position\n"
20 " 'l' - laser";
21 
22 int test_laser( playerc_client_t* client )
23 {
24  // Create and subscribe to a laser device.
25  playerc_laser_t *laser =
26  playerc_laser_create(client, 0);
27  if (playerc_laser_subscribe(laser, PLAYER_OPEN_MODE))
28  return -1;
29 
30  int i;
31  for(i = 0; i < 100; i++)
32  {
33  // Wait for new data from server
34  playerc_client_read(client);
35  }
36 
37  playerc_laser_unsubscribe(laser);
38  playerc_laser_destroy(laser);
39 
40  return 0;
41 }
42 
43 int test_position( playerc_client_t* client )
44 {
45  // Create and subscribe to a position device.
46  playerc_position2d_t *position =
47  playerc_position2d_create(client, 0);
48  if (playerc_position2d_subscribe(position, PLAYER_OPEN_MODE))
49  return -1;
50 
51  // Make the robot spin!
52  if (playerc_position2d_set_cmd_vel(position, 0, 0, DTOR(40.0), 1) != 0)
53  return -1;
54 
55  int i;
56  for( i = 0; i < 100; i++)
57  {
58  // Wait for new data from server
59  playerc_client_read(client);
60 
61  // Print current robot pose
62  printf("position : %f %f %f\n",
63  position->px, position->py, position->pa);
64  }
65 
66  playerc_position2d_unsubscribe(position);
67  playerc_position2d_destroy(position);
68 
69  return 0;
70 }
71 
72 int main(int argc, const char **argv)
73 {
74  const char *host;
75  int port;
76  playerc_client_t *client;
77 
78  host = "localhost";
79  port = 6665;
80 
81  if( argc != 2 )
82  {
83  puts( USAGE );
84  return(-1);
85  }
86 
87  printf( "Attempting to connect to a Player server on %s:%d\n",
88  host, port );
89 
90  // Create a client and connect it to the server.
91  client = playerc_client_create(NULL, host, port);
92  if (playerc_client_connect(client) != 0)
93  {
94  puts( "Failed. Quitting." );
95  return -1;
96  }
97 
98  puts( "Connected. Running tests." );
99 
100  // run through the input string
101  size_t len = strlen( argv[1] );
102  size_t i;
103  for( i=0; i<len; i++ )
104  switch( argv[1][i] )
105  {
106  case 'p':
107  test_position(client);
108  break;
109 
110  case 'l':
111  test_laser(client);
112  break;
113 
114  default:
115  printf( "unrecognized test '%c'\n", argv[1][i] );
116  }
117 
118  puts( "Disconnecting" );
119  // Shutdown
120  playerc_client_disconnect(client);
121  playerc_client_destroy(client);
122 
123  puts( "Done." );
124  return 0;
125 }
const char * USAGE
Definition: ptest.c:16
static int argc
int test_position(playerc_client_t *client)
Definition: ptest.c:43
static char * argv
int test_laser(playerc_client_t *client)
Definition: ptest.c:22
int main(int argc, const char **argv)
Definition: ptest.c:72


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 Mon Jun 10 2019 15:06:09