-
Notifications
You must be signed in to change notification settings - Fork 0
/
MotorManager.h
88 lines (82 loc) · 1.8 KB
/
MotorManager.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <AFMotor.h>
#include "Constants.h"
/**
MotorManager class is used for managing the motors of the robot.
It uses the Adafruit Motor Shield library for controlling the motors.
*/
class MotorManager {
private:
AF_DCMotor mFrontLeft;
AF_DCMotor mFrontRight;
AF_DCMotor mRearLeft;
AF_DCMotor mRearRight;
int mSpeed;
public:
// Initialise the Motors (AF_DCMotors)
MotorManager()
: mFrontLeft(MOTOR_FRONT_LEFT),
mFrontRight(MOTOR_FRONT_RIGHT),
mRearLeft(MOTOR_REAR_LEFT),
mRearRight(MOTOR_REAR_RIGHT) {
mSpeed = 255;
}
/**
Set the speeds of the motors to given speed
Must be called inside the Setup function
@param motorSpeed Set the Speed of the motors. Ranges from 0 to 255, 0 being stop.
*/
void Init(int motorSpeed) {
mSpeed = motorSpeed;
mFrontLeft.setSpeed(mSpeed);
mFrontRight.setSpeed(mSpeed);
mRearLeft.setSpeed(mSpeed);
mRearRight.setSpeed(mSpeed);
Stop();
}
/**
Move the Robot
*/
void MoveForward() {
mFrontLeft.run(FORWARD);
mFrontRight.run(FORWARD);
mRearLeft.run(FORWARD);
mRearRight.run(FORWARD);
}
/**
Move the Robot
*/
void MoveBackward() {
mFrontLeft.run(BACKWARD);
mFrontRight.run(BACKWARD);
mRearLeft.run(BACKWARD);
mRearRight.run(BACKWARD);
}
/**
Move the Robot
*/
void MoveLeft() {
mFrontLeft.run(BACKWARD);
mFrontRight.run(FORWARD);
mRearLeft.run(BACKWARD);
mRearRight.run(FORWARD);
}
/**
Move the Robot
*/
void MoveRight() {
mFrontLeft.run(FORWARD);
mFrontRight.run(BACKWARD);
mRearLeft.run(FORWARD);
mRearRight.run(BACKWARD);
}
/**
Stop the Robot
*/
void Stop() {
mFrontLeft.run(RELEASE);
mFrontRight.run(RELEASE);
mRearLeft.run(RELEASE);
mRearRight.run(RELEASE);
}
};