WPILib 2012
WPILibRoboticsLibraryforFRC
|
#include <CANJaguar.h>
Public Types | |
enum | ControlMode { kPercentVbus, kCurrent, kSpeed, kPosition, kVoltage } |
enum | Faults { kCurrentFault = 1, kTemperatureFault = 2, kBusVoltageFault = 4, kGateDriverFault = 8 } |
enum | Limits { kForwardLimit = 1, kReverseLimit = 2 } |
enum | PositionReference { kPosRef_QuadEncoder = 0, kPosRef_Potentiometer = 1, kPosRef_None = 0xFF } |
enum | SpeedReference { kSpeedRef_Encoder = 0, kSpeedRef_InvEncoder = 2, kSpeedRef_QuadEncoder = 3, kSpeedRef_None = 0xFF } |
enum | NeutralMode { kNeutralMode_Jumper = 0, kNeutralMode_Brake = 1, kNeutralMode_Coast = 2 } |
enum | LimitMode { kLimitMode_SwitchInputsOnly = 0, kLimitMode_SoftPositionLimits = 1 } |
Public Member Functions | |
CANJaguar (UINT8 deviceNumber, ControlMode controlMode=kPercentVbus) | |
virtual float | Get () |
virtual void | Set (float value, UINT8 syncGroup=0) |
virtual void | Disable () |
virtual void | PIDWrite (float output) |
void | SetSpeedReference (SpeedReference reference) |
SpeedReference | GetSpeedReference () |
void | SetPositionReference (PositionReference reference) |
PositionReference | GetPositionReference () |
void | SetPID (double p, double i, double d) |
double | GetP () |
double | GetI () |
double | GetD () |
void | EnableControl (double encoderInitialPosition=0.0) |
void | DisableControl () |
void | ChangeControlMode (ControlMode controlMode) |
ControlMode | GetControlMode () |
float | GetBusVoltage () |
float | GetOutputVoltage () |
float | GetOutputCurrent () |
float | GetTemperature () |
double | GetPosition () |
double | GetSpeed () |
bool | GetForwardLimitOK () |
bool | GetReverseLimitOK () |
UINT16 | GetFaults () |
bool | GetPowerCycled () |
void | SetVoltageRampRate (double rampRate) |
virtual UINT32 | GetFirmwareVersion () |
UINT8 | GetHardwareVersion () |
void | ConfigNeutralMode (NeutralMode mode) |
void | ConfigEncoderCodesPerRev (UINT16 codesPerRev) |
void | ConfigPotentiometerTurns (UINT16 turns) |
void | ConfigSoftPositionLimits (double forwardLimitPosition, double reverseLimitPosition) |
void | DisableSoftPositionLimits () |
void | ConfigMaxOutputVoltage (double voltage) |
void | ConfigFaultTime (float faultTime) |
void | SetExpiration (float timeout) |
float | GetExpiration () |
bool | IsAlive () |
void | StopMotor () |
bool | IsSafetyEnabled () |
void | SetSafetyEnabled (bool enabled) |
void | GetDescription (char *desc) |
Static Public Member Functions | |
static void | UpdateSyncGroup (UINT8 syncGroup) |
Static Public Attributes | |
static const INT32 | kControllerRate = 1000 |
static const double | kApproxBusVoltage = 12.0 |
Protected Member Functions | |
UINT8 | packPercentage (UINT8 *buffer, double value) |
UINT8 | packFXP8_8 (UINT8 *buffer, double value) |
UINT8 | packFXP16_16 (UINT8 *buffer, double value) |
UINT8 | packINT16 (UINT8 *buffer, INT16 value) |
UINT8 | packINT32 (UINT8 *buffer, INT32 value) |
double | unpackPercentage (UINT8 *buffer) |
double | unpackFXP8_8 (UINT8 *buffer) |
double | unpackFXP16_16 (UINT8 *buffer) |
INT16 | unpackINT16 (UINT8 *buffer) |
INT32 | unpackINT32 (UINT8 *buffer) |
virtual void | setTransaction (UINT32 messageID, const UINT8 *data, UINT8 dataSize) |
virtual void | getTransaction (UINT32 messageID, UINT8 *data, UINT8 *dataSize) |
Static Protected Member Functions | |
static INT32 | sendMessage (UINT32 messageID, const UINT8 *data, UINT8 dataSize) |
static INT32 | receiveMessage (UINT32 *messageID, UINT8 *data, UINT8 *dataSize, float timeout=0.02) |
Protected Attributes | |
UINT8 | m_deviceNumber |
ControlMode | m_controlMode |
SEM_ID | m_transactionSemaphore |
double | m_maxOutputVoltage |
MotorSafetyHelper * | m_safetyHelper |
Luminary Micro Jaguar Speed Control
CANJaguar::CANJaguar | ( | UINT8 | deviceNumber, |
ControlMode | controlMode = kPercentVbus |
||
) | [explicit] |
Constructor
deviceNumber | The the address of the Jaguar on the CAN bus. |
void CANJaguar::ChangeControlMode | ( | ControlMode | controlMode | ) |
Change the control mode of this Jaguar object.
After changing modes, configure any PID constants or other settings needed and then EnableControl() to actually change the mode on the Jaguar.
controlMode | The new mode. |
void CANJaguar::ConfigEncoderCodesPerRev | ( | UINT16 | codesPerRev | ) |
Configure how many codes per revolution are generated by your encoder.
codesPerRev | The number of counts per revolution in 1X mode. |
void CANJaguar::ConfigFaultTime | ( | float | faultTime | ) |
Configure how long the Jaguar waits in the case of a fault before resuming operation.
Faults include over temerature, over current, and bus under voltage. The default is 3.0 seconds, but can be reduced to as low as 0.5 seconds.
faultTime | The time to wait before resuming operation, in seconds. |
void CANJaguar::ConfigMaxOutputVoltage | ( | double | voltage | ) |
void CANJaguar::ConfigNeutralMode | ( | NeutralMode | mode | ) |
Configure what the controller does to the H-Bridge when neutral (not driving the output).
This allows you to override the jumper configuration for brake or coast.
mode | Select to use the jumper setting or to override it to coast or brake. |
void CANJaguar::ConfigPotentiometerTurns | ( | UINT16 | turns | ) |
Configure the number of turns on the potentiometer.
There is no special support for continuous turn potentiometers. Only integer numbers of turns are supported.
turns | The number of turns of the potentiometer |
void CANJaguar::ConfigSoftPositionLimits | ( | double | forwardLimitPosition, |
double | reverseLimitPosition | ||
) |
Configure Soft Position Limits when in Position Controller mode.
When controlling position, you can add additional limits on top of the limit switch inputs that are based on the position feedback. If the position limit is reached or the switch is opened, that direction will be disabled.
forwardLimitPosition | The position that if exceeded will disable the forward direction. |
reverseLimitPosition | The position that if exceeded will disable the reverse direction. |
void CANJaguar::Disable | ( | ) | [virtual] |
Common interface for disabling a motor.
Implements SpeedController.
void CANJaguar::DisableControl | ( | ) |
Disable the closed loop controller.
Stop driving the output based on the feedback.
void CANJaguar::DisableSoftPositionLimits | ( | ) |
Disable Soft Position Limits if previously enabled.
Soft Position Limits are disabled by default.
void CANJaguar::EnableControl | ( | double | encoderInitialPosition = 0.0 | ) |
Enable the closed loop controller.
Start actually controlling the output based on the feedback. If starting a position controller with an encoder reference, use the encoderInitialPosition parameter to initialize the encoder state.
encoderInitialPosition | Encoder position to set if position with encoder reference. Ignored otherwise. |
float CANJaguar::Get | ( | ) | [virtual] |
Get the recently set outputValue setpoint.
The scale and the units depend on the mode the Jaguar is in. In PercentVbus Mode, the outputValue is from -1.0 to 1.0 (same as PWM Jaguar). In Voltage Mode, the outputValue is in Volts. In Current Mode, the outputValue is in Amps. In Speed Mode, the outputValue is in Rotations/Minute. In Position Mode, the outputValue is in Rotations.
Implements SpeedController.
float CANJaguar::GetBusVoltage | ( | ) |
Get the voltage at the battery input terminals of the Jaguar.
CANJaguar::ControlMode CANJaguar::GetControlMode | ( | ) |
Get the active control mode from the Jaguar.
Ask the Jag what mode it is in.
double CANJaguar::GetD | ( | ) |
Get the Differential gain of the controller.
UINT16 CANJaguar::GetFaults | ( | ) |
Get the status of any faults the Jaguar has detected.
UINT32 CANJaguar::GetFirmwareVersion | ( | ) | [virtual] |
Get the version of the firmware running on the Jaguar.
bool CANJaguar::GetForwardLimitOK | ( | ) |
Get the status of the forward limit switch.
UINT8 CANJaguar::GetHardwareVersion | ( | ) |
double CANJaguar::GetI | ( | ) |
Get the Intregral gain of the controller.
float CANJaguar::GetOutputCurrent | ( | ) |
Get the current through the motor terminals of the Jaguar.
float CANJaguar::GetOutputVoltage | ( | ) |
Get the voltage being output from the motor terminals of the Jaguar.
double CANJaguar::GetP | ( | ) |
Get the Proportional gain of the controller.
double CANJaguar::GetPosition | ( | ) |
Get the position of the encoder or potentiometer.
CANJaguar::PositionReference CANJaguar::GetPositionReference | ( | ) |
Get the reference source device for position controller mode.
bool CANJaguar::GetPowerCycled | ( | ) |
bool CANJaguar::GetReverseLimitOK | ( | ) |
Get the status of the reverse limit switch.
double CANJaguar::GetSpeed | ( | ) |
Get the speed of the encoder.
CANJaguar::SpeedReference CANJaguar::GetSpeedReference | ( | ) |
Get the reference source device for speed controller mode.
float CANJaguar::GetTemperature | ( | ) |
void CANJaguar::getTransaction | ( | UINT32 | messageID, |
UINT8 * | data, | ||
UINT8 * | dataSize | ||
) | [protected, virtual] |
Execute a transaction with a Jaguar that gets some property.
Jaguar always generates a message with the same message ID when replying.
messageID | The messageID to read from the CAN bus (device number is added internally) |
data | The up to 8 bytes of data that was received with the message |
dataSize | Indicates how much data was received |
void CANJaguar::PIDWrite | ( | float | output | ) | [virtual] |
Write out the PID value as seen in the PIDOutput base object.
output | Write out the PercentVbus value as was computed by the PIDController |
Implements PIDOutput.
INT32 CANJaguar::receiveMessage | ( | UINT32 * | messageID, |
UINT8 * | data, | ||
UINT8 * | dataSize, | ||
float | timeout = 0.02 |
||
) | [static, protected] |
Receive a message from the CAN bus through the CAN driver in FRC_NetworkCommunication
messageID | The messageID to read from the CAN bus |
data | The up to 8 bytes of data that was received with the message |
dataSize | Indicates how much data was received |
timeout | Specify how long to wait for a message (in seconds) |
INT32 CANJaguar::sendMessage | ( | UINT32 | messageID, |
const UINT8 * | data, | ||
UINT8 | dataSize | ||
) | [static, protected] |
Send a message on the CAN bus through the CAN driver in FRC_NetworkCommunication
Trusted messages require a 2-byte token at the beginning of the data payload. If the message being sent is trusted, make space for the token.
messageID | The messageID to be used on the CAN bus |
data | The up to 8 bytes of data to be sent with the message |
dataSize | Specify how much of the data in "data" to send |
void CANJaguar::Set | ( | float | outputValue, |
UINT8 | syncGroup = 0 |
||
) | [virtual] |
Set the output set-point value.
The scale and the units depend on the mode the Jaguar is in. In PercentVbus Mode, the outputValue is from -1.0 to 1.0 (same as PWM Jaguar). In Voltage Mode, the outputValue is in Volts. In Current Mode, the outputValue is in Amps. In Speed Mode, the outputValue is in Rotations/Minute. In Position Mode, the outputValue is in Rotations.
outputValue | The set-point to sent to the motor controller. |
syncGroup | The update group to add this Set() to, pending UpdateSyncGroup(). If 0, update immediately. |
Implements SpeedController.
void CANJaguar::SetPID | ( | double | p, |
double | i, | ||
double | d | ||
) |
Set the P, I, and D constants for the closed loop modes.
p | The proportional gain of the Jaguar's PID controller. |
i | The integral gain of the Jaguar's PID controller. |
d | The differential gain of the Jaguar's PID controller. |
void CANJaguar::SetPositionReference | ( | PositionReference | reference | ) |
Set the reference source device for position controller mode.
Choose between using and encoder and using a potentiometer as the source of position feedback when in position control mode.
reference | Specify a PositionReference. |
void CANJaguar::SetSpeedReference | ( | SpeedReference | reference | ) |
Set the reference source device for speed controller mode.
Choose encoder as the source of speed feedback when in speed control mode.
reference | Specify a SpeedReference. |
void CANJaguar::setTransaction | ( | UINT32 | messageID, |
const UINT8 * | data, | ||
UINT8 | dataSize | ||
) | [protected, virtual] |
Execute a transaction with a Jaguar that sets some property.
Jaguar always acks when it receives a message. If we don't wait for an ack, the message object in the Jaguar could get overwritten before it is handled.
messageID | The messageID to be used on the CAN bus (device number is added internally) |
data | The up to 8 bytes of data to be sent with the message |
dataSize | Specify how much of the data in "data" to send |
void CANJaguar::SetVoltageRampRate | ( | double | rampRate | ) |
Set the maximum voltage change rate.
When in PercentVbus or Voltage output mode, the rate at which the voltage changes can be limited to reduce current spikes. Set this to 0.0 to disable rate limiting.
rampRate | The maximum rate of voltage change in Percent Voltage mode in V/s. |
void CANJaguar::StopMotor | ( | ) | [virtual] |
Common interface for stopping the motor Part of the MotorSafety interface
Implements MotorSafety.
void CANJaguar::UpdateSyncGroup | ( | UINT8 | syncGroup | ) | [static] |
Update all the motors that have pending sets in the syncGroup.
syncGroup | A bitmask of groups to generate synchronous output. |