WPILibC++
unspecified
|
CAN TALON SRX driver. More...
#include <CanTalonSRX.h>
Public Types | |
enum | param_t { eProfileParamSlot0_P = 1, eProfileParamSlot0_I = 2, eProfileParamSlot0_D = 3, eProfileParamSlot0_F = 4, eProfileParamSlot0_IZone = 5, eProfileParamSlot0_CloseLoopRampRate = 6, eProfileParamSlot1_P = 11, eProfileParamSlot1_I = 12, eProfileParamSlot1_D = 13, eProfileParamSlot1_F = 14, eProfileParamSlot1_IZone = 15, eProfileParamSlot1_CloseLoopRampRate = 16, eProfileParamSoftLimitForThreshold = 21, eProfileParamSoftLimitRevThreshold = 22, eProfileParamSoftLimitForEnable = 23, eProfileParamSoftLimitRevEnable = 24, eOnBoot_BrakeMode = 31, eOnBoot_LimitSwitch_Forward_NormallyClosed = 32, eOnBoot_LimitSwitch_Reverse_NormallyClosed = 33, eOnBoot_LimitSwitch_Forward_Disable = 34, eOnBoot_LimitSwitch_Reverse_Disable = 35, eFault_OverTemp = 41, eFault_UnderVoltage = 42, eFault_ForLim = 43, eFault_RevLim = 44, eFault_HardwareFailure = 45, eFault_ForSoftLim = 46, eFault_RevSoftLim = 47, eStckyFault_OverTemp = 48, eStckyFault_UnderVoltage = 49, eStckyFault_ForLim = 50, eStckyFault_RevLim = 51, eStckyFault_ForSoftLim = 52, eStckyFault_RevSoftLim = 53, eAppliedThrottle = 61, eCloseLoopErr = 62, eFeedbackDeviceSelect = 63, eRevMotDuringCloseLoopEn = 64, eModeSelect = 65, eProfileSlotSelect = 66, eRampThrottle = 67, eRevFeedbackSensor = 68, eLimitSwitchEn = 69, eLimitSwitchClosedFor = 70, eLimitSwitchClosedRev = 71, eSensorPosition = 73, eSensorVelocity = 74, eCurrent = 75, eBrakeIsEnabled = 76, eEncPosition = 77, eEncVel = 78, eEncIndexRiseEvents = 79, eQuadApin = 80, eQuadBpin = 81, eQuadIdxpin = 82, eAnalogInWithOv = 83, eAnalogInVel = 84, eTemp = 85, eBatteryV = 86, eResetCount = 87, eResetFlags = 88, eFirmVers = 89, eSettingsChanged = 90, eQuadFilterEn = 91, ePidIaccum = 93, eStatus1FrameRate = 94, eStatus2FrameRate = 95, eStatus3FrameRate = 96, eStatus4FrameRate = 97, eStatus6FrameRate = 98, eStatus7FrameRate = 99, eClearPositionOnIdx = 100, ePeakPosOutput = 104, eNominalPosOutput = 105, ePeakNegOutput = 106, eNominalNegOutput = 107, eQuadIdxPolarity = 108, eStatus8FrameRate = 109, eAllowPosOverflow = 110, eProfileParamSlot0_AllowableClosedLoopErr = 111, eNumberPotTurns = 112, eNumberEncoderCPR = 113, ePwdPosition = 114, eAinPosition = 115, eProfileParamVcompRate = 116, eProfileParamSlot1_AllowableClosedLoopErr = 117, eStatus9FrameRate = 118, eMotionProfileHasUnderrunErr = 119, eReserved120 = 120, eLegacyControlMode = 121 } |
Signal enumeration for generic signal access. More... | |
Public Member Functions | |
CanTalonSRX (int deviceNumber=0, int controlPeriodMs=kDefaultControlPeriodMs, int enablePeriodMs=kDefaultEnablePeriodMs) | |
void | Set (double value) |
CTR_Code | SetParam (param_t paramEnum, double value) |
Send a one shot frame to set an arbitrary signal. More... | |
CTR_Code | RequestParam (param_t paramEnum) |
Asks TALON to immedietely respond with signal value. More... | |
CTR_Code | GetParamResponse (param_t paramEnum, double &value) |
CTR_Code | GetParamResponseInt32 (param_t paramEnum, int &value) |
CTR_Code | SetPgain (unsigned slotIdx, double gain) |
These signals are backed up in flash and will survive a power cycle. More... | |
CTR_Code | SetIgain (unsigned slotIdx, double gain) |
CTR_Code | SetDgain (unsigned slotIdx, double gain) |
CTR_Code | SetFgain (unsigned slotIdx, double gain) |
CTR_Code | SetIzone (unsigned slotIdx, int zone) |
CTR_Code | SetCloseLoopRampRate (unsigned slotIdx, int closeLoopRampRate) |
CTR_Code | SetVoltageCompensationRate (double voltagePerMs) |
CTR_Code | SetSensorPosition (int pos) |
CTR_Code | SetForwardSoftLimit (int forwardLimit) |
CTR_Code | SetReverseSoftLimit (int reverseLimit) |
CTR_Code | SetForwardSoftEnable (int enable) |
CTR_Code | SetReverseSoftEnable (int enable) |
CTR_Code | GetPgain (unsigned slotIdx, double &gain) |
CTR_Code | GetIgain (unsigned slotIdx, double &gain) |
CTR_Code | GetDgain (unsigned slotIdx, double &gain) |
CTR_Code | GetFgain (unsigned slotIdx, double &gain) |
CTR_Code | GetIzone (unsigned slotIdx, int &zone) |
CTR_Code | GetCloseLoopRampRate (unsigned slotIdx, int &closeLoopRampRate) |
CTR_Code | GetVoltageCompensationRate (double &voltagePerMs) |
CTR_Code | GetForwardSoftLimit (int &forwardLimit) |
CTR_Code | GetReverseSoftLimit (int &reverseLimit) |
CTR_Code | GetForwardSoftEnable (int &enable) |
CTR_Code | GetReverseSoftEnable (int &enable) |
CTR_Code | GetPulseWidthRiseToFallUs (int ¶m) |
CTR_Code | IsPulseWidthSensorPresent (int ¶m) |
CTR_Code | SetModeSelect (int modeSelect, int demand) |
CTR_Code | SetStatusFrameRate (unsigned frameEnum, unsigned periodMs) |
Change the periodMs of a TALON's status frame. More... | |
CTR_Code | ClearStickyFaults () |
Clear all sticky faults in TALON. | |
void | ChangeMotionControlFramePeriod (uint32_t periodMs) |
Calling application can opt to speed up the handshaking between the robot API and the Talon to increase the download rate of the Talon's Motion Profile. More... | |
void | ClearMotionProfileTrajectories () |
Clear the buffered motion profile in both Talon RAM (bottom), and in the API (top). | |
uint32_t | GetMotionProfileTopLevelBufferCount () |
Retrieve just the buffer count for the api-level (top) buffer. More... | |
bool | IsMotionProfileTopLevelBufferFull () |
Retrieve just the buffer full for the api-level (top) buffer. More... | |
CTR_Code | PushMotionProfileTrajectory (int targPos, int targVel, int profileSlotSelect, int timeDurMs, int velOnly, int isLastPoint, int zeroPos) |
Push another trajectory point into the top level buffer (which is emptied into the Talon's bottom buffer as room allows). More... | |
void | ProcessMotionProfileBuffer () |
This must be called periodically to funnel the trajectory points from the API's top level buffer to the Talon's bottom level buffer. More... | |
CTR_Code | GetMotionProfileStatus (uint32_t &flags, uint32_t &profileSlotSelect, int32_t &targPos, int32_t &targVel, uint32_t &topBufferRemaining, uint32_t &topBufferCnt, uint32_t &btmBufferCnt, uint32_t &outputEnable) |
Retrieve all status information. More... | |
CTR_Code | GetFault_OverTemp (int ¶m) |
CTR_Code | GetFault_UnderVoltage (int ¶m) |
CTR_Code | GetFault_ForLim (int ¶m) |
CTR_Code | GetFault_RevLim (int ¶m) |
CTR_Code | GetFault_HardwareFailure (int ¶m) |
CTR_Code | GetFault_ForSoftLim (int ¶m) |
CTR_Code | GetFault_RevSoftLim (int ¶m) |
CTR_Code | GetStckyFault_OverTemp (int ¶m) |
CTR_Code | GetStckyFault_UnderVoltage (int ¶m) |
CTR_Code | GetStckyFault_ForLim (int ¶m) |
CTR_Code | GetStckyFault_RevLim (int ¶m) |
CTR_Code | GetStckyFault_ForSoftLim (int ¶m) |
CTR_Code | GetStckyFault_RevSoftLim (int ¶m) |
CTR_Code | GetAppliedThrottle (int ¶m) |
CTR_Code | GetCloseLoopErr (int ¶m) |
CTR_Code | GetFeedbackDeviceSelect (int ¶m) |
CTR_Code | GetModeSelect (int ¶m) |
CTR_Code | GetLimitSwitchEn (int ¶m) |
CTR_Code | GetLimitSwitchClosedFor (int ¶m) |
CTR_Code | GetLimitSwitchClosedRev (int ¶m) |
CTR_Code | GetSensorPosition (int ¶m) |
CTR_Code | GetSensorVelocity (int ¶m) |
CTR_Code | GetCurrent (double ¶m) |
CTR_Code | GetBrakeIsEnabled (int ¶m) |
CTR_Code | GetEncPosition (int ¶m) |
CTR_Code | GetEncVel (int ¶m) |
CTR_Code | GetEncIndexRiseEvents (int ¶m) |
CTR_Code | GetQuadApin (int ¶m) |
CTR_Code | GetQuadBpin (int ¶m) |
CTR_Code | GetQuadIdxpin (int ¶m) |
CTR_Code | GetAnalogInWithOv (int ¶m) |
CTR_Code | GetAnalogInVel (int ¶m) |
CTR_Code | GetTemp (double ¶m) |
CTR_Code | GetBatteryV (double ¶m) |
CTR_Code | GetResetCount (int ¶m) |
CTR_Code | GetResetFlags (int ¶m) |
CTR_Code | GetFirmVers (int ¶m) |
CTR_Code | GetPulseWidthPosition (int ¶m) |
CTR_Code | GetPulseWidthVelocity (int ¶m) |
CTR_Code | GetPulseWidthRiseToRiseUs (int ¶m) |
CTR_Code | GetActTraj_IsValid (int ¶m) |
CTR_Code | GetActTraj_ProfileSlotSelect (int ¶m) |
CTR_Code | GetActTraj_VelOnly (int ¶m) |
CTR_Code | GetActTraj_IsLast (int ¶m) |
CTR_Code | GetOutputType (int ¶m) |
CTR_Code | GetHasUnderrun (int ¶m) |
CTR_Code | GetIsUnderrun (int ¶m) |
CTR_Code | GetNextID (int ¶m) |
CTR_Code | GetBufferIsFull (int ¶m) |
CTR_Code | GetCount (int ¶m) |
CTR_Code | GetActTraj_Velocity (int ¶m) |
CTR_Code | GetActTraj_Position (int ¶m) |
CTR_Code | SetDemand (int param) |
CTR_Code | SetOverrideLimitSwitchEn (int param) |
CTR_Code | SetFeedbackDeviceSelect (int param) |
CTR_Code | SetRevMotDuringCloseLoopEn (int param) |
CTR_Code | SetOverrideBrakeType (int param) |
CTR_Code | SetModeSelect (int param) |
CTR_Code | SetProfileSlotSelect (int param) |
CTR_Code | SetRampThrottle (int param) |
CTR_Code | SetRevFeedbackSensor (int param) |
![]() | |
CtreCanNode (UINT8 deviceNumber) | |
UINT8 | GetDeviceNumber () |
Additional Inherited Members | |
![]() | |
void | RegisterRx (uint32_t arbId) |
void | RegisterTx (uint32_t arbId, uint32_t periodMs) |
Schedule a CAN Frame for periodic transmit. More... | |
void | RegisterTx (uint32_t arbId, uint32_t periodMs, uint32_t dlc, const uint8_t *initialFrame) |
Schedule a CAN Frame for periodic transmit. More... | |
void | UnregisterTx (uint32_t arbId) |
CTR_Code | GetRx (uint32_t arbId, uint8_t *dataBytes, uint32_t timeoutMs) |
void | FlushTx (uint32_t arbId) |
bool | ChangeTxPeriod (uint32_t arbId, uint32_t periodMs) |
template<typename T > | |
txTask< T > | GetTx (uint32_t arbId) |
template<class T > | |
void | FlushTx (T &par) |
template<class T > | |
recMsg< T > | GetRx (uint32_t arbId, uint32_t timeoutMs) |
![]() | |
UINT8 | _deviceNumber |
CAN TALON SRX driver.
The TALON SRX is designed to instrument all runtime signals periodically. The default periods are chosen to support 16 TALONs with 10ms update rate for control (throttle or setpoint). However these can be overridden with SetStatusFrameRate.
Likewise most control signals are sent periodically using the fire-and-forget CAN API. The setters for these unsolicited signals are auto generated at the bottom of this module.
Signals that are not available in an unsolicited fashion are the Close Loop gains. For teams that have a single profile for their TALON close loop they can use either the webpage to configure their TALONs once or set the PIDF, Izone, CloseLoopRampRate, etc... once in the robot application. These parameters are saved to flash so once they are loaded in the TALON, they will persist through power cycles and mode changes.
For teams that have one or two profiles to switch between, they can use the same strategy since there are two slots to choose from and the ProfileSlotSelect is periodically sent in the 10 ms control frame.
For teams that require changing gains frequently, they can use the soliciting API to get and set those parameters. Most likely they will only need to set them in a periodic fashion as a function of what motion the application is attempting. If this API is used, be mindful of the CAN utilization reported in the driver station.
If calling application has used the config routines to configure the selected feedback sensor, then all positions are measured in floating point precision rotations. All sensor velocities are specified in floating point precision RPM.
Encoder position is measured in encoder edges. Every edge is counted (similar to roboRIO 4X mode). Analog position is 10 bits, meaning 1024 ticks per rotation (0V => 3.3V). Use SetFeedbackDeviceSelect to select which sensor type you need. Once you do that you can use GetSensorPosition() and GetSensorVelocity(). These signals are updated on CANBus every 20ms (by default). If a relative sensor is selected, you can zero (or change the current value) using SetSensorPosition.
Analog Input and quadrature position (and velocity) are also explicitly reported in GetEncPosition, GetEncVel, GetAnalogInWithOv, GetAnalogInVel. These signals are available all the time, regardless of what sensor is selected at a rate of 100ms. This allows easy instrumentation for "in the pits" checking of all sensors regardless of modeselect. The 100ms rate is overridable for teams who want to acquire sensor data for processing, not just instrumentation. Or just select the sensor using SetFeedbackDeviceSelect to get it at 20ms.
Velocity is in position ticks / 100ms.
All output units are in respect to duty cycle (throttle) which is -1023(full reverse) to +1023 (full forward). This includes demand (which specifies duty cycle when in duty cycle mode) and rampRamp, which is in throttle units per 10ms (if nonzero).
Pos and velocity close loops are calc'd as err = target - posOrVel. iErr += err; if( (IZone!=0) and abs(err) > IZone) ClearIaccum() output = P X err + I X iErr + D X dErr + F X target dErr = err - lastErr P, I, and D gains are always positive. F can be negative. Motor direction can be reversed using SetRevMotDuringCloseLoopEn if sensor and motor are out of phase. Similarly feedback sensor can also be reversed (multiplied by -1) if you prefer the sensor to be inverted.
P gain is specified in throttle per error tick. For example, a value of 102 is ~9.9% (which is 102/1023) throttle per 1 ADC unit(10bit) or 1 quadrature encoder edge depending on selected sensor.
I gain is specified in throttle per integrated error. For example, a value of 10 equates to ~0.99% (which is 10/1023) for each accumulated ADC unit (10 bit) or 1 quadrature encoder edge depending on selected sensor. Close loop and integral accumulator runs every 1ms.
D gain is specified in throttle per derivative error. For example a value of 102 equates to ~9.9% (which is 102/1023) per change of 1 unit (ADC or encoder) per ms.
I Zone is specified in the same units as sensor position (ADC units or quadrature edges). If pos/vel error is outside of this value, the integrated error will auto-clear... if( (IZone!=0) and abs(err) > IZone) ClearIaccum() ...this is very useful in preventing integral windup and is highly recommended if using full PID to keep stability low.
CloseLoopRampRate is in throttle units per 1ms. Set to zero to disable ramping. Works the same as RampThrottle but only is in effect when a close loop mode and profile slot is selected.
auto generated using spreadsheet and wpiclassgen.py https://docs.google.com/spreadsheets/d/1OU_ZV7fZLGYUQ-Uhc8sVAmUmWTlT8XBFYK8lfjg_tac/edit#gid=1766046967
enum CanTalonSRX::param_t |
Signal enumeration for generic signal access.
Although every signal is enumerated, only use this for traffic that must be solicited. Use the auto generated getters/setters at bottom of this header as much as possible.
void CanTalonSRX::ChangeMotionControlFramePeriod | ( | uint32_t | periodMs | ) |
CTR_Code CanTalonSRX::GetMotionProfileStatus | ( | uint32_t & | flags, |
uint32_t & | profileSlotSelect, | ||
int32_t & | targPos, | ||
int32_t & | targVel, | ||
uint32_t & | topBufferRemaining, | ||
uint32_t & | topBufferCnt, | ||
uint32_t & | btmBufferCnt, | ||
uint32_t & | outputEnable | ||
) |
Retrieve all status information.
Since this all comes from one CAN frame, its ideal to have one routine to retrieve the frame once and decode everything.
[out] | flags | bitfield for status bools. Starting with least significant bit: IsValid, HasUnderrun, IsUnderrun, IsLast, VelOnly. |
IsValid set when MP executer is processing a trajectory point, and that point's status is instrumented with IsLast, VelOnly, targPos, targVel. However if MP executor is not processing a trajectory point, then this flag is false, and the instrumented signals will be zero. HasUnderrun is set anytime the MP executer is ready to pop another trajectory point from the Talon's RAM, but the buffer is empty. It can only be cleared by using SetParam(eMotionProfileHasUnderrunErr,0); IsUnderrun is set when the MP executer is ready for another point, but the buffer is empty, and cleared when the MP executer does not need another point. HasUnderrun shadows this registor when this register gets set, however HasUnderrun stays asserted until application has process it, and IsUnderrun auto-clears when the condition is resolved. IsLast is set/cleared based on the MP executer's current trajectory point's IsLast value. This assumes IsLast was set when PushMotionProfileTrajectory was used to insert the currently processed trajectory point. VelOnly is set/cleared based on the MP executer's current trajectory point's VelOnly value.
[out] | profileSlotSelect | The currently processed trajectory point's selected slot. This can differ in the currently selected slot used for Position and Velocity servo modes. |
[out] | targPos | The currently processed trajectory point's position in native units. This param is zero if IsValid is zero. |
[out] | targVel | The currently processed trajectory point's velocity in native units. This param is zero if IsValid is zero. |
[out] | topBufferRem | The remaining number of points in the top level buffer. |
[out] | topBufferCnt | The number of points in the top level buffer to be sent to Talon. |
[out] | btmBufferCnt | The number of points in the bottom level buffer inside Talon. |
uint32_t CanTalonSRX::GetMotionProfileTopLevelBufferCount | ( | ) |
Retrieve just the buffer count for the api-level (top) buffer.
This routine performs no CAN or data structure lookups, so its fast and ideal if caller needs to quickly poll the progress of trajectory points being emptied into Talon's RAM. Otherwise just use GetMotionProfileStatus.
bool CanTalonSRX::IsMotionProfileTopLevelBufferFull | ( | ) |
Retrieve just the buffer full for the api-level (top) buffer.
This routine performs no CAN or data structure lookups, so its fast and ideal if caller needs to quickly poll. Otherwise just use GetMotionProfileStatus.
void CanTalonSRX::ProcessMotionProfileBuffer | ( | ) |
This must be called periodically to funnel the trajectory points from the API's top level buffer to the Talon's bottom level buffer.
Recommendation is to call this twice as fast as the executation rate of the motion profile. So if MP is running with 20ms trajectory points, try calling this routine every 10ms. All motion profile functions are thread-safe through the use of a mutex, so there is no harm in having the caller utilize threading.
CTR_Code CanTalonSRX::PushMotionProfileTrajectory | ( | int | targPos, |
int | targVel, | ||
int | profileSlotSelect, | ||
int | timeDurMs, | ||
int | velOnly, | ||
int | isLastPoint, | ||
int | zeroPos | ||
) |
Push another trajectory point into the top level buffer (which is emptied into the Talon's bottom buffer as room allows).
targPos | servo position in native Talon units (sensor units). |
targVel | velocity to feed-forward in native Talon units (sensor units per 100ms). |
profileSlotSelect | which slot to pull PIDF gains from. Currently supports 0 or 1. |
timeDurMs | time in milliseconds of how long to apply this point. |
velOnly | set to nonzero to signal Talon that only the feed-foward velocity should be used, i.e. do not perform PID on position. This is equivalent to setting PID gains to zero, but much more efficient and synchronized to MP. |
isLastPoint | set to nonzero to signal Talon to keep processing this trajectory point, instead of jumping to the next one when timeDurMs expires. Otherwise MP executer will eventually see an empty buffer after the last point expires, causing it to assert the IsUnderRun flag. However this may be desired if calling application nevers wants to terminate the MP. |
zeroPos | set to nonzero to signal Talon to "zero" the selected position sensor before executing this trajectory point. Typically the first point should have this set only thus allowing the remainder of the MP positions to be relative to zero. |
Asks TALON to immedietely respond with signal value.
This API is only used for signals that are not sent periodically. This can be useful for reading params that rarely change like Limit Switch settings and PIDF values.
param | to request. |
Send a one shot frame to set an arbitrary signal.
Most signals are in the control frame so avoid using this API unless you have to. Use this api for... -A motor controller profile signal eProfileParam_XXXs. These are backed up in flash. If you are gain-scheduling then call this periodically. -Default brake and limit switch signals... eOnBoot_XXXs. Avoid doing this, use the override signals in the control frame. Talon will automatically send a PARAM_RESPONSE after the set, so GetParamResponse will catch the latest value after a couple ms.
CTR_Code CanTalonSRX::SetPgain | ( | unsigned | slotIdx, |
double | gain | ||
) |
These signals are backed up in flash and will survive a power cycle.
If your application requires changing these values consider using both slots and switch between slot0 <=> slot1. If your application requires changing these signals frequently then it makes sense to leverage this API. Getters don't block, so it may require several calls to get the latest value.
CTR_Code CanTalonSRX::SetStatusFrameRate | ( | unsigned | frameEnum, |
unsigned | periodMs | ||
) |
Change the periodMs of a TALON's status frame.
See kStatusFrame_* enums for what's available.