1 #include <libplayerc++/playerc++.h> 8 #define VSPEED 0.4 // meters per second 9 #define WGAIN 1.0 // turn speed gain 10 #define SAFE_DIST 0.3 // meters 11 #define SAFE_ANGLE 0.4 // radians 21 using namespace PlayerCc;
27 robot.SetDataMode( PLAYER_DATAMODE_PULL );
28 robot.SetReplaceRule(
true );
30 Position2dProxy** ppp =
new Position2dProxy*[
gPop];
31 SonarProxy** spp =
new SonarProxy*[
gPop];
32 Graphics2dProxy** gpp =
new Graphics2dProxy*[
gPop];
34 for( uint i=0; i<
gPop; i++ )
36 ppp[i] =
new Position2dProxy( &robot , i );
39 spp[i] =
new SonarProxy( &robot, i );
42 gpp[i] =
new Graphics2dProxy( &robot, i );
45 spp[i]->RequestGeom();
54 for( uint i=0; i<
gPop; i++ )
55 if( spp[i]->IsFresh() )
62 int num_ranges = spp[i]->GetCount();
63 for(
int s=0;
s<num_ranges;
s++ )
65 player_pose3d_t spose = spp[i]->GetPose(
s);
66 double srange = spp[i]->GetScan(
s);
68 dx += srange * cos( spose.pyaw );
69 dy += srange * sin( spose.pyaw );
72 double resultant_angle = atan2( dy, dx );
75 double forward_speed = 0.0;
76 double side_speed = 0.0;
77 double turn_speed =
WGAIN * resultant_angle;
79 int forward = num_ranges/2 -1 ;
81 if( (spp[i]->GetScan(forward-1) >
SAFE_DIST) &&
83 (spp[i]->GetScan(forward+1) >
SAFE_DIST) &&
90 ppp[i]->SetSpeed( forward_speed, side_speed, turn_speed );
94 if( forward_speed > 0 )
95 gpp[i]->Color( 0,255,0,0 );
97 gpp[i]->Color( 0,255,255,0 );
99 player_point_2d_t pts[2];
106 gpp[i]->DrawPolyline( pts, 2 );
111 catch (PlayerCc::PlayerError e)
113 std::cerr << e << std::endl;
int parse_args(int argc, char **argv)
uint gPort(PlayerCc::PLAYER_PORTNUM)
std::string gHostname(PlayerCc::PLAYER_HOSTNAME)
int main(int argc, char **argv)