11 #include "ErrorBase.h"
12 #include "MotorSafety.h"
13 #include "MotorSafetyHelper.h"
14 #include "PIDOutput.h"
15 #include "SpeedController.h"
18 #include "LiveWindow/LiveWindowSendable.h"
19 #include "tables/ITable.h"
27 public LiveWindowSendable,
32 static const int32_t kControllerRate = 1000;
33 static constexpr
double kApproxBusVoltage = 12.0;
35 typedef enum {kPercentVbus, kCurrent, kSpeed, kPosition, kVoltage} ControlMode;
36 typedef enum {kCurrentFault = 1, kTemperatureFault = 2, kBusVoltageFault = 4, kGateDriverFault = 8} Faults;
37 typedef enum {kForwardLimit = 1, kReverseLimit = 2} Limits;
38 typedef enum {kPosRef_QuadEncoder = 0, kPosRef_Potentiometer = 1, kPosRef_None = 0xFF} PositionReference;
39 typedef enum {kSpeedRef_Encoder = 0, kSpeedRef_InvEncoder = 2, kSpeedRef_QuadEncoder = 3, kSpeedRef_None = 0xFF} SpeedReference;
40 typedef enum {kNeutralMode_Jumper = 0, kNeutralMode_Brake = 1, kNeutralMode_Coast = 2} NeutralMode;
41 typedef enum {kLimitMode_SwitchInputsOnly = 0, kLimitMode_SoftPositionLimits = 1} LimitMode;
43 explicit CANJaguar(uint8_t deviceNumber, ControlMode controlMode = kPercentVbus);
48 virtual void Set(
float value, uint8_t syncGroup=0);
59 void SetPID(
double p,
double i,
double d);
90 void SetExpiration(
float timeout);
91 float GetExpiration();
94 bool IsSafetyEnabled();
95 void SetSafetyEnabled(
bool enabled);
96 void GetDescription(
char *desc);
99 uint8_t packPercentage(uint8_t *buffer,
double value);
100 uint8_t packFXP8_8(uint8_t *buffer,
double value);
101 uint8_t packFXP16_16(uint8_t *buffer,
double value);
102 uint8_t packint16_t(uint8_t *buffer, int16_t value);
103 uint8_t packint32_t(uint8_t *buffer, int32_t value);
104 double unpackPercentage(uint8_t *buffer);
105 double unpackFXP8_8(uint8_t *buffer);
106 double unpackFXP16_16(uint8_t *buffer);
107 int16_t unpackint16_t(uint8_t *buffer);
108 int32_t unpackint32_t(uint8_t *buffer);
109 virtual void setTransaction(uint32_t messageID,
const uint8_t *data, uint8_t dataSize);
110 virtual void getTransaction(uint32_t messageID, uint8_t *data, uint8_t *dataSize);
112 static int32_t
sendMessage(uint32_t messageID,
const uint8_t *data, uint8_t dataSize);
113 static int32_t
receiveMessage(uint32_t *messageID, uint8_t *data, uint8_t *dataSize,
float timeout = 0.02);
115 uint8_t m_deviceNumber;
116 ControlMode m_controlMode;
117 SEM_ID m_transactionSemaphore;
118 double m_maxOutputVoltage;
122 void ValueChanged(ITable* source,
const std::string& key, EntryValue value,
bool isNew);
124 void StartLiveWindowMode();
125 void StopLiveWindowMode();
126 std::string GetSmartDashboardType();
127 void InitTable(ITable *subTable);
133 void InitCANJaguar();
void StopMotor()
Definition: CANJaguar.cpp:1236
bool GetReverseLimitOK()
Definition: CANJaguar.cpp:934
SpeedReference GetSpeedReference()
Definition: CANJaguar.cpp:482
Definition: MotorSafety.h:11
virtual void setTransaction(uint32_t messageID, const uint8_t *data, uint8_t dataSize)
Definition: CANJaguar.cpp:395
void DisableControl()
Definition: CANJaguar.cpp:738
virtual void Set(float value, uint8_t syncGroup=0)
Definition: CANJaguar.cpp:113
bool GetPowerCycled()
Definition: CANJaguar.cpp:973
bool GetForwardLimitOK()
Definition: CANJaguar.cpp:916
virtual float Get()
Definition: CANJaguar.cpp:182
static int32_t receiveMessage(uint32_t *messageID, uint8_t *data, uint8_t *dataSize, float timeout=0.02)
Definition: CANJaguar.cpp:377
void SetSpeedReference(SpeedReference reference)
Definition: CANJaguar.cpp:469
double GetPosition()
Definition: CANJaguar.cpp:880
static void UpdateSyncGroup(uint8_t syncGroup)
Definition: CANJaguar.cpp:1191
float GetBusVoltage()
Definition: CANJaguar.cpp:807
void ConfigMaxOutputVoltage(double voltage)
Definition: CANJaguar.cpp:1158
double GetSpeed()
Definition: CANJaguar.cpp:898
void ConfigFaultTime(float faultTime)
Definition: CANJaguar.cpp:1176
virtual void Disable()
Definition: CANJaguar.cpp:233
virtual void PIDWrite(float output)
Definition: CANJaguar.cpp:245
void EnableControl(double encoderInitialPosition=0.0)
Definition: CANJaguar.cpp:707
ControlMode GetControlMode()
Definition: CANJaguar.cpp:789
double GetP()
Definition: CANJaguar.cpp:579
void ConfigEncoderCodesPerRev(uint16_t codesPerRev)
Definition: CANJaguar.cpp:1084
void SetPID(double p, double i, double d)
Definition: CANJaguar.cpp:536
virtual void getTransaction(uint32_t messageID, uint8_t *data, uint8_t *dataSize)
Definition: CANJaguar.cpp:430
Definition: ErrorBase.h:37
void ConfigPotentiometerTurns(uint16_t turns)
Definition: CANJaguar.cpp:1101
double GetD()
Definition: CANJaguar.cpp:661
static int32_t sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize)
Definition: CANJaguar.cpp:334
float GetTemperature()
Definition: CANJaguar.cpp:862
void ConfigNeutralMode(NeutralMode mode)
Definition: CANJaguar.cpp:1071
Definition: SpeedController.h:16
Definition: MotorSafetyHelper.h:16
void SetVoltageRampRate(double rampRate)
Definition: CANJaguar.cpp:1003
void ChangeControlMode(ControlMode controlMode)
Definition: CANJaguar.cpp:771
virtual uint32_t GetFirmwareVersion()
Definition: CANJaguar.cpp:1028
CANJaguar(uint8_t deviceNumber, ControlMode controlMode=kPercentVbus)
Definition: CANJaguar.cpp:82
PositionReference GetPositionReference()
Definition: CANJaguar.cpp:516
uint8_t GetHardwareVersion()
Definition: CANJaguar.cpp:1047
void DisableSoftPositionLimits()
Definition: CANJaguar.cpp:1142
uint16_t GetFaults()
Definition: CANJaguar.cpp:952
void ConfigSoftPositionLimits(double forwardLimitPosition, double reverseLimitPosition)
Definition: CANJaguar.cpp:1120
double GetI()
Definition: CANJaguar.cpp:620
float GetOutputCurrent()
Definition: CANJaguar.cpp:844
float GetOutputVoltage()
Definition: CANJaguar.cpp:825
Definition: CANJaguar.h:24
void SetPositionReference(PositionReference reference)
Definition: CANJaguar.cpp:503