edu.wpi.first.wpilibj
Class CANJaguar

java.lang.Object
  extended by edu.wpi.first.wpilibj.CANJaguar
All Implemented Interfaces:
MotorSafety, PIDOutput, SpeedController

public class CANJaguar
extends java.lang.Object
implements MotorSafety, PIDOutput, SpeedController


Nested Class Summary
static class CANJaguar.ControlMode
          Mode determines how the Jaguar is controlled
static class CANJaguar.Faults
          Faults reported by the Jaguar
static class CANJaguar.LimitMode
          Determines which sensor to use for position reference.
static class CANJaguar.Limits
          Limit switch masks
static class CANJaguar.NeutralMode
          Determines how the Jaguar behaves when sending a zero signal.
static class CANJaguar.PositionReference
          Determines which sensor to use for position reference.
static class CANJaguar.SpeedReference
          Determines which sensor to use for speed reference.
 
Field Summary
static double kApproxBusVoltage
           
static int kControllerRate
           
 
Fields inherited from interface edu.wpi.first.wpilibj.MotorSafety
DEFAULT_SAFETY_EXPIRATION
 
Constructor Summary
CANJaguar(int deviceNumber)
          Constructor Default to percent Vbus control mode.
CANJaguar(int deviceNumber, CANJaguar.ControlMode controlMode)
          Constructor
 
Method Summary
 void changeControlMode(CANJaguar.ControlMode controlMode)
          Change the control mode of this Jaguar object.
 void configEncoderCodesPerRev(int codesPerRev)
          Configure how many codes per revolution are generated by your encoder.
 void configFaultTime(double faultTime)
          Configure how long the Jaguar waits in the case of a fault before resuming operation.
 void configMaxOutputVoltage(double voltage)
          Configure the maximum voltage that the Jaguar will ever output.
 void configNeutralMode(CANJaguar.NeutralMode mode)
          Configure what the controller does to the H-Bridge when neutral (not driving the output).
 void configPotentiometerTurns(int turns)
          Configure the number of turns on the potentiometer.
 void configSoftPositionLimits(double forwardLimitPosition, double reverseLimitPosition)
          Configure Soft Position Limits when in Position Controller mode.
 void disable()
          Deprecated. Use disableControl instead.
 void disableControl()
          Disable the closed loop controller.
 void disableSoftPositionLimits()
          Disable Soft Position Limits if previously enabled.
 void enableControl()
          Enable the closed loop controller.
 void enableControl(double encoderInitialPosition)
          Enable the closed loop controller.
 double get()
          Deprecated. Use getX instead.
 double getBusVoltage()
          Get the voltage at the battery input terminals of the Jaguar.
 CANJaguar.ControlMode getControlMode()
          Get the active control mode from the Jaguar.
 double getD()
          Get the Differential gain of the controller.
 java.lang.String getDescription()
           
 double getExpiration()
           
 short getFaults()
          Get the status of any faults the Jaguar has detected.
 int getFirmwareVersion()
          Get the version of the firmware running on the Jaguar.
 boolean getForwardLimitOK()
          Get the status of the forward limit switch.
 byte getHardwareVersion()
          Get the version of the Jaguar hardware.
 double getI()
          Get the Intregral gain of the controller.
 double getOutputCurrent()
          Get the current through the motor terminals of the Jaguar.
 double getOutputVoltage()
          Get the voltage being output from the motor terminals of the Jaguar.
 double getP()
          Get the Proportional gain of the controller.
 double getPosition()
          Get the position of the encoder or potentiometer.
 CANJaguar.PositionReference getPositionReference()
          Get the reference source device for position controller mode.
 boolean getPowerCycled()
          Check if the Jaguar's power has been cycled since this was last called.
 boolean getReverseLimitOK()
          Get the status of the reverse limit switch.
 double getSpeed()
          Get the speed of the encoder.
 CANJaguar.SpeedReference getSpeedReference()
          Get the reference source device for speed controller mode.
 double getTemperature()
          Get the internal temperature of the Jaguar.
protected  byte getTransaction(int messageID, byte[] data)
          Execute a transaction with a Jaguar that gets some property.
 double getX()
          Get the recently set outputValue setpoint.
 boolean isAlive()
           
 boolean isSafetyEnabled()
           
 void pidWrite(double output)
          Deprecated. Use setX instead.
protected static byte receiveMessage(int messageID, byte[] data)
           
protected static byte receiveMessage(int messageID, byte[] data, double timeout)
          Receive a message from the CAN bus through the CAN driver in FRC_NetworkCommunication
protected static void sendMessage(int messageID, byte[] data, int dataSize)
          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.
 void set(double outputValue)
          Deprecated. Use setX instead.
 void set(double outputValue, byte syncGroup)
          Deprecated. Use setX instead.
 void setExpiration(double timeout)
           
 void setPID(double p, double i, double d)
          Set the P, I, and D constants for the closed loop modes.
 void setPositionReference(CANJaguar.PositionReference reference)
          Set the reference source device for position controller mode.
 void setSafetyEnabled(boolean enabled)
           
 void setSpeedReference(CANJaguar.SpeedReference reference)
          Set the reference source device for speed controller mode.
protected  byte setTransaction(int messageID, byte[] data, byte dataSize)
          Execute a transaction with a Jaguar that sets some property.
 void setVoltageRampRate(double rampRate)
          Set the maximum voltage change rate.
 void setX(double outputValue)
          Set the output set-point value.
 void setX(double outputValue, byte syncGroup)
          Set the output set-point value.
 void stopMotor()
          Deprecated. Use disableControl instead.
static void updateSyncGroup(byte syncGroup)
          Update all the motors that have pending sets in the syncGroup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kControllerRate

public static final int kControllerRate
See Also:
Constant Field Values

kApproxBusVoltage

public static final double kApproxBusVoltage
See Also:
Constant Field Values
Constructor Detail

CANJaguar

public CANJaguar(int deviceNumber)
          throws CANTimeoutException
Constructor Default to percent Vbus control mode.

Parameters:
deviceNumber - The address of the Jaguar on the CAN bus.
Throws:
CANTimeoutException

CANJaguar

public CANJaguar(int deviceNumber,
                 CANJaguar.ControlMode controlMode)
          throws CANTimeoutException
Constructor

Parameters:
deviceNumber - The address of the Jaguar on the CAN bus.
controlMode - The control mode that the Jaguar will run in.
Throws:
CANTimeoutException
Method Detail

setX

public void setX(double outputValue)
          throws CANTimeoutException
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:
outputValue - The set-point to sent to the motor controller.
Throws:
CANTimeoutException

set

public void set(double outputValue)
Deprecated. Use setX instead.

Set the output set-point value. Needed by the SpeedControl interface (swallows CANTimeoutExceptions).

Specified by:
set in interface SpeedController
Parameters:
outputValue - The set-point to sent to the motor controller.

setX

public void setX(double outputValue,
                 byte syncGroup)
          throws CANTimeoutException
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:
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.
Throws:
CANTimeoutException

set

public void set(double outputValue,
                byte syncGroup)
Deprecated. Use setX instead.

Set the output set-point value. Needed by the SpeedControl interface (swallows CANTimeoutExceptions).

Specified by:
set in interface SpeedController
Parameters:
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.

getX

public double getX()
            throws CANTimeoutException
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.
Throws:
CANTimeoutException

get

public double get()
Deprecated. Use getX instead.

Get the recently set outputValue setpoint. Needed by the SpeedControl interface (swallows CANTimeoutExceptions).

Specified by:
get in interface SpeedController
Returns:
The most recently set outputValue setpoint.

disable

public void disable()
Deprecated. Use disableControl instead.

Common interface for disabling a motor. Needed by the SpeedControl interface (swallows CANTimeoutExceptions).

Specified by:
disable in interface SpeedController

pidWrite

public void pidWrite(double output)
Deprecated. Use setX instead.

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

Specified by:
pidWrite in interface PIDOutput
Parameters:
output - Write out the percentage voltage value as was computed by the PIDController

sendMessage

protected static void sendMessage(int messageID,
                                  byte[] data,
                                  int dataSize)
                           throws CANTimeoutException
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:
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
Throws:
CANTimeoutException

receiveMessage

protected static byte receiveMessage(int messageID,
                                     byte[] data,
                                     double timeout)
                              throws CANTimeoutException
Receive a message from the CAN bus through the CAN driver in FRC_NetworkCommunication

Parameters:
messageID - The messageID to read from the CAN bus
data - The up to 8 bytes of data that was received with the message
timeout - Specify how long to wait for a message (in seconds)
Throws:
CANTimeoutException

receiveMessage

protected static byte receiveMessage(int messageID,
                                     byte[] data)
                              throws CANTimeoutException
Throws:
CANTimeoutException

setTransaction

protected byte setTransaction(int messageID,
                              byte[] data,
                              byte dataSize)
                       throws CANTimeoutException
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:
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
Throws:
CANTimeoutException

getTransaction

protected byte getTransaction(int messageID,
                              byte[] data)
                       throws CANTimeoutException
Execute a transaction with a Jaguar that gets some property. Jaguar always generates a message with the same message ID when replying.

Parameters:
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
Returns:
Indicates how much data was received
Throws:
CANTimeoutException

setSpeedReference

public void setSpeedReference(CANJaguar.SpeedReference reference)
                       throws CANTimeoutException
Set the reference source device for speed controller mode. Choose encoder as the source of speed feedback when in speed control mode.

Parameters:
reference - Specify a SpeedReference.
Throws:
CANTimeoutException

getSpeedReference

public CANJaguar.SpeedReference getSpeedReference()
                                           throws CANTimeoutException
Get the reference source device for speed controller mode.

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

setPositionReference

public void setPositionReference(CANJaguar.PositionReference reference)
                          throws CANTimeoutException
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:
reference - Specify a PositionReference.
Throws:
CANTimeoutException

getPositionReference

public CANJaguar.PositionReference getPositionReference()
                                                 throws CANTimeoutException
Get the reference source device for position controller mode.

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

setPID

public void setPID(double p,
                   double i,
                   double d)
            throws CANTimeoutException
Set the P, I, and D constants for the closed loop modes.

Parameters:
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.
Throws:
CANTimeoutException

getP

public double getP()
            throws CANTimeoutException
Get the Proportional gain of the controller.

Returns:
The proportional gain.
Throws:
CANTimeoutException

getI

public double getI()
            throws CANTimeoutException
Get the Intregral gain of the controller.

Returns:
The integral gain.
Throws:
CANTimeoutException

getD

public double getD()
            throws CANTimeoutException
Get the Differential gain of the controller.

Returns:
The differential gain.
Throws:
CANTimeoutException

enableControl

public void enableControl()
                   throws CANTimeoutException
Enable the closed loop controller. Start actually controlling the output based on the feedback.

Throws:
CANTimeoutException

enableControl

public void enableControl(double encoderInitialPosition)
                   throws CANTimeoutException
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:
encoderInitialPosition - Encoder position to set if position with encoder reference. Ignored otherwise.
Throws:
CANTimeoutException

disableControl

public void disableControl()
                    throws CANTimeoutException
Disable the closed loop controller. Stop driving the output based on the feedback.

Throws:
CANTimeoutException

changeControlMode

public void changeControlMode(CANJaguar.ControlMode controlMode)
                       throws CANTimeoutException
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:
controlMode - The new mode.
Throws:
CANTimeoutException

getControlMode

public CANJaguar.ControlMode getControlMode()
                                     throws CANTimeoutException
Get the active control mode from the Jaguar. Ask the Jag what mode it is in.

Returns:
ControlMode that the Jag is in.
Throws:
CANTimeoutException

getBusVoltage

public double getBusVoltage()
                     throws CANTimeoutException
Get the voltage at the battery input terminals of the Jaguar.

Returns:
The bus voltage in Volts.
Throws:
CANTimeoutException

getOutputVoltage

public double getOutputVoltage()
                        throws CANTimeoutException
Get the voltage being output from the motor terminals of the Jaguar.

Returns:
The output voltage in Volts.
Throws:
CANTimeoutException

getOutputCurrent

public double getOutputCurrent()
                        throws CANTimeoutException
Get the current through the motor terminals of the Jaguar.

Returns:
The output current in Amps.
Throws:
CANTimeoutException

getTemperature

public double getTemperature()
                      throws CANTimeoutException
Get the internal temperature of the Jaguar.

Returns:
The temperature of the Jaguar in degrees Celsius.
Throws:
CANTimeoutException

getPosition

public double getPosition()
                   throws CANTimeoutException
Get the position of the encoder or potentiometer.

Returns:
The position of the motor based on the configured feedback.
Throws:
CANTimeoutException

getSpeed

public double getSpeed()
                throws CANTimeoutException
Get the speed of the encoder.

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

getForwardLimitOK

public boolean getForwardLimitOK()
                          throws CANTimeoutException
Get the status of the forward limit switch.

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

getReverseLimitOK

public boolean getReverseLimitOK()
                          throws CANTimeoutException
Get the status of the reverse limit switch.

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

getFaults

public short getFaults()
                throws CANTimeoutException
Get the status of any faults the Jaguar has detected.

Returns:
A bit-mask of faults defined by the "Faults" enum class.
Throws:
CANTimeoutException

getPowerCycled

public boolean getPowerCycled()
                       throws CANTimeoutException
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.
Throws:
CANTimeoutException

setVoltageRampRate

public void setVoltageRampRate(double rampRate)
                        throws CANTimeoutException
Set the maximum voltage change rate. When in percent 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:
rampRate - The maximum rate of voltage change in Percent Voltage mode in V/s.
Throws:
CANTimeoutException

getFirmwareVersion

public int getFirmwareVersion()
                       throws CANTimeoutException
Get the version of the firmware running on the Jaguar.

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

getHardwareVersion

public byte getHardwareVersion()
                        throws CANTimeoutException
Get the version of the Jaguar hardware.

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

configNeutralMode

public void configNeutralMode(CANJaguar.NeutralMode mode)
                       throws CANTimeoutException
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:
mode - Select to use the jumper setting or to override it to coast or brake.
Throws:
CANTimeoutException

configEncoderCodesPerRev

public void configEncoderCodesPerRev(int codesPerRev)
                              throws CANTimeoutException
Configure how many codes per revolution are generated by your encoder.

Parameters:
codesPerRev - The number of counts per revolution in 1X mode.
Throws:
CANTimeoutException

configPotentiometerTurns

public void configPotentiometerTurns(int turns)
                              throws CANTimeoutException
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:
turns - The number of turns of the potentiometer
Throws:
CANTimeoutException

configSoftPositionLimits

public void configSoftPositionLimits(double forwardLimitPosition,
                                     double reverseLimitPosition)
                              throws CANTimeoutException
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:
forwardLimitPosition - The position that if exceeded will disable the forward direction.
reverseLimitPosition - The position that if exceeded will disable the reverse direction.
Throws:
CANTimeoutException

disableSoftPositionLimits

public void disableSoftPositionLimits()
                               throws CANTimeoutException
Disable Soft Position Limits if previously enabled. Soft Position Limits are disabled by default.

Throws:
CANTimeoutException

configMaxOutputVoltage

public void configMaxOutputVoltage(double voltage)
                            throws CANTimeoutException
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:
voltage - The maximum voltage output by the Jaguar.
Throws:
CANTimeoutException

configFaultTime

public void configFaultTime(double faultTime)
                     throws CANTimeoutException
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:
faultTime - The time to wait before resuming operation, in seconds.
Throws:
CANTimeoutException

updateSyncGroup

public static void updateSyncGroup(byte syncGroup)
                            throws CANTimeoutException
Update all the motors that have pending sets in the syncGroup.

Parameters:
syncGroup - A bitmask of groups to generate synchronous output.
Throws:
CANTimeoutException

setExpiration

public void setExpiration(double timeout)
Specified by:
setExpiration in interface MotorSafety

getExpiration

public double getExpiration()
Specified by:
getExpiration in interface MotorSafety

isAlive

public boolean isAlive()
Specified by:
isAlive in interface MotorSafety

isSafetyEnabled

public boolean isSafetyEnabled()
Specified by:
isSafetyEnabled in interface MotorSafety

setSafetyEnabled

public void setSafetyEnabled(boolean enabled)
Specified by:
setSafetyEnabled in interface MotorSafety

getDescription

public java.lang.String getDescription()
Specified by:
getDescription in interface MotorSafety

stopMotor

public void stopMotor()
Deprecated. Use disableControl instead.

Common interface for stopping a motor.

Specified by:
stopMotor in interface MotorSafety