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 static class
CANSparkMaxLowLevel.ConfigParameter
protected static class
CANSparkMaxLowLevel.FollowConfig
static class
CANSparkMaxLowLevel.MotorType
static class
CANSparkMaxLowLevel.ParameterStatus
static class
CANSparkMaxLowLevel.ParameterType
static class
CANSparkMaxLowLevel.PeriodicFrame
class
CANSparkMaxLowLevel.PeriodicStatus0
class
CANSparkMaxLowLevel.PeriodicStatus1
class
CANSparkMaxLowLevel.PeriodicStatus2
-
Field Summary
Fields Modifier and Type Field Description static int
kDefaultCANTimeoutMs
static int
kDefaultStatus0PeriodMs
static int
kDefaultStatus1PeriodMs
static int
kDefaultStatus2PeriodMs
static int
kMinFirmwareVersion
static byte
kNumFirmwareRetries
protected edu.wpi.first.wpilibj.CAN
m_can
protected int
m_canTimeoutMs
protected int
m_controlPeriodMs
protected boolean
m_inverted
-
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 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
getMotorType()
Get the motor type setting for the SPARK MAX.java.util.Optional<java.lang.Boolean>
getParameterBoolean(CANSparkMaxLowLevel.ConfigParameter parameterID)
java.util.Optional<java.lang.Integer>
getParameterCore(CANSparkMaxLowLevel.ConfigParameter parameterID, CANSparkMaxLowLevel.ParameterType expectedType)
java.util.Optional<java.lang.Double>
getParameterDouble(CANSparkMaxLowLevel.ConfigParameter parameterID)
java.util.Optional<java.lang.Integer>
getParameterInt(CANSparkMaxLowLevel.ConfigParameter parameterID)
CANSparkMaxLowLevel.ParameterType
getParameterType(CANSparkMaxLowLevel.ConfigParameter parameterID)
protected CANSparkMaxLowLevel.PeriodicStatus0
getPeriodicStatus0()
protected CANSparkMaxLowLevel.PeriodicStatus1
getPeriodicStatus1()
protected CANSparkMaxLowLevel.PeriodicStatus2
getPeriodicStatus2()
float
getSafeFloat(float f)
byte[]
getSerialNumber()
Get the unique serial number of the SPARK MAX.protected static void
notifyOnCANDisconnect()
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.CANError
setEncPosition(double value)
CANError
setIAccum(double value)
CANError
setMotorType(CANSparkMaxLowLevel.MotorType type)
Set the motor type connected to the SPARK MAX.CANSparkMaxLowLevel.ParameterStatus
setParameter(CANSparkMaxLowLevel.ConfigParameter parameterID, boolean value)
CANSparkMaxLowLevel.ParameterStatus
setParameter(CANSparkMaxLowLevel.ConfigParameter parameterID, double value)
CANSparkMaxLowLevel.ParameterStatus
setParameter(CANSparkMaxLowLevel.ConfigParameter parameterID, int value)
CANSparkMaxLowLevel.ParameterStatus
setParameterCore(CANSparkMaxLowLevel.ConfigParameter parameterID, CANSparkMaxLowLevel.ParameterType type, int value)
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
-
kNumFirmwareRetries
public static final byte kNumFirmwareRetries
- See Also:
- Constant Field Values
-
kDefaultCANTimeoutMs
public static final int kDefaultCANTimeoutMs
- See Also:
- Constant Field Values
-
kDefaultStatus0PeriodMs
public static final int kDefaultStatus0PeriodMs
- See Also:
- Constant Field Values
-
kDefaultStatus1PeriodMs
public static final int kDefaultStatus1PeriodMs
- See Also:
- Constant Field Values
-
kDefaultStatus2PeriodMs
public static final int kDefaultStatus2PeriodMs
- See Also:
- Constant Field Values
-
kMinFirmwareVersion
public static final int kMinFirmwareVersion
- See Also:
- Constant Field Values
-
m_can
protected edu.wpi.first.wpilibj.CAN m_can
-
m_controlPeriodMs
protected int m_controlPeriodMs
-
m_canTimeoutMs
protected int m_canTimeoutMs
-
m_inverted
protected boolean m_inverted
-
-
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. Min value 1ms
-
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
-
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
-
setParameter
public CANSparkMaxLowLevel.ParameterStatus setParameter(CANSparkMaxLowLevel.ConfigParameter parameterID, double value)
-
setParameter
public CANSparkMaxLowLevel.ParameterStatus setParameter(CANSparkMaxLowLevel.ConfigParameter parameterID, int value)
-
setParameter
public CANSparkMaxLowLevel.ParameterStatus setParameter(CANSparkMaxLowLevel.ConfigParameter parameterID, boolean value)
-
getParameterDouble
public java.util.Optional<java.lang.Double> getParameterDouble(CANSparkMaxLowLevel.ConfigParameter parameterID)
-
getParameterInt
public java.util.Optional<java.lang.Integer> getParameterInt(CANSparkMaxLowLevel.ConfigParameter parameterID)
-
getParameterBoolean
public java.util.Optional<java.lang.Boolean> getParameterBoolean(CANSparkMaxLowLevel.ConfigParameter parameterID)
-
getSafeFloat
public float getSafeFloat(float f)
-
setEncPosition
public CANError setEncPosition(double value)
-
setIAccum
public 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
-
setParameterCore
public CANSparkMaxLowLevel.ParameterStatus setParameterCore(CANSparkMaxLowLevel.ConfigParameter parameterID, CANSparkMaxLowLevel.ParameterType type, int value)
-
getParameterCore
public java.util.Optional<java.lang.Integer> getParameterCore(CANSparkMaxLowLevel.ConfigParameter parameterID, CANSparkMaxLowLevel.ParameterType expectedType)
-
getParameterType
public CANSparkMaxLowLevel.ParameterType getParameterType(CANSparkMaxLowLevel.ConfigParameter parameterID)
-
getPeriodicStatus0
protected CANSparkMaxLowLevel.PeriodicStatus0 getPeriodicStatus0()
-
getPeriodicStatus1
protected CANSparkMaxLowLevel.PeriodicStatus1 getPeriodicStatus1()
-
getPeriodicStatus2
protected CANSparkMaxLowLevel.PeriodicStatus2 getPeriodicStatus2()
-
notifyOnCANDisconnect
protected static void notifyOnCANDisconnect()
-
-