Now you can download a copy of these docs so you can use them offline! Download now

#include <CANJaguar.h>

Inheritance diagram for CANJaguar:
Collaboration diagram for CANJaguar:

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_t deviceNumber, ControlMode controlMode=kPercentVbus)
 
virtual float Get ()
 
virtual void Set (float value, uint8_t 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_t GetFaults ()
 
bool GetPowerCycled ()
 
void SetVoltageRampRate (double rampRate)
 
virtual uint32_t GetFirmwareVersion ()
 
uint8_t GetHardwareVersion ()
 
void ConfigNeutralMode (NeutralMode mode)
 
void ConfigEncoderCodesPerRev (uint16_t codesPerRev)
 
void ConfigPotentiometerTurns (uint16_t 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)
 
- Public Member Functions inherited from ErrorBase
virtual ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (ErrorBase *rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Static Public Member Functions

static void UpdateSyncGroup (uint8_t syncGroup)
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static void SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 

Static Public Attributes

static const int32_t kControllerRate = 1000
 
static constexpr double kApproxBusVoltage = 12.0
 

Protected Member Functions

uint8_t packPercentage (uint8_t *buffer, double value)
 
uint8_t packFXP8_8 (uint8_t *buffer, double value)
 
uint8_t packFXP16_16 (uint8_t *buffer, double value)
 
uint8_t packint16_t (uint8_t *buffer, int16_t value)
 
uint8_t packint32_t (uint8_t *buffer, int32_t value)
 
double unpackPercentage (uint8_t *buffer)
 
double unpackFXP8_8 (uint8_t *buffer)
 
double unpackFXP16_16 (uint8_t *buffer)
 
int16_t unpackint16_t (uint8_t *buffer)
 
int32_t unpackint32_t (uint8_t *buffer)
 
virtual void setTransaction (uint32_t messageID, const uint8_t *data, uint8_t dataSize)
 
virtual void getTransaction (uint32_t messageID, uint8_t *data, uint8_t *dataSize)
 
void ValueChanged (ITable *source, const std::string &key, EntryValue value, bool isNew)
 
void UpdateTable ()
 
void StartLiveWindowMode ()
 
void StopLiveWindowMode ()
 
std::string GetSmartDashboardType ()
 
void InitTable (ITable *subTable)
 
ITableGetTable ()
 
- Protected Member Functions inherited from ErrorBase
 ErrorBase ()
 Initialize the instance status to 0 for now.
 

Static Protected Member Functions

static int32_t sendMessage (uint32_t messageID, const uint8_t *data, uint8_t dataSize)
 
static int32_t receiveMessage (uint32_t *messageID, uint8_t *data, uint8_t *dataSize, float timeout=0.02)
 

Protected Attributes

uint8_t m_deviceNumber
 
ControlMode m_controlMode
 
SEM_ID m_transactionSemaphore
 
double m_maxOutputVoltage
 
MotorSafetyHelperm_safetyHelper
 
ITablem_table
 
- Protected Attributes inherited from ErrorBase
Error m_error
 

Additional Inherited Members

- Static Protected Attributes inherited from ErrorBase
static SEM_ID _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE)
 
static Error _globalError
 

Detailed Description

Luminary Micro Jaguar Speed Control

Definition at line 24 of file CANJaguar.h.

Constructor & Destructor Documentation

CANJaguar::CANJaguar ( uint8_t  deviceNumber,
ControlMode  controlMode = kPercentVbus 
)
explicit

Constructor

Parameters
deviceNumberThe the address of the Jaguar on the CAN bus.

Definition at line 82 of file CANJaguar.cpp.

Member Function Documentation

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.

Parameters
controlModeThe new mode.

Definition at line 771 of file CANJaguar.cpp.

void CANJaguar::ConfigEncoderCodesPerRev ( uint16_t  codesPerRev)

Configure how many codes per revolution are generated by your encoder.

Parameters
codesPerRevThe number of counts per revolution in 1X mode.

Definition at line 1084 of file CANJaguar.cpp.

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.

Parameters
faultTimeThe time to wait before resuming operation, in seconds.

Definition at line 1176 of file CANJaguar.cpp.

void CANJaguar::ConfigMaxOutputVoltage ( double  voltage)

Configure the maximum voltage that the Jaguar will ever output.

This can be used to limit the maximum output voltage in all modes so that motors which cannot withstand full bus voltage can be used safely.

Parameters
voltageThe maximum voltage output by the Jaguar.

Definition at line 1158 of file CANJaguar.cpp.

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.

Parameters
modeSelect to use the jumper setting or to override it to coast or brake.

Definition at line 1071 of file CANJaguar.cpp.

void CANJaguar::ConfigPotentiometerTurns ( uint16_t  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.

Parameters
turnsThe number of turns of the potentiometer

Definition at line 1101 of file CANJaguar.cpp.

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.

Parameters
forwardLimitPositionThe position that if exceeded will disable the forward direction.
reverseLimitPositionThe position that if exceeded will disable the reverse direction.

Definition at line 1120 of file CANJaguar.cpp.

void CANJaguar::Disable ( )
virtual

Common interface for disabling a motor.

Deprecated:
Call DisableControl instead.

Implements SpeedController.

Definition at line 233 of file CANJaguar.cpp.

void CANJaguar::DisableControl ( )

Disable the closed loop controller.

Stop driving the output based on the feedback.

Definition at line 738 of file CANJaguar.cpp.

void CANJaguar::DisableSoftPositionLimits ( )

Disable Soft Position Limits if previously enabled.

Soft Position Limits are disabled by default.

Definition at line 1142 of file CANJaguar.cpp.

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.

Parameters
encoderInitialPositionEncoder position to set if position with encoder reference. Ignored otherwise.

Definition at line 707 of file CANJaguar.cpp.

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.

Returns
The most recently set outputValue setpoint.

Implements SpeedController.

Definition at line 182 of file CANJaguar.cpp.

float CANJaguar::GetBusVoltage ( )

Get the voltage at the battery input terminals of the Jaguar.

Returns
The bus voltage in Volts.

Definition at line 807 of file CANJaguar.cpp.

CANJaguar::ControlMode CANJaguar::GetControlMode ( )

Get the active control mode from the Jaguar.

Ask the Jag what mode it is in.

Returns
ControlMode that the Jag is in.

Definition at line 789 of file CANJaguar.cpp.

double CANJaguar::GetD ( )

Get the Differential gain of the controller.

Returns
The differential gain.

Definition at line 661 of file CANJaguar.cpp.

uint16_t CANJaguar::GetFaults ( )

Get the status of any faults the Jaguar has detected.

Returns
A bit-mask of faults defined by the "Faults" enum.

Definition at line 952 of file CANJaguar.cpp.

uint32_t CANJaguar::GetFirmwareVersion ( )
virtual

Get the version of the firmware running on the Jaguar.

Returns
The firmware version. 0 if the device did not respond.

Definition at line 1028 of file CANJaguar.cpp.

bool CANJaguar::GetForwardLimitOK ( )

Get the status of the forward limit switch.

Returns
The motor is allowed to turn in the forward direction when true.

Definition at line 916 of file CANJaguar.cpp.

uint8_t CANJaguar::GetHardwareVersion ( )

Get the version of the Jaguar hardware.

Returns
The hardware version. 1: Jaguar, 2: Black Jaguar

Definition at line 1047 of file CANJaguar.cpp.

double CANJaguar::GetI ( )

Get the Intregral gain of the controller.

Returns
The integral gain.

Definition at line 620 of file CANJaguar.cpp.

float CANJaguar::GetOutputCurrent ( )

Get the current through the motor terminals of the Jaguar.

Returns
The output current in Amps.

Definition at line 844 of file CANJaguar.cpp.

float CANJaguar::GetOutputVoltage ( )

Get the voltage being output from the motor terminals of the Jaguar.

Returns
The output voltage in Volts.

Definition at line 825 of file CANJaguar.cpp.

double CANJaguar::GetP ( )

Get the Proportional gain of the controller.

Returns
The proportional gain.

Definition at line 579 of file CANJaguar.cpp.

double CANJaguar::GetPosition ( )

Get the position of the encoder or potentiometer.

Returns
The position of the motor in rotations based on the configured feedback.

Definition at line 880 of file CANJaguar.cpp.

CANJaguar::PositionReference CANJaguar::GetPositionReference ( )

Get the reference source device for position controller mode.

Returns
A PositionReference indicating the currently selected reference device for position controller mode.

Definition at line 516 of file CANJaguar.cpp.

bool CANJaguar::GetPowerCycled ( )

Check if the Jaguar's power has been cycled since this was last called.

This should return true the first time called after a Jaguar power up, and false after that.

Returns
The Jaguar was power cycled since the last call to this function.

Definition at line 973 of file CANJaguar.cpp.

bool CANJaguar::GetReverseLimitOK ( )

Get the status of the reverse limit switch.

Returns
The motor is allowed to turn in the reverse direction when true.

Definition at line 934 of file CANJaguar.cpp.

std::string CANJaguar::GetSmartDashboardType ( )
protectedvirtual
Returns
the string representation of the named data type that will be used by the smart dashboard for this sendable

Implements Sendable.

Definition at line 1263 of file CANJaguar.cpp.

double CANJaguar::GetSpeed ( )

Get the speed of the encoder.

Returns
The speed of the motor in RPM based on the configured feedback.

Definition at line 898 of file CANJaguar.cpp.

CANJaguar::SpeedReference CANJaguar::GetSpeedReference ( )

Get the reference source device for speed controller mode.

Returns
A SpeedReference indicating the currently selected reference device for speed controller mode.

Definition at line 482 of file CANJaguar.cpp.

ITable * CANJaguar::GetTable ( )
protectedvirtual
Returns
the table that is currently associated with the sendable

Implements Sendable.

Definition at line 1272 of file CANJaguar.cpp.

float CANJaguar::GetTemperature ( )

Get the internal temperature of the Jaguar.

Returns
The temperature of the Jaguar in degrees Celsius.

Definition at line 862 of file CANJaguar.cpp.

void CANJaguar::getTransaction ( uint32_t  messageID,
uint8_t *  data,
uint8_t *  dataSize 
)
protectedvirtual

Execute a transaction with a Jaguar that gets some property.

Jaguar always generates a message with the same message ID when replying.

Parameters
messageIDThe messageID to read from the CAN bus (device number is added internally)
dataThe up to 8 bytes of data that was received with the message
dataSizeIndicates how much data was received

Definition at line 430 of file CANJaguar.cpp.

void CANJaguar::InitTable ( ITable subtable)
protectedvirtual

Initializes a table for this sendable object.

Parameters
subtableThe table to put the values in.

Implements Sendable.

Definition at line 1267 of file CANJaguar.cpp.

void CANJaguar::PIDWrite ( float  output)
virtual

Write out the PID value as seen in the PIDOutput base object.

Deprecated:
Call Set instead.
Parameters
outputWrite out the PercentVbus value as was computed by the PIDController

Implements PIDOutput.

Definition at line 245 of file CANJaguar.cpp.

int32_t CANJaguar::receiveMessage ( uint32_t *  messageID,
uint8_t *  data,
uint8_t *  dataSize,
float  timeout = 0.02 
)
staticprotected

Receive a message from the CAN bus through the CAN driver in FRC_NetworkCommunication

Parameters
messageIDThe messageID to read from the CAN bus
dataThe up to 8 bytes of data that was received with the message
dataSizeIndicates how much data was received
timeoutSpecify how long to wait for a message (in seconds)
Returns
Status of receive call

Definition at line 377 of file CANJaguar.cpp.

int32_t CANJaguar::sendMessage ( uint32_t  messageID,
const uint8_t *  data,
uint8_t  dataSize 
)
staticprotected

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.

Parameters
messageIDThe messageID to be used on the CAN bus
dataThe up to 8 bytes of data to be sent with the message
dataSizeSpecify how much of the data in "data" to send
Returns
Status of send call

Definition at line 334 of file CANJaguar.cpp.

void CANJaguar::Set ( float  outputValue,
uint8_t  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.

Parameters
outputValueThe set-point to sent to the motor controller.
syncGroupThe update group to add this Set() to, pending UpdateSyncGroup(). If 0, update immediately.

Implements SpeedController.

Definition at line 113 of file CANJaguar.cpp.

void CANJaguar::SetPID ( double  p,
double  i,
double  d 
)

Set the P, I, and D constants for the closed loop modes.

Parameters
pThe proportional gain of the Jaguar's PID controller.
iThe integral gain of the Jaguar's PID controller.
dThe differential gain of the Jaguar's PID controller.

Definition at line 536 of file CANJaguar.cpp.

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.

Parameters
referenceSpecify a PositionReference.

Definition at line 503 of file CANJaguar.cpp.

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.

Parameters
referenceSpecify a SpeedReference.

Definition at line 469 of file CANJaguar.cpp.

void CANJaguar::setTransaction ( uint32_t  messageID,
const uint8_t *  data,
uint8_t  dataSize 
)
protectedvirtual

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.

Parameters
messageIDThe messageID to be used on the CAN bus (device number is added internally)
dataThe up to 8 bytes of data to be sent with the message
dataSizeSpecify how much of the data in "data" to send

Definition at line 395 of file CANJaguar.cpp.

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.

Parameters
rampRateThe maximum rate of voltage change in Percent Voltage mode in V/s.

Definition at line 1003 of file CANJaguar.cpp.

void CANJaguar::StartLiveWindowMode ( )
protectedvirtual

Start having this sendable object automatically respond to value changes reflect the value on the table.

Implements LiveWindowSendable.

Definition at line 1251 of file CANJaguar.cpp.

void CANJaguar::StopLiveWindowMode ( )
protectedvirtual

Stop having this sendable object automatically respond to value changes.

Implements LiveWindowSendable.

Definition at line 1257 of file CANJaguar.cpp.

void CANJaguar::StopMotor ( )
virtual

Common interface for stopping the motor Part of the MotorSafety interface

Deprecated:
Call DisableControl instead.

Implements MotorSafety.

Definition at line 1236 of file CANJaguar.cpp.

void CANJaguar::UpdateSyncGroup ( uint8_t  syncGroup)
static

Update all the motors that have pending sets in the syncGroup.

Parameters
syncGroupA bitmask of groups to generate synchronous output.

Definition at line 1191 of file CANJaguar.cpp.

void CANJaguar::UpdateTable ( )
protectedvirtual

Update the table for this sendable object with the latest values.

Implements LiveWindowSendable.

Definition at line 1245 of file CANJaguar.cpp.

void CANJaguar::ValueChanged ( ITable source,
const std::string &  key,
EntryValue  value,
bool  isNew 
)
protectedvirtual

Called when a key-value pair is changed in a ITable WARNING: If a new key-value is put in this method value changed will immediatly be called which could lead to recursive code

Parameters
sourcethe table the key-value pair exists in
keythe key associated with the value that changed
valuethe new value
isNewtrue if the key did not previously exist in the table, otherwise it is false

Implements ITableListener.

Definition at line 1241 of file CANJaguar.cpp.


The documentation for this class was generated from the following files:

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6