-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointTurnToPosition.cpp
More file actions
47 lines (39 loc) · 1.23 KB
/
PointTurnToPosition.cpp
File metadata and controls
47 lines (39 loc) · 1.23 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
/** Command to do a point turn to a position between the supply
* and storage tubes
* @author Hans Johnson
* @date Oct. 2015
**/
#include "PointTurnToPosition.h"
/** Constructor
* @param turn Turning rate of robot
* @param duration Length of time in milliseconds to turn for
**/
PointTurnToPosition::PointTurnToPosition(float turn, int duration, bool sideA) : PausableCommand("PointTurnToPosition") {
curie = Robot::getInstance();
_turn = turn;
_duration = duration;
_sideA = sideA;
}
void PointTurnToPosition::initialize() {
//Calculate the direction to turn based on the current position, and closest Supply
_bitmask = curie->reactorLink->getSupplyAvailabilityByte();
deltaPos = curie->tubeProcessor->getFreshRodTube(_bitmask, _sideA)-curie->currentPos;
if (deltaPos != 0) {
_turn = -1*abs(_turn)*deltaPos/abs(deltaPos);
}
}
void PointTurnToPosition::execute() {
curie->drivetrain->pointTurn(_turn);
}
void PointTurnToPosition::end() {
curie->drivetrain->stop();
}
bool PointTurnToPosition::isFinished() {
return getTime() > _duration;
}
/** Stop the drivetrain while paused **/
void PointTurnToPosition::onPause() {
curie->drivetrain->stop();
}
/** Nothing special on resume **/
void PointTurnToPosition::onResume() {}