-
Notifications
You must be signed in to change notification settings - Fork 14
/
RobotMonitor.cpp
67 lines (56 loc) · 2.13 KB
/
RobotMonitor.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "RobotMonitor.h"
RobotMonitor::RobotMonitor(ArRobot *r, ArServerHandlerPopup *ps) :
robot(r),
popupServer(ps),
motorsDisabledPopupID(0),
motorsDisabledPopupInfo( NULL,
"Robot Motors Are Disabled",
"The robot's motors are disabled",
ArServerHandlerPopup::WARNING,
1, // default button ID
0, // escape button ID
-1, // timeout
NULL, // timeout message
"Enable Motors", "Enabling Motors...",
"Ignore", "Ignore"
),
handleMotorsDisabledPopupResponseCB(this, &RobotMonitor::handleMotorsDisabledResponse),
robotMonitorCB(this, &RobotMonitor::robotMonitorTask)
{
robot->addUserTask("arnlServerRobotMonitor", 30, &robotMonitorCB);
}
RobotMonitor::~RobotMonitor()
{
robot->remUserTask(&robotMonitorCB);
}
void RobotMonitor::handleMotorsDisabledResponse(ArTypes::Byte4 popupID, int button)
{
if(button == 0)
{
ArLog::log(ArLog::Normal, "Enabling motors...");
robot->enableMotors();
}
popupServer->closePopup(motorsDisabledPopupID, "Closing motor disable popup.");
motorsDisabledPopupID = 0;
}
// This function is called as a robot task (every 100ms) to check on the robot
// state and perform feedback and interact with user as needed.
void RobotMonitor::robotMonitorTask()
{
// a way for user to re-enable motors if disabled -- show a popup dialog in
// MobileEyes.
if(motorsDisabledPopupID == 0 && robot && !robot->areMotorsEnabled() && robot->isConnected())
{
motorsDisabledPopupID = popupServer->createPopup(&motorsDisabledPopupInfo, &handleMotorsDisabledPopupResponseCB);
}
// Set LX wheel light pattern based on robot activity. You could add more
// conditions/light patterns here if you want.
if(robot->isEStopPressed())
robot->comDataN(ArCommands::WHEEL_LIGHT, "\x02\0\0\0", 4); // pattern #2, flash red
else if(!robot->areMotorsEnabled())
robot->comDataN(ArCommands::WHEEL_LIGHT, "\x03\0\0\0", 4); // pattern #3, flash yellow
else if(fabs(robot->getVel()) < 5)
robot->comDataN(ArCommands::WHEEL_LIGHT, "\x0A\0\0\0", 4); // pattern #10, slow blue flash
else
robot->comDataN(ArCommands::WHEEL_LIGHT, "\x09\0\0\0", 4); // pattern 9, blue sweep.
}