Class 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
    • Field Detail

      • 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
      • 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 type
        periodMs - The rate the controller sends the frame to the controller.
        Returns:
        CANError Set to CANError.kOk if successful
      • 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
      • notifyOnCANDisconnect

        protected static void notifyOnCANDisconnect()