42 population_size(popsize),
43 robots(new
Robot[population_size])
51 for(
unsigned int idx = 0; idx < population_size; idx++)
54 std::stringstream name;
63 robots[idx].position = posmod;
68 robots[idx].position->GetChild(
"ranger:0" )
72 robots[idx].ranger = rngmod;
89 const double vspeed = 0.4;
90 const double wgain = 1.0;
91 const double safe_dist = 0.1;
92 const double safe_angle = 0.3;
97 for(
unsigned int idx = 0; idx < population_size; idx++)
105 typedef std::vector<Stg::ModelRanger::Sensor>::const_iterator sensor_iterator;
106 const std::vector<Stg::ModelRanger::Sensor> sensors = rgr->
GetSensors();
108 for(sensor_iterator sensor = sensors.begin(); sensor != sensors.end(); sensor++)
111 const double srange = (*sensor).ranges[0];
112 const double angle = (*sensor).pose.a;
114 dx += srange * std::cos(angle);
115 dy += srange * std::sin(angle);
125 const double resultant_angle = std::atan2( dy, dx );
128 const unsigned int forward_idx = sensors.size() / 2u - 1u;
130 const double forwardm_range = sensors[forward_idx - 1].ranges[0];
131 const double forward_range = sensors[forward_idx + 0].ranges[0];
132 const double forwardp_range = sensors[forward_idx + 1].ranges[0];
135 (forwardm_range > safe_dist / 5.0) &&
136 (forward_range > safe_dist) &&
137 (forwardp_range > safe_dist / 5.0) &&
138 (std::abs(resultant_angle) < safe_angle)
144 const double forward_speed = front_clear ? vspeed : 0.0;
146 const double side_speed = 0.0;
149 const double turn_speed = wgain * resultant_angle;
152 robots[idx].position->SetSpeed( forward_speed, side_speed, turn_speed );
166 puts(
"Usage: stest <worldfile> <number of robots>" );
170 const int popsize = atoi(argv[2] );
178 world.
Load( argv[1] );
181 Logic logic(popsize);
Stg::ModelPosition * position
unsigned int population_size
Logic(unsigned int popsize)
void Init(int *argc, char **argv[])
void AddUpdateCallback(world_callback_t cb, void *user)
virtual void Load(const std::string &filename)
const std::vector< Sensor > & GetSensors() const
Stg::ModelRanger * ranger
int main(int argc, char *argv[])
void connect(Stg::World *world)
Model * GetModel(const std::string &name) const
static int Callback(Stg::World *world, void *userarg)