Class CANSparkLowLevel
- java.lang.Object
-
- com.revrobotics.CANSparkLowLevel
-
- All Implemented Interfaces:
edu.wpi.first.wpilibj.motorcontrol.MotorController
,java.lang.AutoCloseable
- Direct Known Subclasses:
CANSparkBase
public abstract class CANSparkLowLevel extends java.lang.Object implements edu.wpi.first.wpilibj.motorcontrol.MotorController, java.lang.AutoCloseable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CANSparkLowLevel.FollowConfig
static class
CANSparkLowLevel.MotorType
static class
CANSparkLowLevel.PeriodicFrame
class
CANSparkLowLevel.PeriodicStatus0
class
CANSparkLowLevel.PeriodicStatus1
class
CANSparkLowLevel.PeriodicStatus2
protected static class
CANSparkLowLevel.SparkModel
-
Field Summary
Fields Modifier and Type Field Description protected CANSparkLowLevel.SparkModel
expectedSparkModel
protected java.util.concurrent.atomic.AtomicBoolean
isClosed
static int
kAPIBuildVersion
static int
kAPIMajorVersion
static int
kAPIMinorVersion
static int
kAPIVersion
protected CANSparkLowLevel.MotorType
motorType
protected long
sparkMaxHandle
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Closes the SPARK Controllerstatic void
enableExternalUSBControl(boolean enable)
Allow external controllers to recieve control commands over USB.int
getDeviceId()
Get the configured Device ID of the SPARK.java.lang.String
getFirmwareString()
Get the firmware version of the SPARK as a string.int
getFirmwareVersion()
Get the firmware version of the SPARK.CANSparkLowLevel.MotorType
getInitialMotorType()
Deprecated, for removal: This API element is subject to removal in a future version.UsegetMotorType()
insteadCANSparkLowLevel.MotorType
getMotorType()
Get the motor type setting for the SPARKfloat
getSafeFloat(float f)
byte[]
getSerialNumber()
Get the unique serial number of the SPARK.REVLibError
restoreFactoryDefaults()
Restore motor controller parameters to factory default until the next controller rebootREVLibError
restoreFactoryDefaults(boolean persist)
Restore motor controller parameters to factory defaultvoid
setCANMaxRetries(int numRetries)
Set the maximum number of times to retry an RTR CAN frame.void
setControlFramePeriodMs(int periodMs)
Set the control frame send period for the native CAN Send thread.REVLibError
setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame frame, int periodMs)
Set the rate of transmission for periodic frames from the SPARKREVLibError
setPeriodicFramePeriod(CANSparkMaxLowLevel.PeriodicFrame frame, int periodMs)
Deprecated, for removal: This API element is subject to removal in a future version.void
setPeriodicFrameTimeout(int timeoutMs)
Set the amount of time to wait for a periodic status frame before returning a timeout error.protected void
throwIfClosed()
-
-
-
Field Detail
-
kAPIMajorVersion
public static final int kAPIMajorVersion
-
kAPIMinorVersion
public static final int kAPIMinorVersion
-
kAPIBuildVersion
public static final int kAPIBuildVersion
-
kAPIVersion
public static final int kAPIVersion
-
sparkMaxHandle
protected final long sparkMaxHandle
-
isClosed
protected final java.util.concurrent.atomic.AtomicBoolean isClosed
-
motorType
protected final CANSparkLowLevel.MotorType motorType
-
expectedSparkModel
protected final CANSparkLowLevel.SparkModel expectedSparkModel
-
-
Method Detail
-
close
public void close()
Closes the SPARK Controller- Specified by:
close
in interfacejava.lang.AutoCloseable
-
getFirmwareVersion
public int getFirmwareVersion()
Get the firmware version of the SPARK.- Returns:
- uint32_t Firmware version integer. Value is represented as 4 bytes, Major.Minor.Build H.Build L
-
setControlFramePeriodMs
public void setControlFramePeriodMs(int periodMs)
Set the control frame send period for the native CAN Send thread.- Parameters:
periodMs
- The send period in milliseconds between 1ms and 100ms or set to 0 to disable periodic sends. Note this is not updated until the next call to Set() or SetReference().
-
getFirmwareString
public java.lang.String getFirmwareString()
Get the firmware version of the SPARK as a string.- Returns:
- std::string Human readable firmware version string
-
getSerialNumber
public byte[] getSerialNumber()
Get the unique serial number of the SPARK. Not currently available.- Returns:
- byte[] Vector of bytes representig the unique serial number
-
getDeviceId
public int getDeviceId()
Get the configured Device ID of the SPARK.- Returns:
- int device ID
-
getInitialMotorType
@Deprecated(forRemoval=true) public CANSparkLowLevel.MotorType getInitialMotorType()
Deprecated, for removal: This API element is subject to removal in a future version.UsegetMotorType()
insteadGet the motor type setting for the SPARK- Returns:
- MotorType Motor type setting
-
getMotorType
public CANSparkLowLevel.MotorType getMotorType()
Get the motor type setting for the SPARK- Returns:
- MotorType Motor type setting
-
setPeriodicFramePeriod
public REVLibError setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame frame, int periodMs)
Set the rate of transmission for periodic frames from the SPARKEach motor controller sends back status frames with different data at set rates. Use this function to change the default rates.
Defaults: Status0 - 10ms Status1 - 20ms Status2 - 20ms Status3 - 50ms Status4 - 20ms Status5 - 200ms Status6 - 200ms Status7 - 250ms
This value is not stored in the FLASH after calling burnFlash() and is reset on powerup.
Refer to the SPARK reference manual on details for how and when to configure this parameter.
- Parameters:
frame
- Which type of periodic frame to change the period ofperiodMs
- The rate the controller sends the frame to the controller.- Returns:
REVLibError.kOk
if successful
-
setPeriodicFramePeriod
@Deprecated(forRemoval=true) public REVLibError setPeriodicFramePeriod(CANSparkMaxLowLevel.PeriodicFrame frame, int periodMs)
Deprecated, for removal: This API element is subject to removal in a future version.Set the rate of transmission for periodic frames from the SPARKEach motor controller sends back status frames with different data at set rates. Use this function to change the default rates.
Defaults: Status0 - 10ms Status1 - 20ms Status2 - 20ms Status3 - 50ms Status4 - 20ms Status5 - 200ms Status6 - 200ms Status7 - 250ms
This value is not stored in the FLASH after calling burnFlash() and is reset on powerup.
Refer to the SPARK reference manual on details for how and when to configure this parameter.
- Parameters:
frame
- Which type of periodic frame to change the period ofperiodMs
- The rate the controller sends the frame to the controller.- Returns:
REVLibError.kOk
if successful
-
setPeriodicFrameTimeout
public void setPeriodicFrameTimeout(int timeoutMs)
Set the amount of time to wait for a periodic status frame before returning a timeout error. This timeout will apply to all periodic status frames for the SPARK motor controller.To prevent invalid timeout errors, the minimum timeout for a given periodic status is 2.1 times its period. To use the minimum timeout for all status frames, set timeoutMs to 0.
The default timeout is 500ms.
- Parameters:
timeoutMs
- The timeout in milliseconds
-
setCANMaxRetries
public void setCANMaxRetries(int numRetries)
Set the maximum number of times to retry an RTR CAN frame. This applies to calls such as SetParameter* and GetParameter* where a request is made to the SPARK motor controller and a response is expected. Anytime sending the request or receiving the response fails, it will retry the request a number of times, no more than the value set by this method. If an attempt succeeds, it will immediately return. The minimum number of retries is 0, where only a single attempt will be made and will return regardless of success or failure.If the CAN timeout is set to 0 with
CANSparkBase.setCANTimeout(int)
, this will have no effect when getting the response from the SPARK motor controller fails. However, it will retry when sending the request from the roboRIO fails.The default maximum is 5 retries.
- Parameters:
numRetries
- The maximum number of retries
-
enableExternalUSBControl
public static void enableExternalUSBControl(boolean enable)
Allow external controllers to recieve control commands over USB. For example, a configuration where the heartbeat (and enable/disable) is sent by the main controller, but control frames are sent by other CAN devices over USB.This is global for all controllers on the same bus.
This does not disable sending control frames from this device. To prevent conflicts, do not enable this feature and also send Set() for SetReference() from the controllers you wish to control.
- Parameters:
enable
- Enable or disable external control
-
getSafeFloat
public float getSafeFloat(float f)
-
restoreFactoryDefaults
public REVLibError restoreFactoryDefaults()
Restore motor controller parameters to factory default until the next controller reboot- Returns:
REVLibError.kOk
if successful
-
restoreFactoryDefaults
public REVLibError restoreFactoryDefaults(boolean persist)
Restore motor controller parameters to factory default- Parameters:
persist
- If true, burn the flash with the factory default parameters- Returns:
REVLibError.kOk
if successful
-
throwIfClosed
protected void throwIfClosed()
-
-