Package com.ctre.phoenix.led
Class CANdle
java.lang.Object
com.ctre.phoenix.led.CANdle
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The various LED types that the CANdle can supportstatic enum
The various methods of managing the VBat output behavior -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAnimates 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 effectClears the sticky faults.clearStickyFaults
(int timeoutMs) Clears the sticky faults.configAllSettings
(CANdleConfiguration allConfigs) Configures all persistent settings.configAllSettings
(CANdleConfiguration allConfigs, int timeoutMs) Configures all persistent settings.configBrightnessScalar
(double brightness) Configures the brightness scalar to be applied to every LED output.configBrightnessScalar
(double brightness, int timeoutMs) Configures the brightness scalar to be applied to every LED output.Configures all persistent settings to defaults.configFactoryDefault
(int timeoutMs) Configures all persistent settings to defaults.int
configGetCustomParam
(int paramIndex) Gets the value of a custom parameter.int
configGetCustomParam
(int paramIndex, int timeoutMs) Gets the value of a custom parameter.double
configGetParameter
(ParamEnum param, int ordinal) Gets a parameter.double
configGetParameter
(ParamEnum param, int ordinal, int timeoutMs) Gets a parameter.Configures the type of LED the CANdle controlsconfigLEDType
(CANdle.LEDStripType type, int timeoutMs) Configures the type of LED the CANdle controlsconfigLOSBehavior
(boolean disableWhenLOS) Configures what the CANdle should do if it loses communications to the ControllerconfigLOSBehavior
(boolean disableWhenLOS, int timeoutMs) Configures what the CANdle should do if it loses communications to the ControllerconfigSetCustomParam
(int paramIndex, int value) Sets the value of a custom parameter.configSetCustomParam
(int paramIndex, int value, int timeoutMs) Sets the value of a custom parameter.configSetParameter
(ParamEnum param, double value, int subValue, int ordinal) Sets a parameter.configSetParameter
(ParamEnum param, double value, int subValue, int ordinal, int timeoutMs) Sets a parameter.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.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.Configures how the VBat Output will behaveconfigVBatOutput
(CANdle.VBatOutputMode mode, int timeoutMs) Configures how the VBat Output will behavedouble
Gets the Voltage of the 5V line as measured by CANdlevoid
getAllConfigs
(CANdleConfiguration allConfigs) Gets all persistant settings.void
getAllConfigs
(CANdleConfiguration allConfigs, int timeoutMs) Gets all persistant settings.double
Gets the Voltage of VBat as measured by CANdledouble
Gets the low-side current as measured by CANdlegetFaults
(CANdleFaults toFill) Gets the CANdle fault statusCall GetLastError() generated by this object.int
Gets the period of the given status frame.int
getStatusFramePeriod
(CANdleStatusFrame frame, int timeoutMs) Gets the period of the given status frame.getStickyFaults
(CANdleStickyFaults toFill) Gets the CANdle sticky fault statusdouble
Gets the temperature of the CANdle in Celciusdouble
Gets the applied vbat modulation in percent.boolean
Returns true if the device has reset since last call.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 ModulatedsetControlFramePeriod
(CANdleControlFrame frame, int periodMs) Sets the period of the given control frame.setLEDs
(int r, int g, int b) Sets a block of LEDs to the specified color.setLEDs
(int r, int g, int b, int w, int startIdx, int count) Sets a block of LEDs to the specified colorsetStatusFramePeriod
(CANdleStatusFrame frame, int periodMs) Sets the period of the given status frame.setStatusFramePeriod
(CANdleStatusFrame frame, int periodMs, int timeoutMs) Sets the period of the given status frame.
-
Constructor Details
-
CANdle
Constructor for a CANdle Device- Parameters:
deviceId
- The Device ID of the CANdlecanbus
- Name of the CANbus; can be a SocketCAN interface (on Linux), or a CANivore device name or serial number
-
CANdle
Constructor for a CANdle Device- Parameters:
deviceId
- The Device ID of the CANdle
-
-
Method Details
-
destroyObject
-
getBusVoltage
Gets the Voltage of VBat as measured by CANdle- Returns:
- Voltage of VBat
-
get5VRailVoltage
Gets the Voltage of the 5V line as measured by CANdle- Returns:
- Voltage of the 5V line
-
getCurrent
Gets the low-side current as measured by CANdle- Returns:
- Current in Amps
-
getTemperature
Gets the temperature of the CANdle in Celcius- Returns:
- Temperature in Celcius
-
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
-
animate
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- Returns:
- ErrorCode generated by function. OK indicates no error.
-
setLEDs
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 LEDscount
- The number of LEDs to apply this to- Returns:
- ErrorCode generated by function. OK indicates no error.
-
setLEDs
Sets a block of LEDs to the specified color. This will apply to the first 255 LEDs.- 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
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
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
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
Configures the type of LED the CANdle controls- Parameters:
type
- The type of the LEDs the CANdle controlstimeoutMs
- 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
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
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
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 runningtimeoutMs
- 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
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
Configures how the VBat Output will behave- Parameters:
mode
- VBat Output BehaviortimeoutMs
- 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.
-
configGetParameter
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
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
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
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
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
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
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
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
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
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
Returns true if the device has reset since last call.- Returns:
- Has a Device Reset Occurred?
-
setStatusFramePeriod
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
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
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
Gets the period of the given status frame.- Parameters:
frame
- Frame to get the period of.- Returns:
- Period of the given status frame.
-
setControlFramePeriod
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
Configures all persistent settings.- Parameters:
allConfigs
- Object with all of the persistant settingstimeoutMs
- 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
Gets all persistant settings.- Parameters:
allConfigs
- Object with all of the persistant settingstimeoutMs
- 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
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.
-