LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
DriveESC.h
1 #ifndef DRIVE_ESC_H_
2 #define DRIVE_ESC_H_
3 
4 #include <WPILib.h>
5 #include <utility>
6 #include <string>
7 
8 #include "LRTSpeedController.h"
9 #include "../Sensors/LRTEncoder.h"
10 #include "../Utils/AsyncPrinter.h"
11 #include "../Logging/Loggable.h"
12 
16 class DriveESC : public Loggable
17 {
18 public:
19 
26  DriveESC(LRTSpeedController* esc, LRTEncoder *encoder, std::string name);
27 
35  DriveESC(LRTSpeedController* esc1, LRTSpeedController* esc2, LRTEncoder *encoder, std::string name);
36 
37 
41  ~DriveESC();
42 
47  void SetDutyCycle(float dutycycle);
48 
53  void SetForwardCurrentLimit(float limit);
54 
59  void SetReverseCurrentLimit(float limit);
60 
64  void ResetCache();
65 
66  void Disable();
67 
68  void Log();
69 
70 private:
71  struct BrakeAndDutyCycle
72  {
73  float dutyCycle;
74  float braking;
75  };
76 
77  float DitheredBraking(float dutyCycle, float speed);
78  float CurrentLimit(float dutyCycle, float speed);
79  BrakeAndDutyCycle CalculateBrakeAndDutyCycle(float target_speed, float current_speed);
80 
81  LRTEncoder* m_encoder;
82  LRTSpeedController* m_controller1;
83  LRTSpeedController* m_controller2;
84 
85  float m_dutyCycle;
86 
87  int m_cycle_count;
88 
89  float m_forwardCurrentLimit; // % stall current for acceleration
90  float m_reverseCurrentLimit; // % stall current for reversing direction
91 
92  bool m_shouldBrakeThisCycle;
93 
94 };
95 
96 #endif /* ESC_H_ */