-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.cpp
More file actions
30 lines (25 loc) · 872 Bytes
/
robot.cpp
File metadata and controls
30 lines (25 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "Robot.hpp"
bool CanSeeBeacon (Robot *robot) { return -1 < robot->IRPower (); }
void MainTask (Robot *robot) {
while (!robot->HasQuit ()) {
if (CanSeeBeacon (robot)) {
float ir_dir = robot->IRDirection ();
float ir_power = robot->IRPower ();
if (ir_power > 240) { // close enough
robot->SetMotors (0, 0);
break;
} else {
float speed = 20.0;
float left = speed / 2.0; // ??
float right = speed / 2.0; //?
robot->SetMotors (left, right);
}
INFORM ("The IR Beacon is at location " + ToStr (ir_dir) +
" and power " + ToStr (ir_power));
} else {
INFORM ("Can not see beacon.");
break;
}
robot->Wait (0.1);
}
}