ReduxLib C++ 2024.1.1-beta0
|
#include <Canandcolor.h>
Protected Attributes | |
redux::frames::Frame< double > | proximity {0.0, 0_ms} |
redux::frames::Frame< CanandcolorColorData > | color {CanandcolorColorData{0.0, 0.0, 0.0, 0.0}, 0_ms} |
redux::frames::Frame< digout::DigoutSlotState > | digout {digout::DigoutSlotState{0}, 0_ms} |
redux::frames::Frame< CanandcolorStatus > | status {CanandcolorStatus{0, 0, false, 0_degC}, 0_ms} |
redux::canand::CanandSettingsManager< CanandcolorSettings > | stg {*this} |
Class for the CAN interface of the Canandcolor.
Operations that receive data from the device (proximity, color, faults, temperature) generally do not block. The object receives data asynchronously from the CAN packet receive thread and reads thus return the last data received.
Operations that set settings or change offsets will generally wait for up to 50ms by default as they will usually wait for a confirmation packet to be received in response – unless the blocking timeout is set to zero, in which case the operations will not block.
Example code:
redux::sensors::canandcolor::Canandcolor::Canandcolor | ( | int | canID | ) |
Instantiates a new Canandcolor object. This object will be constant with respect to whatever CAN id assigned to it, so if a device changes id it may change which device this object reads from.
canID | the device id to use [0..63] |
void redux::sensors::canandcolor::Canandcolor::ClearAllDigoutSlots | ( | CanandcolorDigout | digout | ) |
Clears all configured "slots" on the specified digital output.
digout | the digital output to clear slots on |
void redux::sensors::canandcolor::Canandcolor::ClearStickyFaults | ( | ) |
Clears sticky faults.
It is recommended to clear this during initialization, so one can check if the device loses power during operation later.
This call does not block, so it may take up to the next status frame (default every 1000 ms) for the sticky faults to be updated. To check for validity, use CanandcolorFaults::FaultsValid() for faults returned by GetStickyFaults()
CanandcolorFaults redux::sensors::canandcolor::Canandcolor::GetActiveFaults | ( | ) |
Returns an object representing currently active faults. Active faults are only active for as long as the error state exists.
|
overridevirtual |
Returns the reference to the CanandAddress representing the combination of CAN bus and CAN device ID that this CanandDevice refers to.
Implementing device subclasses should likely construct a new CanandAddress in their constructor and return it here.
Implements redux::canand::CanandDevice.
double redux::sensors::canandcolor::Canandcolor::GetBlue | ( | ) |
Blue intensity, normalized [0..1) where 0 is none and 1 is as bright as possible.
CanandcolorColorData redux::sensors::canandcolor::Canandcolor::GetColor | ( | ) |
Returns a CanandcolorColorData object which can also convert to HSV.
|
inline |
Returns the color reading frame, which includes CAN timestamp data.
|
inlineoverridevirtual |
Returns a canonical class-wide device name.
Reimplemented from redux::canand::CanandDevice.
|
inline |
Returns the digital output state frame, which includes CAN timestamp data.
std::optional< digout::DigoutSlot > redux::sensors::canandcolor::Canandcolor::GetDigoutSlot | ( | CanandcolorDigout | digout, |
uint8_t | slotIndex, | ||
units::second_t | timeout = 50_ms |
||
) |
Fetches a digout slot's configuration.
These condition slots are used to determine the value of the digital outputs. For more information on how these slots work, see https://docs.reduxrobotics.com/canandcolor/programming/digital-ports.html
digout | digital output associated with the slot to fetch from |
slotIndex | The index of the slot to fetch from (0-15) |
timeout | The timeout to wait for the slot to be retrieved (default 50_ms, set to 0_s to not block) |
digout::DigoutSlotState redux::sensors::canandcolor::Canandcolor::GetDigoutState | ( | ) |
Returns a DigoutSlotState object representing the current state of the digital outputs.
double redux::sensors::canandcolor::Canandcolor::GetGreen | ( | ) |
Green intensity, normalized [0..1) where 0 is none and 1 is as bright as possible.
|
inlineoverridevirtual |
Returns the minimum firmware version this vendordep requires.
Reimplemented from redux::canand::CanandDevice.
double redux::sensors::canandcolor::Canandcolor::GetProximity | ( | ) |
Gets the currently sensed proximity normalized between [0..1]. Proximity decreases as objects get further away from the sensor face and increases as they approach the sensor. Proximities that are too close will saturate at 1.0.
Note that proximity is not given a unit as different materials and sensor configurations can greatly vary how proximity translates to actual distance. It is generally presumed that users will have to finetune specific thresholds for applications anyway and units may not be meaningful or accurate.
|
inline |
Returns the proximity reading frame.
double redux::sensors::canandcolor::Canandcolor::GetRed | ( | ) |
Red intensity, normalized [0..1) where 0 is none and 1 is as bright as possible.
|
inline |
Fetches the Canandcolor's current configuration in a blocking manner. This function will block for at up to 0.5 seconds waiting for the device to reply, so it is best to put this in an init function, rather than the main loop.
timeout | maximum number of seconds to wait for settings before giving up |
missingTimeout | maximum number of seconds to wait for each settings retry before giving up |
attempts | number of attempts to try and fetch values missing from the first pass |
|
inline |
Non-blockingly returns a CanandcolorSettings object of the most recent known settings values received from the device.
Most users will probably want to use Canandcolor::GetSettings instead.
One can call this after a Canandcolor::StartFetchSettings() call, and use CanandcolorSettings::AllSettingsReceived() to check if/when all values have been seen. As an example:
If this is called after Canandcolor::SetSettings(CanandcolorSettings), this method will return a settings object where only the fields where the device has echoed the new values back will be populated. To illustrate this, consider the following:
|
inline |
Returns the current status frame, which includes CAN timestamp data. FrameData objects are immutable.
CanandcolorFaults redux::sensors::canandcolor::Canandcolor::GetStickyFaults | ( | ) |
Returns sticky faults. Sticky faults are the active faults, except once set they do not become unset until ClearStickyFaults() is called.
units::celsius_t redux::sensors::canandcolor::Canandcolor::GetTemperature | ( | ) |
Get onboard device temperature readings in degrees Celsius.
double redux::sensors::canandcolor::Canandcolor::GetWhite | ( | ) |
White intensity, normalized [0..1) This can be used as a proxy for proximity at ranges too close for the normmal proximity sensor to give useful values.
|
overridevirtual |
A callback called when a Redux CAN message is received and should be parsed. Subclasses of CanandDevice should override this to update their internal state accordingly.
HandleMessage will be called on all Redux CAN packets received by the vendordep that match the CanandAddress returned by CanandDevice::GetAddress().
msg | a reference to a CanandMessage representing the received message. The message may not have lifetime outside the function call. |
Implements redux::canand::CanandDevice.
|
inline |
Resets the device to factory defaults, and then wait for all settings to be broadcasted back.
timeout | how long to wait for the new settings to be confirmed by the device in seconds (suggested at least 0.35 seconds) |
bool redux::sensors::canandcolor::Canandcolor::SetDigoutSlot | ( | CanandcolorDigout | digout, |
uint8_t | slotIndex, | ||
const digout::DigoutSlot & | slotConfig, | ||
units::second_t | timeout = 50_ms |
||
) |
Sets an indexed slot on a Canandcolor digital output.
These condition slots are used to determine the value of the digital outputs. For more information on how these slots work, see https://docs.reduxrobotics.com/canandcolor/programming/digital-ports.html
digout | The digital output associated with the slot to write |
slotIndex | The index of the slot to write to (0-15) |
slotConfig | The actual slot data (see DigoutSlot) |
timeout | The timeout to wait for a confirmation message (default 50_ms, set to 0_s to not block) |
void redux::sensors::canandcolor::Canandcolor::SetLampLED | ( | bool | lamp | ) |
Sets whether or not the onboard lamp LED is to be powered.
This value does not persist on device reboot! Use CanandcolorSettings.SetLampLED and Canandcolor.SetSettings to set this persistently.
The LED can also be physically turned off regardless of setting with the onboard switch.
The LED is useful for measuring the color of objects that do not themselves emit light (e.g. most game pieces) or for using the white channel to estimate very close proximity.
By factory default the lamp is enabled.
lamp | whether to enable or disable the lamp LED |
void redux::sensors::canandcolor::Canandcolor::SetLampLEDBrightness | ( | double | brightness | ) |
Sets the brightness of the onboard lamp LED.
This value does not persist on device reboot! Use CanandcolorSettings.SetLampLEDBrightness and Canandcolor.SetSettings to set this persistently.
By factory default this setting is set to max brightness (1.0)
brightness | scaled brightness from 0.0 (off) to 1.0 (max brightness) |
void redux::sensors::canandcolor::Canandcolor::SetPartyMode | ( | uint8_t | level | ) |
Controls "party mode" – an device identification tool that blinks the onboard LED various colors at a user-specified strobe period. The strobe period of the LED will be (50 milliseconds * level). Setting this to 0 disables party mode.
This function does not block.
level | the party level value to set. |
|
inline |
Applies the settings from a CanandcolorSettings object to the device. For more information, see the CanandcolorSettings class documentation.
Example:
settings | the CanandcolorSettings to update the device with |
timeout | maximum time in seconds to wait for each setting to be confirmed (default 50 ms). Set to 0 to not check (and not block). |
attempts | the maxinum number of attempts to write each individual settings |
|
inline |
Tells the Canandcolor to begin transmitting its settings; once they are all transmitted (after ~200-300ms), the values can be retrieved from Canandcolor::GetSettingsAsync()
|
protected |
internal Frame variable holding current color state
|
protected |
internal Frame variable holding current digital output state
|
protected |
internal Frame variable holding current proximity state
|
protected |
internal Frame variable holding current status value state
|
protected |
internal settings manager