ASMESDC2018
/home/swerve/Github/sdc_2018/omni_robot/Motor.h
Go to the documentation of this file.
1 
8 #ifndef MOTOR_H_
9 #define MOTOR_H_
10 
11 #include <Encoder.h> // Teensy Encoder library
12 #include <Servo.h> // Teensy Servo library
13 // #include <PWMServo.h>
14 
15 // #include "Sensor.h" // Sensor class
16 
17 #define MOTOR_TYPE_DC 1
18 #define MOTOR_TYPE_BLDC 2
19 #define MOTOR_TYPE_SERVO 3
20 
21 #define MOTOR_TYPE_MIN 1
22 #define MOTOR_TYPE_MAX 3
23 
24 #define MOTOR_FORWARD 1
25 #define MOTOR_BRAKE 0
26 #define MOTOR_REVERSE -1
27 
28 #define MOTOR_SPEED_MIN 0
29 #define MOTOR_SPEED_MAX 100
30 
31 #define MOTOR_PWM_MIN 0
32 #define MOTOR_PWM_MAX 255
33 #define MOTOR_PPM_MIN 1200
34 #define MOTOR_PPM_MAX 1800
35 #define MOTOR_PPM_OFF 1500
36 
37 #define ESC_ARM_DELAY 10
38 
39 #define NO_ENCODER_PIN -1 // pin to supply encoder class if not using it
40 
41 struct MotorState {
42  int type; // motor type
43  int speed; // value between 0 and 100
44  int direction;
45 };
46 
47 struct MotorPins {
48  int PIN_PWM;
49  int PIN_A;
50  int PIN_B;
51 };
52 
53 class Motor {
54 public:
55 
56  bool ready = false;
57 
58  /* Constructor Functions */
59  Motor(int, int, int pin_a = 0, int pin_b = 0);
66  Motor(int, int, int, int, int, int);
73  /* Public Functions */
74  int setupMotor(int, int, int pin_a = 0, int pin_b = 0);
81  void run(int);
88  long getPosition(void);
95  double getCurrentUsage(void);
96 
97 protected:
98 
99  /* Protected Variables */
102 
103  bool ENCODER_SETUP = false;
104  bool CURRENT_SENSOR_SETUP = false;
105 
106 private:
107 
108  /* Provate Variables */
109  Servo _servo;
110  Encoder _encoder;
111  // Sensor _current_sensor;
112 
113  // volatile int _servo_update_it;
114 
115  /* Private Functions */
116  void _setupDCMotor(int, int);
124  void _setupBLDCMotor(void);
131  void _runDCMotor(int);
138  void _runBLDCMotor(int);
145  void _runServoMotor(int);
152  String _getMotorTypeName(void);
159 };
160 
161 #endif /* MOTOR_H_ */
162 
163 
int speed
Definition: Motor.h:43
int type
Definition: Motor.h:42
MotorPins pins
Definition: Motor.h:101
int PIN_A
Definition: Motor.h:49
Definition: Motor.h:53
int PIN_PWM
Definition: Motor.h:48
int direction
Definition: Motor.h:44
MotorState state
Definition: Motor.h:100
int PIN_B
Definition: Motor.h:50