lsp_test_position2d.cc
Go to the documentation of this file.
1 #include "lsp_test_position2d.hh"
2 
3 
4 using namespace lspTest;
5 
7  connect();
8  posProxy = playerc_position2d_create( client, 0 );
9  CPPUNIT_ASSERT( playerc_position2d_subscribe( posProxy, PLAYER_OPEN_MODE ) == 0 );
10 
11  // ignore initial messages on proxy subscription
12  for ( int i = 0; i < 10; i++ )
13  playerc_client_read( client );
14 }
15 
17  CPPUNIT_ASSERT( playerc_position2d_unsubscribe( posProxy ) == 0 );
18  playerc_position2d_destroy( posProxy );
19  disconnect();
20 }
21 
23  CPPUNIT_ASSERT( playerc_position2d_get_geom( posProxy ) == 0 );
24 
25  // values from pioneer.inc
26  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom pose (x)", -0.04, posProxy->pose[0], Delta );
27  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom pose (y)", 0, posProxy->pose[1], Delta );
28  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom pose (angle)", 0, posProxy->pose[2], Delta );
29  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom size (x)", 0.44, posProxy->size[0], Delta );
30  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom size (y)", 0.38, posProxy->size[1], Delta );
31 }
32 
34  playerc_client_read( client );
35 
36  // verify that we're getting new data
37  posProxy->info.fresh = 0;
38  playerc_client_read( client );
39  CPPUNIT_ASSERT_MESSAGE( "laser updating", posProxy->info.fresh == 1 );
40 
41  CPPUNIT_ASSERT( posProxy->info.datatime > 0 );
42  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (x)", 0, posProxy->px, Delta );
43  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (y)", 0, posProxy->py, Delta );
44  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (angle)", 0, posProxy->pa, Delta );
45  CPPUNIT_ASSERT( posProxy->stall == 0 );
46  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "forward velocity", 0, posProxy->vx, Delta );
47  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "horizontal velocity", 0, posProxy->vy, Delta );
48  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "angular velocity", 0, posProxy->va, Delta );
49 }
50 
52  // Back the robot into the wall
53  CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, -3, 0, 0, 1 ) == 0 );
54  // for 500ms, read and stop
55  usleep( 500000 );
56  playerc_client_read( client );
57  CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, 0, 0, 0, 1 ) == 0 );
58 
59  // Make sure it moved back
60  CPPUNIT_ASSERT( posProxy->px < 0 );
61  // Make sure it didn't turn or move sideways
62  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (y)", 0, posProxy->py, Delta );
63  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (angle)", 0, posProxy->pa, Delta );
64  // Make sure it's hitting the wall
65  CPPUNIT_ASSERT( posProxy->stall == 1 );
66  // Make sure the velocity is as specified
67  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "forward velocity", -3, posProxy->vx, Delta );
68  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "horizontal velocity", 0, posProxy->vy, Delta );
69  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "angular velocity", 0, posProxy->va, Delta );
70 
71  // Start turning left at 45 deg. / sec
72  CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, 0, 0, M_PI/2, 1 ) == 0 );
73  // for 500ms, stop, and read
74  usleep( 500000 );
75  CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, 0, 0, 0, 1 ) == 0 );
76  usleep( 500000 );
77  playerc_client_read( client );
78 
79  // Make sure odom still reads negative
80  CPPUNIT_ASSERT( posProxy->px < 0 );
81  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (y)", 0, posProxy->py, Delta );
82  // See if we turned in the right direction
83  CPPUNIT_ASSERT( posProxy > 0 );
84  // Shouldn't be stalled
85  CPPUNIT_ASSERT_EQUAL( 0, posProxy->stall );
86  // Should have stopped
87  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "forward velocity", 0, posProxy->vx, Delta );
88  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "horizontal velocity", 0, posProxy->vy, Delta );
89  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "angular velocity", 0, posProxy->va, Delta );
90 
91  // Save position and try position based movement toward start position
92  double oldx = posProxy->px;
93  double olda = posProxy->pa;
94  CPPUNIT_ASSERT( playerc_position2d_set_cmd_pose( posProxy, 0, 0, 0, 1 ) == 0 );
95  sleep( 5 );
96  CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, 0, 0, 0, 1 ) == 0 );
97  usleep( 500000 );
98  playerc_client_read( client );
99 
100  // Make sure we've made progress
101  CPPUNIT_ASSERT( posProxy->px > oldx );
102  CPPUNIT_ASSERT( posProxy->pa < olda );
103  CPPUNIT_ASSERT( posProxy->stall == 0 );
104  // Verify that we've stopped
105  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "forward velocity", 0, posProxy->vx, 0.1 );
106  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "horizontal velocity", 0, posProxy->vy, 0.1 );
107  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "angular velocity", 0, posProxy->va, 0.1 );
108 
109  // Reset odometer and check position
110  playerc_client_read( client );
111  CPPUNIT_ASSERT( playerc_position2d_set_odom( posProxy, 0, 0, 0 ) == 0 );
112  usleep( 500000 );
113  playerc_client_read( client );
114  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (x)", 0, posProxy->px, Delta );
115  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (y)", 0, posProxy->py, Delta );
116  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (angle)", 0, posProxy->pa, Delta );
117 }
static const double Delta
playerc_client_t * client
playerc_position2d_t * posProxy


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