Class CANdle

java.lang.Object
com.ctre.phoenix.led.CANdle

public class CANdle
extends Object
CTRE CANdle Device for controlling LEDs from the CAN bus.
 
 // Example usage of a CANdle
 CANdle candle = new CANdle(0); // creates a new CANdle with ID 0

 CANdleConfiguration config = new CANdleConfiguration();
 config.stripType = LEDStripType.RGB; // set the strip type to RGB
 config.brightnessScalar = 0.5; // dim the LEDs to half brightness
 candle.configAllSettings(config);

 candle.setLEDs(255, 255, 255); // set the CANdle LEDs to white

 // create a rainbow animation:
 // - max brightness
 // - half speed
 // - 64 LEDs
 RainbowAnimation rainbowAnim = new RainbowAnimation(1, 0.5, 64);
 candle.animate(rainbowAnim);

 ErrorCode error = candle.getLastError(); // gets the last error generated by the CANdle
 CANdleFaults faults = new CANdleFaults();
 ErrorCode faultsError = candle.getFaults(faults); // fills faults with the current CANdle faults; returns the last error generated
 
 
  • Constructor Details

    • CANdle

      public CANdle​(int deviceId, String canbus)
      Constructor for a CANdle Device
      Parameters:
      deviceId - The Device ID of the CANdle
      canbus - Name of the CANbus; can be a SocketCAN interface (on Linux), or a CANivore device name or serial number
    • CANdle

      public CANdle​(int deviceId)
      Constructor for a CANdle Device
      Parameters:
      deviceId - The Device ID of the CANdle
  • Method Details

    • destroyObject

    • getBusVoltage

      public double getBusVoltage()
      Gets the Voltage of VBat as measured by CANdle
      Returns:
      Voltage of VBat
    • get5VRailVoltage

      public double get5VRailVoltage()
      Gets the Voltage of the 5V line as measured by CANdle
      Returns:
      Voltage of the 5V line
    • getCurrent

      public double getCurrent()
      Gets the low-side current as measured by CANdle
      Returns:
      Current in Amps
    • getTemperature

      public double getTemperature()
      Gets the temperature of the CANdle in Celcius
      Returns:
      Temperature in Celcius
    • getVBatModulation

      public double getVBatModulation()
      Gets the applied vbat modulation in percent. If the CANdle is configured to always enable VBat, this returns 1 If the CANdle is confgigured to always disable VBat, this returns 0 Otherwise it returns the last set Modulation as a value [0, 1]
      Returns:
      VBat Output Modulation
    • getMaxSimultaneousAnimationCount

      Gets the maximum number of simultaneous animations this version of CANdle firmware supports. If you specify an animation slot >= to this return, Phoenix will error out. You can also get the maximum count from a self-test snapshot.
      Returns:
      Maximum number of simultaneous animations this version of firmware supports.
    • animate

      public ErrorCode animate​(Animation animation)
      Animates the CANdle with the passed-in animation If the animation changes after calling this function, it must be passed into animate again for the changes to take effect
      Parameters:
      animation - The animation that CANdle will run. If this is null, it will clear the animation at the specified slot
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • animate

      public ErrorCode animate​(Animation animation, int animSlot)
      Animates the CANdle with the passed-in animation If the animation changes after calling this function, it must be passed into animate again for the changes to take effect
      Parameters:
      animation - The animation that CANdle will run. If this is null, it will clear the animation at the specified slot
      animSlot - The animation slot to use for the animation, range is [0, getMaxSimultaneousAnimationCount()) exclusive
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • clearAnimation

      public ErrorCode clearAnimation​(int animSlot)
      Clears the animation occurring in the selected selected animSlot.
      Parameters:
      animSlot - Animation slot to clear
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • setLEDs

      public ErrorCode setLEDs​(int r, int g, int b, int w, int startIdx, int count)
      Sets a block of LEDs to the specified color
      Parameters:
      r - The amount of Red to set, range is [0, 255]
      g - The amount of Green to set, range is [0, 255]
      b - The amount of Blue to set, range is [0, 255]
      w - The amount of White to set, range is [0, 255]. This only applies for LED strips with white in them.
      startIdx - Where to start setting the LEDs
      count - The number of LEDs to apply this to
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • setLEDs

      public ErrorCode setLEDs​(int r, int g, int b)
      Sets a block of LEDs to the specified color.
      Parameters:
      r - The amount of Red to set, range is [0, 255]
      g - The amount of Green to set, range is [0, 255]
      b - The amount of Blue to set, range is [0, 255]
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • modulateVBatOutput

      public ErrorCode modulateVBatOutput​(double dutyCyclePrcnt)
      Modulates the VBat output to the specified duty cycle percentage This function will only do something if the CANdle's VBatOutput is configured to Modulated
      Parameters:
      dutyCyclePrcnt - The duty cycle of the output modulation [0, 1]
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • configLOSBehavior

      public ErrorCode configLOSBehavior​(boolean disableWhenLOS, int timeoutMs)
      Configures what the CANdle should do if it loses communications to the Controller
      Parameters:
      disableWhenLOS - Set to true to disable the LEDs on Loss of Signal.
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • configLOSBehavior

      public ErrorCode configLOSBehavior​(boolean disableWhenLOS)
      Configures what the CANdle should do if it loses communications to the Controller
      Parameters:
      disableWhenLOS - Set to true to disable the LEDs on Loss of Signal.
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • configLEDType

      public ErrorCode configLEDType​(CANdle.LEDStripType type, int timeoutMs)
      Configures the type of LED the CANdle controls
      Parameters:
      type - The type of the LEDs the CANdle controls
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • configLEDType

      Configures the type of LED the CANdle controls
      Parameters:
      type - The type of the LEDs the CANdle controls
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • configBrightnessScalar

      public ErrorCode configBrightnessScalar​(double brightness, int timeoutMs)
      Configures the brightness scalar to be applied to every LED output. This value is bounded to [0, 1]. Setting this to 1 will allow the LEDs to function at max brightness. Setting this to 0.5 will scale all values to half their applied value. Setting this to 0 will turn off the LEDs. Forcing the LEDs off this way may be useful in certain testing circumstances but is generally not necessary. Self-test (Tuner) may be used to verify what the effective scalar is in case user forgot to restore the scalar to a non-zero value.
      Parameters:
      brightness - Value from [0, 1] that will scale the LED output.
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configBrightnessScalar

      public ErrorCode configBrightnessScalar​(double brightness)
      Configures the brightness scalar to be applied to every LED output. This value is bounded to [0, 1]. Setting this to 1 will allow the LEDs to function at max brightness. Setting this to 0.5 will scale all values to half their applied value. Setting this to 0 will turn off the LEDs. Forcing the LEDs off this way may be useful in certain testing circumstances but is generally not necessary. Self-test (Tuner) may be used to verify what the effective scalar is in case user forgot to restore the scalar to a non-zero value.
      Parameters:
      brightness - Value from [0, 1] that will scale the LED output.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configStatusLedState

      public ErrorCode configStatusLedState​(boolean disableWhenRunning, int timeoutMs)
      Configures how the status led will behave when the CANdle is actively controlling LEDs If the CANdle is LOS or not actively commanded a value, it will always turn on its status LED.
      Parameters:
      disableWhenRunning - Disables the status LED when the CANdle is running
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configStatusLedState

      public ErrorCode configStatusLedState​(boolean disableWhenRunning)
      Configures how the status led will behave when the CANdle is actively controlling LEDs If the CANdle is LOS or not actively commanded a value, it will always turn on its status LED.
      Parameters:
      disableWhenRunning - Disables the status LED when the CANdle is running
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configVBatOutput

      public ErrorCode configVBatOutput​(CANdle.VBatOutputMode mode, int timeoutMs)
      Configures how the VBat Output will behave
      Parameters:
      mode - VBat Output Behavior
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configVBatOutput

      Configures how the VBat Output will behave
      Parameters:
      mode - VBat Output Behavior
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configV5Enabled

      public ErrorCode configV5Enabled​(boolean enable5V, int timeoutMs)
      Configures the enable state for the 5V rail. This also affects the on-board LEDs.
      Parameters:
      enable5V - True to enable the 5V rail.
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • configV5Enabled

      public ErrorCode configV5Enabled​(boolean enable5V)
      Configures the enable state for the 5V rail. This also disables the on-board LEDs.
      Parameters:
      enable5V - True to enable the 5V rail.
      Returns:
      ErrorCode generated by function. OK indicates no error.
    • configGetParameter

      public double configGetParameter​(ParamEnum param, int ordinal, int timeoutMs)
      Gets a parameter. Generally this is not used. This can be utilized in - Using new features without updating API installation. - Errata workarounds to circumvent API implementation. - Allows for rapid testing / unit testing of firmware.
      Parameters:
      param - Parameter enumeration.
      ordinal - Ordinal of parameter.
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Value of parameter.
    • configGetParameter

      public double configGetParameter​(ParamEnum param, int ordinal)
      Gets a parameter. Generally this is not used. This can be utilized in - Using new features without updating API installation. - Errata workarounds to circumvent API implementation. - Allows for rapid testing / unit testing of firmware.
      Parameters:
      param - Parameter enumeration.
      ordinal - Ordinal of parameter.
      Returns:
      Value of parameter.
    • configSetParameter

      public ErrorCode configSetParameter​(ParamEnum param, double value, int subValue, int ordinal, int timeoutMs)
      Sets a parameter. Generally this is not used. This can be utilized in - Using new features without updating API installation. - Errata workarounds to circumvent API implementation. - Allows for rapid testing / unit testing of firmware.
      Parameters:
      param - Parameter enumeration.
      value - Value of parameter.
      subValue - Subvalue for parameter. Maximum value of 255.
      ordinal - Ordinal of parameter.
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configSetParameter

      public ErrorCode configSetParameter​(ParamEnum param, double value, int subValue, int ordinal)
      Sets a parameter. Generally this is not used. This can be utilized in - Using new features without updating API installation. - Errata workarounds to circumvent API implementation. - Allows for rapid testing / unit testing of firmware.
      Parameters:
      param - Parameter enumeration.
      value - Value of parameter.
      subValue - Subvalue for parameter. Maximum value of 255.
      ordinal - Ordinal of parameter.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configGetCustomParam

      public int configGetCustomParam​(int paramIndex, int timeoutMs)
      Gets the value of a custom parameter. This is for arbitrary use. Sometimes it is necessary to save calibration/duty cycle/output information in the device. Particularly if the device is part of a subsystem that can be replaced.
      Parameters:
      paramIndex - Index of custom parameter. [0-1]
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Value of the custom param.
    • configGetCustomParam

      public int configGetCustomParam​(int paramIndex)
      Gets the value of a custom parameter. This is for arbitrary use. Sometimes it is necessary to save calibration/duty cycle/output information in the device. Particularly if the device is part of a subsystem that can be replaced.
      Parameters:
      paramIndex - Index of custom parameter. [0-1]
      Returns:
      Value of the custom param.
    • configSetCustomParam

      public ErrorCode configSetCustomParam​(int paramIndex, int value, int timeoutMs)
      Sets the value of a custom parameter. This is for arbitrary use. Sometimes it is necessary to save calibration/duty cycle/output information in the device. Particularly if the device is part of a subsystem that can be replaced.
      Parameters:
      paramIndex - Index of custom parameter. [0-1]
      value - Value for custom parameter.
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configSetCustomParam

      public ErrorCode configSetCustomParam​(int paramIndex, int value)
      Sets the value of a custom parameter. This is for arbitrary use. Sometimes it is necessary to save calibration/duty cycle/output information in the device. Particularly if the device is part of a subsystem that can be replaced.
      Parameters:
      paramIndex - Index of custom parameter. [0-1]
      value - Value for custom parameter.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configFactoryDefault

      public ErrorCode configFactoryDefault​(int timeoutMs)
      Configures all persistent settings to defaults.
      Parameters:
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configFactoryDefault

      Configures all persistent settings to defaults.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • getFaults

      public ErrorCode getFaults​(CANdleFaults toFill)
      Gets the CANdle fault status
      Parameters:
      toFill - Container for fault statuses.
      Returns:
      Error Code generated by function. OK indicates no error.
    • getStickyFaults

      Gets the CANdle sticky fault status
      Parameters:
      toFill - Container for sticky fault statuses.
      Returns:
      Error Code generated by function. OK indicates no error.
    • clearStickyFaults

      public ErrorCode clearStickyFaults​(int timeoutMs)
      Clears the sticky faults.
      Parameters:
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • clearStickyFaults

      Clears the sticky faults.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • hasResetOccurred

      public boolean hasResetOccurred()
      Returns true if the device has reset since last call.
      Returns:
      Has a Device Reset Occurred?
    • setStatusFramePeriod

      public ErrorCode setStatusFramePeriod​(CANdleStatusFrame frame, int periodMs, int timeoutMs)
      Sets the period of the given status frame.
      Parameters:
      frame - Frame whose period is to be changed.
      periodMs - Period in ms for the given frame.
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • setStatusFramePeriod

      public ErrorCode setStatusFramePeriod​(CANdleStatusFrame frame, int periodMs)
      Sets the period of the given status frame.
      Parameters:
      frame - Frame whose period is to be changed.
      periodMs - Period in ms for the given frame.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • getStatusFramePeriod

      public int getStatusFramePeriod​(CANdleStatusFrame frame, int timeoutMs)
      Gets the period of the given status frame.
      Parameters:
      frame - Frame to get the period of.
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Period of the given status frame.
    • getStatusFramePeriod

      public int getStatusFramePeriod​(CANdleStatusFrame frame)
      Gets the period of the given status frame.
      Parameters:
      frame - Frame to get the period of.
      Returns:
      Period of the given status frame.
    • setControlFramePeriod

      public ErrorCode setControlFramePeriod​(CANdleControlFrame frame, int periodMs)
      Sets the period of the given control frame.
      Parameters:
      frame - Frame whose period is to be changed.
      periodMs - Period in ms for the given frame.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configAllSettings

      public ErrorCode configAllSettings​(CANdleConfiguration allConfigs, int timeoutMs)
      Configures all persistent settings.
      Parameters:
      allConfigs - Object with all of the persistant settings
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
      Returns:
      Error Code generated by function. 0 indicates no error.
    • configAllSettings

      Configures all persistent settings.
      Parameters:
      allConfigs - Object with all of the persistant settings
      Returns:
      Error Code generated by function. 0 indicates no error.
    • getAllConfigs

      public void getAllConfigs​(CANdleConfiguration allConfigs, int timeoutMs)
      Gets all persistant settings.
      Parameters:
      allConfigs - Object with all of the persistant settings
      timeoutMs - Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.
    • getAllConfigs

      public void getAllConfigs​(CANdleConfiguration allConfigs)
      Gets all persistant settings.
      Parameters:
      allConfigs - Object with all of the persistant settings
    • getLastError

      Call GetLastError() generated by this object. Not all functions return an error code but can potentially report errors. This function can be used to retrieve those error codes.
      Returns:
      The last ErrorCode generated.