Valkyrie 2026
Loading...
Searching...
No Matches
valor::sensors::CANdleSensor Class Reference

Sensor for controlling the CANdle and associated LEDs. More...

#include <valkyrie/sensors/CANdleSensor.h>

Inheritance diagram for valor::sensors::CANdleSensor:
valor::sensors::BaseSensor< int > valor::sensors::BaseSensorCore valor::Loggable

Public Types

enum class  Priority { LOW , MEDIUM , HIGH }

Public Member Functions

 CANdleSensor (int ledCount, int numSegments, int canID, std::string canbus="baseCAN")
 Construct a new CANdleSensor object.
 CANdleSensor (std::vector< int > segmentSizes, int canID, std::string canbus="baseCAN")
 CANdleSensor (int ledCount, int numSegments)
 CANdleSensor (std::vector< int > segmentSizes)
void SetBrightness (double brightness, bool saveImmediately=true)
void SetStripType (ctre::phoenix6::signals::StripTypeValue stripType, bool saveImmediately=true)
void ApplyConfig ()
void SetLED (int led, frc::Color8Bit color)
 Set the color of a specific LED.
void SetColor (int segment, frc::Color8Bit color, Priority priority=Priority::LOW)
 Set the color of a specific segment.
void SetColor (frc::Color8Bit color, Priority priority=Priority::LOW)
 Set the color for all segments.
template<typename T>
void SetAnimation (int segment, frc::Color8Bit color, Priority priority=Priority::LOW)
 Set an animation for a specific segment.
template<typename T>
void SetAnimation (frc::Color8Bit color, Priority priority=Priority::LOW)
 Set an animation for all segments.
void ClearAnimation (int segment)
 Clears any active animation for a specific segment.
void Reset () override
 Resets the CANdle device.
Public Member Functions inherited from valor::sensors::BaseSensor< int >
void SetGetter (std::function< int()> _lambda)
 Set the lambda function to fetch sensor data.
void ApplyPostProcessing (std::function< int(int)> func)
 Set a post-processing function for sensor data.
int Get () const
 Get the current sensor state.
void Refresh () override
 Refresh the sensor state.
Public Member Functions inherited from valor::Loggable
 Loggable (std::string_view name)
 Construct a Loggable that registers a top-level table name.
 Loggable (std::shared_ptr< nt::NetworkTable > table)
 Construct a Loggable that uses an existing NetworkTable.
 Loggable ()
 Default construct an uninitialized Loggable.
void LogChild (std::string_view name, Loggable *child)
 Register a child Loggable under a named subtree.
void LogChild (std::string_view name, wpi::Sendable *child)
 Register a child Sendable under a named subtree.
void SetPeriodicLevel (LogLevel level)
 Set the logging level for LoggablePeriodic.
template<typename T>
WriteLog (std::string_view field, const T &data, LogLevel level=LogLevel::Normal)
 Publish a value to NetworkTables under the given field.
template<typename T>
ReadLog (std::string_view field, const T &defaultValue={})
 Read a value from NetworkTables for the given field.
template<>
decltype(Loggable::subscribers) ::iterator addSubscriber (std::string_view field, const std::vector< bool > &defaultValue)
template<>
void WriteLogImpl (nt::Publisher *pub, const std::vector< bool > &data)
template<>
std::vector< bool > ReadLogImpl (nt::Subscriber *sub)

Static Public Member Functions

static frc::Color8Bit CANcoderMagnetHealthGetter (ctre::phoenix6::hardware::CANcoder *cancoder)
 Get the health status of a CANcoder magnet.
static frc::Color8Bit CANrangeHealthGetter (ctre::phoenix6::hardware::core::CoreCANrange &canrange)
Static Public Member Functions inherited from valor::Loggable
static units::millisecond_t GetLoggingTime ()
static constexpr LoggableGetRoot ()

Static Public Attributes

static constexpr frc::Color8Bit VALOR_GOLD {0xEE, 0xA8, 0x00}
static constexpr frc::Color8Bit VALOR_PURPLE {0xFF, 0x00, 0xFF}
static constexpr frc::Color8Bit RED {0xFF, 0x00, 0x00}
static constexpr frc::Color8Bit ORANGE {0xFF, 0x30, 0x00}
static constexpr frc::Color8Bit GREEN {0x00, 0xFF, 0x00}
static constexpr frc::Color8Bit BLUE {0x00, 0x00, 0xFF}
static constexpr frc::Color8Bit LIGHT_BLUE {0xFF, 0x00, 0xF9}
static constexpr frc::Color8Bit WHITE {0xFF, 0xFF, 0xFF}
static constexpr frc::Color8Bit OFF {0x00, 0x00, 0x00}
Static Public Attributes inherited from valor::sensors::BaseSensorCore
static constexpr units::millisecond_t LOOP_PERIOD = frc::TimedRobot::kDefaultPeriod / 2

Additional Inherited Members

Protected Member Functions inherited from valor::Loggable
virtual void OnLoggingStart ()
 Hook invoked when logging is started for this object.
virtual void LoggablePeriodic ()
 Periodic callback for logging updates.
Protected Attributes inherited from valor::sensors::BaseSensor< int >
std::function< int()> sensorLambda
 Lambda function to fetch sensor data.
std::function< int(int)> postProcessor
 Lambda function to post-process sensor data.
int prevState
 Previous and current sensor states.
int currState

Detailed Description

Sensor for controlling the CANdle and associated LEDs.

This class manages a CANdle device and any connected LEDs. It supports setting static colors, animations, and segment-specific configurations.

Constructor & Destructor Documentation

◆ CANdleSensor()

valor::sensors::CANdleSensor::CANdleSensor ( int ledCount,
int numSegments,
int canID,
std::string canbus = "baseCAN" )

Construct a new CANdleSensor object.

Parameters
robotReference to the main robot instance.
ledCountNumber of external LEDs connected to the CANdle.
numSegmentsNumber of LED segments.
canIDCAN ID assigned to the CANdle.
canbusCAN bus the CANdle is attached to (default: "baseCAN").

Member Function Documentation

◆ CANcoderMagnetHealthGetter()

frc::Color8Bit valor::sensors::CANdleSensor::CANcoderMagnetHealthGetter ( ctre::phoenix6::hardware::CANcoder * cancoder)
static

Get the health status of a CANcoder magnet.

Parameters
cancoderPointer to the CANcoder device.
Returns
frc::Color8Bit Color representing the health status.

◆ ClearAnimation()

void valor::sensors::CANdleSensor::ClearAnimation ( int segment)

Clears any active animation for a specific segment.

Also responsible for clearing the appropriate memory associated with the animation.

Parameters
segmentThe segment that will be cleared.

◆ Reset()

void valor::sensors::CANdleSensor::Reset ( )
overridevirtual

Resets the CANdle device.

Reimplemented from valor::sensors::BaseSensor< int >.

◆ SetAnimation() [1/2]

template<typename T>
void valor::sensors::CANdleSensor::SetAnimation ( frc::Color8Bit color,
Priority priority = Priority::LOW )
inline

Set an animation for all segments.

Template Parameters
TAnimation type.
Parameters
colorColor for the animation.
priorityPriority for the animation.

◆ SetAnimation() [2/2]

template<typename T>
void valor::sensors::CANdleSensor::SetAnimation ( int segment,
frc::Color8Bit color,
Priority priority = Priority::LOW )
inline

Set an animation for a specific segment.

Template Parameters
TAnimation type.
Parameters
segmentSegment index to modify.
colorColor for the animation.
priorityPriority for the animation.

◆ SetColor() [1/2]

void valor::sensors::CANdleSensor::SetColor ( frc::Color8Bit color,
Priority priority = Priority::LOW )

Set the color for all segments.

Parameters
colorRGB hex code to set.
priorityPriority level for the color setting.

◆ SetColor() [2/2]

void valor::sensors::CANdleSensor::SetColor ( int segment,
frc::Color8Bit color,
Priority priority = Priority::LOW )

Set the color of a specific segment.

Parameters
segmentSegment index to modify.
colorColor to set.
priorityPriority for the color setting.

◆ SetLED()

void valor::sensors::CANdleSensor::SetLED ( int led,
frc::Color8Bit color )

Set the color of a specific LED.

Parameters
ledIndex of the LED to set.
colorColor to set.

The documentation for this class was generated from the following file: