16 double have[4][4] = { { 90, 180, 180, 180 },
21 double need[4][4] = { { -120, -180, 180, 180 },
22 { -90, -120, 180, 90 },
23 { -90, -90, 180, 180 },
24 { -90, -180, -90, -90 } };
26 double refuel[4][4] = { { 0, 0, 45, 120 },
27 { 0, -90, -60, -160 },
28 { -90, -90, 180, 180 },
29 { -90, -180, -90, -90 } };
55 : pos(pos), laser((
ModelRanger *)pos->GetChild(
"ranger:1")),
57 fiducial((
ModelFiducial *)pos->GetUnusedModelOfType(
"fiducial")),
60 source(source), sink(sink), avoidcount(0),
62 work_get(0), work_put(0), charger_ahoy(false), charger_bearing(0), charger_range(0),
63 charger_heading(0), mode(
MODE_WORK), at_dest(false)
107 double a_goal =
normalize(charger_bearing);
116 if (charger_range > 0.5) {
117 if (!ObstacleAvoid()) {
125 if (charger_range < 0.08)
147 const meters_t back_off_distance = 0.3;
148 const meters_t back_off_speed = -0.05;
151 if (charger_range < back_off_distance)
169 charger_range > back_off_distance)
175 bool obstruction =
false;
180 double minleft = 1e6;
181 double minright = 1e6;
184 const std::vector<meters_t> &scan = laser->
GetSensors()[0].ranges;
186 uint32_t sample_count = scan.size();
188 for (uint32_t i = 0; i < sample_count; i++) {
190 printf(
"%.3f ", scan[i]);
192 if ((i > (sample_count / 4)) && (i < (sample_count - (sample_count / 4)))
195 puts(
" obstruction!");
205 if (i > sample_count / 2)
206 minleft = std::min(minleft, scan[i]);
208 minright = std::min(minright, scan[i]);
213 printf(
"minleft %.3f \n", minleft);
214 printf(
"minright %.3f\n ", minright);
217 if (obstruction || stop || (avoidcount > 0)) {
219 printf(
"Avoid %d\n", avoidcount);
225 if (avoidcount < 1) {
230 if (minleft < minright) {
233 printf(
"turning right %.2f\n", -
avoidturn);
237 printf(
"turning left %2f\n", +
avoidturn);
251 if (!ObstacleAvoid()) {
262 int x = (pose.
x + 8) / 4;
263 int y = (pose.
y + 8) / 4;
309 switch (robot->
mode) {
325 default: printf(
"unrecognized mode %d\n",
int(robot->
mode));
353 if (hypot(7 - pose.
x, 7 - pose.
y) < 1.0) {
375 std::vector<ModelFiducial::Fiducial> &fids = mod->
GetFiducials();
377 for (
unsigned int i = 0; i < fids.size(); i++) {
void SetTurnSpeed(double a)
unsigned int GetFlagCount() const
PowerPack * FindPowerPack() const
The Stage library uses its own namespace.
std::vector< Fiducial > & GetFiducials()
fiducial detector?
static int PositionUpdate(ModelPosition *pos, Robot *robot)
void Init(int *argc, char **argv[])
const double minfrontdistance
int(* model_callback_t)(Model *mod, void *user)
int FiducialUpdate(ModelFiducial *fid, robot_t *robot)
static int FiducialUpdate(ModelFiducial *mod, Robot *robot)
const std::vector< Sensor > & GetSensors() const
Robot(ModelPosition *pos, Model *source, Model *sink)
double normalize(double a)
int LaserUpdate(Model *mod, robot_t *robot)
void AddCallback(callback_type_t type, model_callback_t cb, void *user)
int PositionUpdate(Model *mod, robot_t *robot)
void PushFlag(Flag *flag)
double ProportionRemaining() const
static int LaserUpdate(ModelRanger *, Robot *robot)
radians_t a
rotation about the z axis.
Model * GetModel(const std::string &name) const
const unsigned int payload