LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
AsyncCANJaguar.h
1 #ifndef ASYNC_CAN_JAGUAR_H_
2 #define ASYNC_CAN_JAGUAR_H_
3 
4 #include <taskLib.h>
5 
6 #include <CANJaguar.h>
7 #include <vector>
8 
9 #include "../Process/SynchronizedProcess.h"
10 #include "../Utils/Util.h"
11 #include "../Utils/PrintInConstructor.h"
12 #include "../Utils/CachedValue.h"
13 #include "../RobotState.h"
14 
15 #include "LRTSpeedController.h"
16 #include "../Logging/Loggable.h"
17 
18 #include <Rhesus/Toolkit/GameState.h>
19 
24 class AsyncCANJaguar : public SynchronizedProcess, public CANJaguar, public LRTSpeedController
25 {
26 public:
32  AsyncCANJaguar(UINT8 channel, std::string name);
33 
38 
42  static std::vector<AsyncCANJaguar*> jaguar_vector;
43 
44  void Update();
45 
46  int GetChannel();
47 
52  void SetDutyCycle(float duty_cycle);
53 
58  void SetPosition(float position);
59 
64  void SetVelocity(float velocity);
65 
72  void SetPID(double p, double i, double d);
73 
78  void ConfigNeutralMode(LRTSpeedController::NeutralMode mode);
79 
84  void SetSpeedReference(SpeedReference reference);
85 
90  void ChangeControlMode(CANJaguar::ControlMode mode);
91 
96  void EnableControl(double encoderInitialPosition = 0.0);
97 
102  void SetVoltageRampRate(double rampRate);
103 
108  void ConfigEncoderCodesPerRev(UINT16 codesPerRev);
109 
114  void ConfigPotentiometerTurns(UINT16 turns);
115 
121  void ConfigSoftPositionLimits(double forwardLimitPosition,
122  double reverseLimitPosition);
123 
128 
132  void DisableControl();
133 
138  void ConfigMaxOutputVoltage(double voltage);
139 
144  void ConfigFaultTime(float faultTime);
145 
150  void SetExpiration(float timeout);
151 
156  void SetPositionReference(CANJaguar::PositionReference reference);
157 
162  void AddCollectionFlags(uint32_t flags = 0xffffffff);
163 
168  void RemoveCollectionFlags(uint32_t flags = 0xffffffff);
169 
174  void SetCollectionFlags(uint32_t flags);
175 
180  float GetDutyCycle();
181 
186  float GetHardwareValue();
187 
192  LRTSpeedController::NeutralMode GetNeutralMode();
193 
198  double GetP();
199 
204  double GetI();
205 
210  double GetD();
211 
216  SpeedReference GetSpeedReference();
217 
222  PositionReference GetPositionReference();
223 
228  ControlMode GetControlMode();
229 
234  float GetBusVoltage();
235 
240  float GetOutputVoltage();
241 
246  double GetOutputCurrent();
251  float GetTemperature();
252 
257  float GetPosition();
258 
263  double GetSpeed();
268  bool GetForwardLimitOK();
269 
274  bool GetReverseLimitOK();
275 
280  bool GetPowerCycled();
281 
286  float GetExpiration();
287 
292  bool StatusOK();
293 
297  void ResetCache();
298 
299  // collection flags
300  const static uint32_t SPEEDREF = (1 << 0);
301  const static uint32_t POSREF = (1 << 1);
302  const static uint32_t PID = (1 << 2);
303  const static uint32_t CTRLMODE = (1 << 3);
304  const static uint32_t BUSVOLT = (1 << 4);
305  const static uint32_t OUTVOLT = (1 << 5);
306  const static uint32_t OUTCURR = (1 << 6);
307  const static uint32_t TEMP = (1 << 7);
308  const static uint32_t POS = (1 << 8);
309  const static uint32_t SPEED = (1 << 9);
310  const static uint32_t FWDLIMOK = (1 << 10);
311  const static uint32_t REVLIMOK = (1 << 11);
312  const static uint32_t PWRCYCLE = (1 << 12);
313  const static uint32_t EXPIRE = (1 << 13);
314  const static uint32_t VALUE = (1 << 14);
315 
316 protected:
320  void Tick();
321 
322 private:
323  void Set(float setpoint, UINT8 syncGroup = 0);
324 
325  void Println(const char* str);
326 
327  std::string m_task_name;
328  int m_channel;
329 
330  CachedValue<float> m_setpoint;
335  CachedValue<float> m_pid_p;
336  CachedValue<float> m_pid_i;
337  CachedValue<float> m_pid_d;
338  CachedValue<float> m_enable_control;
339  bool m_should_disable_control;
340  CachedValue<float> m_voltage_ramp_rate;
341  CachedValue<float> m_max_output_voltage;
342  CachedValue<float> m_fault_time;
343  CachedValue<float> m_expiration;
344  CachedValue<int> m_encoder_codes_per_rev;
345  CachedValue<int> m_potentiometer_turns;
346  bool m_should_disable_position_limits;
347  CachedValue<float> m_forward_limit_position;
348  CachedValue<float> m_reverse_limit_position;
349 
350  volatile uint32_t m_collection_flags;
351  volatile float m_output_voltage;
352  volatile float m_output_current;
353  volatile float m_position;
354  volatile float m_p, m_i, m_d;
355  volatile SpeedReference m_speed_ref;
356  volatile PositionReference m_position_ref;
357  volatile ControlMode m_ctrl_mode;
358  volatile float m_bus_voltage;
359  volatile float m_temperature;
360  volatile float m_speed;
361  volatile bool m_fwd_limit_ok;
362  volatile bool m_rev_limit_ok;
363  volatile bool m_pwr_cyc;
364  volatile float m_expire;
365  volatile float m_value;
366 
367  GameState::Enum m_last_game_mode;
368 };
369 
370 #endif /* ASYNC_CAN_JAGUAR_H_ */