LRT13  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
AsyncCANJaguar.h
1 #ifndef PROXIED_CAN_JAGUAR_H_
2 #define PROXIED_CAN_JAGUAR_H_
3 
4 #include <taskLib.h>
5 
6 #include <WPILib/CANJaguar.h>
7 #include <vector>
8 
9 #include "../ComponentData/RobotData.h"
10 
11 #include "../Process/SynchronizedProcess.h"
12 
13 #include "../Utils/Util.h"
14 #include "../Utils/PrintInConstructor.h"
15 #include "../Utils/CachedValue.h"
16 
17 #include "../Log/Loggable.h"
18 
19 #include "LRTSpeedController.h"
20 
31 class AsyncCANJaguar : public SynchronizedProcess, public CANJaguar, public Loggable, public LRTSpeedController
32 {
33 public:
34  // collection flags
35  const static uint32_t SPEEDREF = (1 << 0);
36  const static uint32_t POSREF = (1 << 1);
37  const static uint32_t PID = (1 << 2);
38  const static uint32_t CTRLMODE = (1 << 3);
39  const static uint32_t BUSVOLT = (1 << 4);
40  const static uint32_t OUTVOLT = (1 << 5);
41  const static uint32_t OUTCURR = (1 << 6);
42  const static uint32_t TEMP = (1 << 7);
43  const static uint32_t POS = (1 << 8);
44  const static uint32_t SPEED = (1 << 9);
45  const static uint32_t FWDLIMOK = (1 << 10);
46  const static uint32_t REVLIMOK = (1 << 11);
47  const static uint32_t PWRCYCLE = (1 << 12);
48  const static uint32_t EXPIRE = (1 << 13);
49 
50 private:
51  string m_task_name;
52  PrintInConstructor m_print_ctor_dtor;
53  int m_channel;
54  char* m_name;
55 
56  CachedValue<float> m_setpoint;
61 
62  CachedValue<float> m_pid_p;
63  CachedValue<float> m_pid_i;
64  CachedValue<float> m_pid_d;
65 
66  CachedValue<float> m_enable_control;
67  bool m_should_disable_control;
68 
69  CachedValue<float> m_voltage_ramp_rate;
70  CachedValue<float> m_max_output_voltage;
71  CachedValue<float> m_fault_time;
72  CachedValue<float> m_expiration;
73  CachedValue<int> m_encoder_codes_per_rev;
74  CachedValue<int> m_potentiometer_turns;
75 
76  CachedValue<float> m_forward_limit_position;
77  CachedValue<float> m_reverse_limit_position;
78  volatile bool m_should_disable_position_limits;
79 
80  volatile uint32_t m_collection_flags;
81  volatile float m_output_voltage;
82  volatile float m_output_current;
83  volatile float m_position;
84  volatile float m_p, m_i, m_d;
85  volatile SpeedReference m_speed_ref;
86  volatile PositionReference m_position_ref;
87  volatile ControlMode m_ctrl_mode;
88  volatile float m_bus_voltage;
89  volatile float m_temperature;
90  volatile float m_speed;
91  volatile bool m_fwd_limit_ok;
92  volatile bool m_rev_limit_ok;
93  volatile bool m_pwr_cyc;
94  volatile float m_expire;
95 
96  static data::RobotData::RobotState m_game_state;
97  data::RobotData::RobotState m_last_game_state;
98 
99  int m_index;
100 
101  void println(const char * str);
102 
103 public:
109  AsyncCANJaguar(UINT8 channel, const char* name);
110 
114  ~AsyncCANJaguar();
115 
119  static vector<AsyncCANJaguar*> jaguar_vector;
120 
125 
130  virtual void SetDutyCycle(float duty_cycle);
131 
136  void SetPosition(float position);
137 
142  void SetVelocity(float velocity);
143 
144  int GetChannel();
145 
146  virtual char* GetName();
147 protected:
151  INT32 Tick();
152 private:
153  //don't let external objects control the ESC with the ambiguous Set() cmd
154  void Set(float setpoint, UINT8 syncGroup = 0);
155 
156 public:
163  void SetPID(double p, double i, double d);
164 
169  virtual void ConfigNeutralMode(LRTSpeedController::NeutralMode mode);
170 
175  void SetSpeedReference(SpeedReference reference);
176 
181  void ChangeControlMode(CANJaguar::ControlMode mode);
182 
187  void EnableControl(double encoderInitialPosition = 0.0);
188 
193  void SetVoltageRampRate(double rampRate);
194 
199  void ConfigEncoderCodesPerRev(UINT16 codesPerRev);
200 
205  void ConfigPotentiometerTurns(UINT16 turns);
206 
212  void ConfigSoftPositionLimits(double forwardLimitPosition,
213  double reverseLimitPosition);
214 
219 
223  void DisableControl();
224 
229  void ConfigMaxOutputVoltage(double voltage);
230 
235  void ConfigFaultTime(float faultTime);
236 
241  void SetExpiration(float timeout);
242 
247  void SetPositionReference(CANJaguar::PositionReference reference);
248 
253  void addCollectionFlags(uint32_t flags = 0xffffffff);
254 
259  void removeCollectionFlags(uint32_t flags = 0xffffffff);
260 
265  void setCollectionFlags(uint32_t flags);
266 
271  double GetP()
272  {
273  return m_p;
274  }
275 
280  double GetI()
281  {
282  return m_i;
283  }
284 
289  double GetD()
290  {
291  return m_d;
292  }
293 
298  SpeedReference GetSpeedReference()
299  {
300  return m_speed_ref;
301  }
302 
307  PositionReference GetPositionReference()
308  {
309  return m_position_ref;
310  }
311 
316  ControlMode GetControlMode()
317  {
318  return m_ctrl_mode;
319  }
320 
326  {
327  return m_bus_voltage;
328  }
329 
335  {
336  return m_output_voltage;
337  }
338 
344  {
345  return m_output_current;
346  }
347 
353  {
354  return m_temperature;
355  }
356 
361  float GetPosition()
362  {
363  return m_position;
364  }
365 
370  double GetSpeed()
371  {
372  return m_speed;
373  }
374 
380  {
381  return m_fwd_limit_ok;
382  }
383 
389  {
390  return m_rev_limit_ok;
391  }
392 
398  {
399  return m_pwr_cyc;
400  }
401 
407  {
408  return m_expire;
409  }
410 
415  bool StatusOK();
416 
421  static void SetGameState(data::RobotData::RobotState state);
422 
426  void ResetCache();
427 
431  virtual void Log();
432 };
433 
434 #endif /* PROXIED_CAN_JAGUAR_H_ */