1 #include <libplayerc++/playerc++.h> 8 #define POP 100 // population size 9 #define VSPEED 0.4 // meters per second 10 #define WGAIN 1.0 // turn speed gain 11 #define SAFE_DIST 0.3 // meters 12 #define SAFE_ANGLE 0.4 // radians 22 using namespace PlayerCc;
28 robot.SetDataMode( PLAYER_DATAMODE_PULL );
29 robot.SetReplaceRule(
true );
31 Position2dProxy pp( &robot,
gIndex );
32 SonarProxy sp( &robot,
gIndex );
33 Graphics2dProxy gp( &robot,
gIndex );
42 for(
int i=0; i<
POP; i++ )
47 int num_ranges = sp.GetCount();
48 for(
int s=0;
s<num_ranges;
s++ )
50 player_pose3d_t spose = sp.GetPose(
s);
51 double srange = sp.GetScan(
s);
53 dx += srange * cos( spose.pyaw );
54 dy += srange * sin( spose.pyaw );
58 double resultant_angle = atan2( dy, dx );
61 double forward_speed = 0.0;
62 double side_speed = 0.0;
63 double turn_speed =
WGAIN * resultant_angle;
66 int forward = num_ranges/2 -1 ;
69 if( (sp.GetScan(forward-1) >
SAFE_DIST) &&
78 pp.SetSpeed( forward_speed, side_speed, turn_speed );
82 if( forward_speed > 0 )
83 gp.Color( 0,255,0,0 );
85 gp.Color( 0,255,255,0 );
87 player_point_2d_t pts[2];
94 gp.DrawPolyline( pts, 2 );
99 catch (PlayerCc::PlayerError e)
101 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)