-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineFollowOverLines.cpp
More file actions
64 lines (56 loc) · 2.04 KB
/
LineFollowOverLines.cpp
File metadata and controls
64 lines (56 loc) · 2.04 KB
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
/** Line follow over the appropriate amount of lines given the
* robot's current position and desired position relative to
* the storage/supply tubes.
* @author Hans Johnson
* @date Oct. 2015
**/
#include "LineFollowOverLines.h"
/* Constructor */
/** Line follows, counting lines until the robot is at the position specified in newPos parameter, based on the inital position of the robot
* @param speed Linefollowing speed
* @param drive Drivetrain object to use for driving, must be initialized
* @param currentPos Position of robot on the field at the beginning of the command
* @param newPos Position the robot should be at when the command finishes
**/
LineFollowOverLines::LineFollowOverLines(float speed, bool sideA) : PausableCommand("LineFollowOverLines"){
_speed = speed;
curie = Robot::getInstance();
_sideA = sideA;
}
void LineFollowOverLines::initialize() {
_bitmask = curie->reactorLink->getSupplyAvailabilityByte();
linesToCross = abs(curie->tubeProcessor->getFreshRodTube(_bitmask, _sideA) - curie->currentPos);
lastCrossTime = getTime();
}
/**
* Commands the robot to follow the line at the specified speed
*@param speed Speed that the robot should line follow at
**/
void LineFollowOverLines::execute() {
curie->drivetrain->drive(_speed, 0.08*curie->lineTracker->lineError());
if (curie->lineTracker->isAtCross()) {
//Check if it was not previously on the line, and has surpassed the time heuristic
if (!onLine && (getTime() - lastCrossTime) > 400) {
linesCrossed++;
lastCrossTime = getTime();
}
onLine = true;
} else {
onLine = false;
}
}
void LineFollowOverLines::end() {
curie->drivetrain->stop();
}
/** Command has finished when it has crossed the appropriate
* amount of lines or just needs to go to the next line
**/
bool LineFollowOverLines::isFinished() {
return (linesCrossed == linesToCross) || (linesToCross == 1);
}
/** Stop the drivetrain while paused **/
void LineFollowOverLines::onPause() {
curie->drivetrain->stop();
}
/** Do nothing special on resume **/
void LineFollowOverLines::onResume() {}