lsp_test_position2d.cc
Go to the documentation of this file.
00001 #include "lsp_test_position2d.hh"
00002 
00003 
00004 using namespace lspTest;
00005 
00006 void Position2D::setUp() {
00007         connect();
00008         posProxy = playerc_position2d_create( client, 0 );
00009         CPPUNIT_ASSERT( playerc_position2d_subscribe( posProxy, PLAYER_OPEN_MODE ) == 0 );
00010         
00011         // ignore initial messages on proxy subscription
00012         for ( int i = 0; i < 10; i++ )
00013                 playerc_client_read( client );
00014 }
00015 
00016 void Position2D::tearDown() {
00017         CPPUNIT_ASSERT( playerc_position2d_unsubscribe( posProxy ) == 0 );
00018         playerc_position2d_destroy( posProxy );
00019         disconnect();
00020 }
00021 
00022 void Position2D::testGeom() {
00023         CPPUNIT_ASSERT( playerc_position2d_get_geom( posProxy ) == 0 );
00024         
00025         // values from pioneer.inc
00026         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom pose (x)", -0.04, posProxy->pose[0], Delta );
00027         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom pose (y)", 0, posProxy->pose[1], Delta );
00028         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom pose (angle)", 0, posProxy->pose[2], Delta );
00029         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom size (x)", 0.44, posProxy->size[0], Delta );
00030         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "geom size (y)", 0.38, posProxy->size[1], Delta );
00031 }
00032 
00033 void Position2D::testData() {
00034         playerc_client_read( client );  
00035         
00036         // verify that we're getting new data
00037         posProxy->info.fresh = 0;
00038         playerc_client_read( client );
00039         CPPUNIT_ASSERT_MESSAGE( "laser updating", posProxy->info.fresh == 1 );
00040         
00041         CPPUNIT_ASSERT( posProxy->info.datatime > 0 );
00042         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (x)", 0, posProxy->px, Delta );
00043         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (y)", 0, posProxy->py, Delta );
00044         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (angle)", 0, posProxy->pa, Delta );
00045         CPPUNIT_ASSERT( posProxy->stall == 0 );
00046         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "forward velocity", 0, posProxy->vx, Delta );
00047         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "horizontal velocity", 0, posProxy->vy, Delta );
00048         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "angular velocity", 0, posProxy->va, Delta );
00049 }
00050 
00051 void Position2D::testMove() {
00052         // Back the robot into the wall
00053         CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, -3, 0, 0, 1 ) == 0 );
00054         // for 500ms, read and stop
00055         usleep( 500000 );
00056         playerc_client_read( client );
00057         CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, 0, 0, 0, 1 ) == 0 );
00058 
00059         // Make sure it moved back
00060         CPPUNIT_ASSERT( posProxy->px < 0 );
00061         // Make sure it didn't turn or move sideways
00062         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (y)", 0, posProxy->py, Delta );
00063         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (angle)", 0, posProxy->pa, Delta );
00064         // Make sure it's hitting the wall
00065         CPPUNIT_ASSERT( posProxy->stall == 1 );
00066         // Make sure the velocity is as specified
00067         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "forward velocity", -3, posProxy->vx, Delta );
00068         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "horizontal velocity", 0, posProxy->vy, Delta );
00069         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "angular velocity", 0, posProxy->va, Delta );
00070         
00071         // Start turning left at 45 deg. / sec
00072         CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, 0, 0, M_PI/2, 1 ) == 0 );
00073         // for 500ms, stop, and read
00074         usleep( 500000 );
00075         CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, 0, 0, 0, 1 ) == 0 );
00076         usleep( 500000 );
00077         playerc_client_read( client );
00078 
00079         // Make sure odom still reads negative
00080         CPPUNIT_ASSERT( posProxy->px < 0 );
00081         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (y)", 0, posProxy->py, Delta );
00082         // See if we turned in the right direction
00083         CPPUNIT_ASSERT( posProxy > 0 );
00084         // Shouldn't be stalled
00085         CPPUNIT_ASSERT_EQUAL( 0, posProxy->stall );
00086         // Should have stopped
00087         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "forward velocity", 0, posProxy->vx, Delta );
00088         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "horizontal velocity", 0, posProxy->vy, Delta );
00089         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "angular velocity", 0, posProxy->va, Delta );
00090         
00091         // Save position and try position based movement toward start position
00092         double oldx = posProxy->px;
00093         double olda = posProxy->pa;
00094         CPPUNIT_ASSERT( playerc_position2d_set_cmd_pose( posProxy, 0, 0, 0, 1 ) == 0 );
00095         sleep( 5 );
00096         CPPUNIT_ASSERT( playerc_position2d_set_cmd_vel( posProxy, 0, 0, 0, 1 ) == 0 );
00097         usleep( 500000 );
00098         playerc_client_read( client );
00099         
00100         // Make sure we've made progress
00101         CPPUNIT_ASSERT( posProxy->px > oldx );
00102         CPPUNIT_ASSERT( posProxy->pa < olda );
00103         CPPUNIT_ASSERT( posProxy->stall == 0 );
00104         // Verify that we've stopped
00105         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "forward velocity", 0, posProxy->vx, 0.1 );
00106         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "horizontal velocity", 0, posProxy->vy, 0.1 );
00107         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "angular velocity", 0, posProxy->va, 0.1 );
00108         
00109         // Reset odometer and check position
00110         playerc_client_read( client );
00111         CPPUNIT_ASSERT( playerc_position2d_set_odom( posProxy, 0, 0, 0 ) == 0 );
00112         usleep( 500000 );
00113         playerc_client_read( client );
00114         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (x)", 0, posProxy->px, Delta );
00115         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (y)", 0, posProxy->py, Delta );
00116         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "pose (angle)", 0, posProxy->pa, Delta ); 
00117 }


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