-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionExploreNavigateNear.cpp
61 lines (52 loc) · 2.12 KB
/
ActionExploreNavigateNear.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
#include "ActionExploreNavigateNear.h"
#include "NavBotUtil.h"
#include <math.h>
ActionExploreNavigateNear::ActionExploreNavigateNear(double threshold):
ArAction("exploreNavigateNear"),
mySonar(NULL),
myThreshold(threshold)
{
setNextArgument(ArArg("exploreNavigateNearThreshold", &myThreshold, "threshold at which to pivot around corners"));
}
void ActionExploreNavigateNear::setRobot(ArRobot *robot) {
ArAction::setRobot(robot);
robot->lock();
mySonar = robot->findRangeDevice("sonar");
robot->unlock();
if (!mySonar) {
ArLog::log(ArLog::Terse, "ActoinExploreNavigateNear::setRobot: Warning: Nosonardevice found, deactivating.");
deactivate();
}
}
ArActionDesired *ActionExploreNavigateNear::fire(ArActionDesired currentDesired) {
myDesired.reset();
if (!mySonar) {
deactivate();
return NULL;
}
mySonar->lockDevice();
leftOppositeLength = mySonar->currentReadingPolar(81, 99, &leftOppositeOffsetAngle);
rightOppositeLength = mySonar->currentReadingPolar(-99, -81, &rightOppositeOffsetAngle);
mySonar->unlockDevice();
if (leftOppositeLength < rightOppositeLength) {
oppositeLength = leftOppositeLength;
oppositeOffsetAngle = leftOppositeOffsetAngle;
direction = 1;
mySonar->lockDevice();
hypotenuseLength = mySonar->currentReadingPolar(0, 50, &hypotenuseOffsetAngle);
mySonar->unlockDevice();
} else {
oppositeLength = rightOppositeLength;
oppositeOffsetAngle = rightOppositeOffsetAngle;
direction = -1;
mySonar->lockDevice();
hypotenuseLength = mySonar->currentReadingPolar(-50, 0, &hypotenuseOffsetAngle);
mySonar->unlockDevice();
}
hypotenuseOppositeAngle = abs(oppositeOffsetAngle) - abs(hypotenuseOffsetAngle);
if (oppositeLength < myThreshold && hypotenuseLength > (utils::getHypotenuseLength(oppositeLength, hypotenuseOppositeAngle)*2)) {
oppositeAjdacentAngle = utils::getOppositeAngle(hypotenuseLength, oppositeLength);
myDesired.setDeltaHeading((oppositeAjdacentAngle*2)*direction);
}
return &myDesired;
}