Robobo
DCMotor.h
1 #ifndef ROBOBO_MOTOR_INCLUDED
2 #define ROBOBO_MOTOR_INCLUDED
3 
4 #include "Arduino.h"
5 #include "MotorI.h"
6 #include "ActiveObject.h"
7 #include "ControlStrategy.h"
8 #include "PID.h"
9 
10 
17 class DCMotor : public ActiveObject, public MotorI
18 {
19  public:
22  void setPinModes();
23 
25  void reset();
26 
27  DCMotor( uint8_t encoderAPinV,
28  uint8_t encoderBPinV,
29  uint8_t hBridgeAPinV,
30  uint8_t hBridgeBPinV,
31  uint8_t voltagePinV,
32  ControlStrategy *strategy);
33 
34  // Pins
35  uint8_t encoderAPin;
36  uint8_t encoderBPin;
37  uint8_t hBridgeAPin;
38  uint8_t hBridgeBPin;
39  uint8_t voltagePin;
40 
41  // State
42  uint8_t encoderAVal;
43  uint8_t encoderBVal;
44  uint8_t encoderAPrevVal;
45  uint8_t encoderBPrevVal;
46  int32_t encoderPosition;
47  int32_t requestedPosition;
48  int8_t direction;
49 
50  // PID Controller parameters
51  float kP;
52  float kI;
53  int32_t integral;
54 
55  // Interface functions
56  void setPosition(int32_t);
57  int32_t getPosition();
58  void stop(void);
59  void enableReports(TickType_t period);
60 
61  // these methods are to run in timer expiration
62  void reportMethod(void);
63  void updateControl(void);
64 
66  void encoderInterrupt(void);
67 
68  private:
69 
70  ControlStrategy *control;
71 
72  void calculatePID(void);
73  void setDirectionRight(void);
74  void setDirectionLeft(void);
75  void setVoltage(uint8_t val);
76 
77 
78  TimerHandle_t triggerTimer;
79  TimerHandle_t reportTimer;
80 
81  friend int main(void);
82 
83 };
84 
85 #endif
Definition: MotorI.h:5
void setPinModes()
Definition: DCMotor.cpp:52
Definition: ControlStrategy.h:4
void reset()
Definition: DCMotor.cpp:61
friend int main(void)
Application entry point.
Definition: arm_class_marks_example_f32.c:139
Definition: ActiveObject.h:9
void encoderInterrupt(void)
Definition: DCMotor.cpp:84
Definition: DCMotor.h:17