Package com.revrobotics
Class CANSparkMaxLowLevel
- java.lang.Object
-
- com.revrobotics.CANSparkMaxLowLevel
-
- All Implemented Interfaces:
edu.wpi.first.wpilibj.PIDOutput
,edu.wpi.first.wpilibj.SpeedController
- Direct Known Subclasses:
CANSparkMax
public abstract class CANSparkMaxLowLevel extends java.lang.Object implements edu.wpi.first.wpilibj.SpeedController
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CANSparkMaxLowLevel.FollowConfig
static class
CANSparkMaxLowLevel.MotorType
static class
CANSparkMaxLowLevel.PeriodicFrame
class
CANSparkMaxLowLevel.PeriodicStatus0
class
CANSparkMaxLowLevel.PeriodicStatus1
class
CANSparkMaxLowLevel.PeriodicStatus2
-
Field Summary
Fields Modifier and Type Field Description static int
kAPIBuildVersion
static int
kAPIMajorVersion
static int
kAPIMinorVersion
static int
kAPIVersion
protected CANSparkMaxLowLevel.MotorType
m_motorType
protected long
m_sparkMax
-
Constructor Summary
Constructors Constructor Description CANSparkMaxLowLevel(int deviceID, CANSparkMaxLowLevel.MotorType type)
Create a new SPARK MAX Controller
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
enableExternalUSBControl(boolean enable)
Allow external controllers to recieve control commands over USB.int
getDeviceId()
Get the configured Device ID of the SPARK MAX.java.lang.String
getFirmwareString()
Get the firmware version of the SPARK MAX as a string.int
getFirmwareVersion()
Get the firmware version of the SPARK MAX.CANSparkMaxLowLevel.MotorType
getInitialMotorType()
Get the motor type setting from when the SparkMax was created.CANSparkMaxLowLevel.MotorType
getMotorType()
Get the motor type setting for the SPARK MAX.float
getSafeFloat(float f)
byte[]
getSerialNumber()
Get the unique serial number of the SPARK MAX.CANError
restoreFactoryDefaults()
Restore motor controller parameters to factory default until the next controller rebootCANError
restoreFactoryDefaults(boolean persist)
Restore motor controller parameters to factory defaultvoid
setControlFramePeriodMs(int periodMs)
Set the control frame send period for the native CAN Send thread.protected CANError
setEncPosition(double value)
protected CANError
setIAccum(double value)
CANError
setMotorType(CANSparkMaxLowLevel.MotorType type)
Set the motor type connected to the SPARK MAX.CANError
setPeriodicFramePeriod(CANSparkMaxLowLevel.PeriodicFrame frameID, int periodMs)
Set the rate of transmission for periodic frames from the SPARK MAX Each motor controller sends back three status frames with different data at set rates.
-
-
-
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
-
m_sparkMax
protected long m_sparkMax
-
m_motorType
protected final CANSparkMaxLowLevel.MotorType m_motorType
-
-
Constructor Detail
-
CANSparkMaxLowLevel
public CANSparkMaxLowLevel(int deviceID, CANSparkMaxLowLevel.MotorType type)
Create a new SPARK MAX Controller- Parameters:
deviceID
- The device ID.type
- The motor type connected to the controller. Brushless motors must be connected to their matching color and the hall sensor plugged in. Brushed motors must be connected to the Red and Black terminals only.
-
-
Method Detail
-
getFirmwareVersion
public int getFirmwareVersion()
Get the firmware version of the SPARK MAX.- 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
-
getFirmwareString
public java.lang.String getFirmwareString()
Get the firmware version of the SPARK MAX as a string.- Returns:
- std::string Human readable firmware version string
-
getSerialNumber
public byte[] getSerialNumber()
Get the unique serial number of the SPARK MAX. 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 MAX.- Returns:
- int device ID
-
getInitialMotorType
public CANSparkMaxLowLevel.MotorType getInitialMotorType()
Get the motor type setting from when the SparkMax was created. This does not use the Get Parameter API which means it does not read what motor type is stored on the SparkMax itself. Instead, it reads the stored motor type from when the SparkMax object was first created.- Returns:
- MotorType Motor type setting
-
setMotorType
public CANError setMotorType(CANSparkMaxLowLevel.MotorType type)
Set the motor type connected to the SPARK MAX. This uses the Set Parameter API and should be used infrequently. The parameter does not presist unless burnFlash() is called. The recommended method to configure this parameter is to use the SPARK MAX GUI to tune and save parameters.- Parameters:
type
- The type of motor connected to the controller. Brushless motors must be connected to their matching color and the hall sensor plugged in. Brushed motors must be connected to the Red and Black terminals only.- Returns:
- CANError Set to CANError::kOk if successful
-
getMotorType
public CANSparkMaxLowLevel.MotorType getMotorType()
Get the motor type setting for the SPARK MAX. This uses the Get Parameter API and should be used infrequently. This function uses a non-blocking call and will return a cached value if the parameter is not returned by the timeout. The timeout can be changed by calling SetCANTimeout(int milliseconds)- Returns:
- MotorType Motor type setting
-
setPeriodicFramePeriod
public CANError setPeriodicFramePeriod(CANSparkMaxLowLevel.PeriodicFrame frameID, int periodMs)
Set the rate of transmission for periodic frames from the SPARK MAX Each motor controller sends back three status frames with different data at set rates. Use this function to change the default rates. Defaults: Status0 - 10ms Status1 - 20ms Status2 - 50ms This value is not stored in the FLASH after calling burnFlash() and is reset on powerup. Refer to the SPARK MAX reference manual on details for how and when to configure this parameter.- Parameters:
frameID
- The frame ID can be one of PeriodicFrame typeperiodMs
- The rate the controller sends the frame to the controller.- Returns:
- CANError Set to CANError.kOK if successful
-
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)
-
setEncPosition
protected CANError setEncPosition(double value)
-
setIAccum
protected CANError setIAccum(double value)
-
restoreFactoryDefaults
public CANError restoreFactoryDefaults()
Restore motor controller parameters to factory default until the next controller reboot- Returns:
- CANError Set to CANError::kOk if successful
-
restoreFactoryDefaults
public CANError restoreFactoryDefaults(boolean persist)
Restore motor controller parameters to factory default- Parameters:
persist
- If true, burn the flash with the factory default parameters- Returns:
- CANError Set to CANError::kOk if successful
-
-