-
Notifications
You must be signed in to change notification settings - Fork 0
/
RobotMotors.cpp
58 lines (45 loc) · 1.28 KB
/
RobotMotors.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
/*
* RobotMotors.cpp
*
*/
#include "RobotMotors.h"
#include "Arduino.h"
RobotMotors::RobotMotors() {
leftMotor = new AF_DCMotor(leftDriveID, MOTOR34_64KHZ);
rightMotor = new AF_DCMotor(rightDriveID, MOTOR34_64KHZ);
}
RobotMotors::~RobotMotors() {
fullStop();
delete leftMotor;
delete rightMotor;
}
void RobotMotors::processTask() {
if(reachedDeadline()) {
fullStop();
taskDeadline = 0;
}
}
void RobotMotors::driveForward(uint8_t speed, uint16_t duration) {
runDrives(speed, duration, FORWARD, FORWARD);
}
void RobotMotors::driveBackward(uint8_t speed, uint16_t duration) {
runDrives(speed, duration, BACKWARD, BACKWARD);
}
void RobotMotors::turnRight(uint8_t speed, uint16_t duration) {
runDrives(speed, duration, FORWARD, BACKWARD);
}
void RobotMotors::turnLeft(uint8_t speed, uint16_t duration) {
runDrives(speed, duration, BACKWARD, FORWARD);
}
void RobotMotors::runDrives(uint8_t speed, uint16_t duration,
uint8_t leftDirection, uint8_t rightDirection) {
leftMotor->setSpeed(speed);
rightMotor->setSpeed(speed);
leftMotor->run(leftDirection);
rightMotor->run(rightDirection);
scheduleTimedTask(duration);
}
void RobotMotors::fullStop() {
leftMotor->run(RELEASE);
rightMotor->run(RELEASE);
}