-
Notifications
You must be signed in to change notification settings - Fork 1
/
motor.h
52 lines (39 loc) · 1.24 KB
/
motor.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
#ifndef MOTOR_CONTROLLER_H
#define MOTOR_CONTROLLER_H
#include <Arduino.h>
#include <TimerOne.h>
#include "consts.h"
#include "receiver.h"
#include "fake_receiver.h"
class MotorController
{
private:
const int frontRightPin;
const int backRightPin;
const int backLeftPin;
const int frontLeftPin;
int frontRightThrust;
int backRightThrust;
int backLeftThrust;
int frontLeftThrust;
void writeThrust(int pin, int thrust);
bool DISABLE_MOTORS = false;
unsigned long lastThrustUpdateTime;
static const unsigned long THRUST_TIMEOUT = 200000; // 200ms timeout in microseconds
bool isInitialized;
void checkAndDisableMotors();
static MotorController *instance;
static void checkMotorsWrapper();
public:
MotorController(int frPin, int brPin, int blPin, int flPin);
void initialize();
bool setThrust(int motor, int thrust);
int getThrust(int motor) const;
bool setAllThrust(int frThrust, int brThrust, int blThrust, int flThrust);
void getAllThrust(int &frThrust, int &brThrust, int &blThrust, int &flThrust) const;
void disableMotors();
void enableMotors(ReceiverController &receiver);
void enableMotors(FakeReceiverController &receiver);
void setupTimer();
};
#endif