ReduxLib C++ 2024.3.2
|
#include <CanandmagSettings.h>
Public Member Functions | |
const std::vector< uint8_t > & | SettingAddresses () const override |
void | SetVelocityFilterWidth (units::millisecond_t widthMs) |
void | SetPositionFramePeriod (units::second_t period) |
void | SetVelocityFramePeriod (units::second_t period) |
void | SetStatusFramePeriod (units::second_t period) |
void | SetInvertDirection (bool invert) |
void | SetDisableZeroButton (bool disable) |
void | SetZeroOffset (units::turn_t offset) |
std::optional< units::millisecond_t > | GetVelocityFilterWidth () |
std::optional< units::second_t > | GetPositionFramePeriod () |
std::optional< units::second_t > | GetVelocityFramePeriod () |
std::optional< units::second_t > | GetStatusFramePeriod () |
std::optional< bool > | GetInvertDirection () |
std::optional< bool > | GetDisableZeroButton () |
std::optional< units::turn_t > | GetZeroOffset () |
Public Member Functions inherited from redux::canand::CanandSettings | |
CanandSettings ()=default | |
CanandSettings (CanandSettings &stg) | |
~CanandSettings ()=default | |
std::unordered_map< uint8_t, uint64_t > | FilteredMap () |
bool | AllSettingsReceived () const |
virtual const std::vector< uint8_t > & | SettingAddresses () const |
std::unordered_map< uint8_t, uint64_t > & | GetMap () |
bool | IsEmpty () const |
bool | IsEphemeral () const |
void | SetEphemeral (bool value) |
std::string | ToString () |
Additional Inherited Members | |
Protected Attributes inherited from redux::canand::CanandSettings | |
std::unordered_map< uint8_t, uint64_t > | values |
bool | ephemeral = false |
The settings class for the Canandmag.
This class holds settings values that can be used to reconfigure Canandmag via Canandmag::SetSettings Additionally, objects of this class can be filled using Canandmag.GetSettings which can be used to read the encoder's settings.
Objects returned by the blocking Canandmag::GetSettings() method will always have all setting values populated and the getters will never return std::nullopt.
However, they may return std::nullopt if the object is either manually constructed and the corresponding getter hasn't been called yet (e.g. calling GetStatusFramePeriod before SetStatusFramePeriod on an object you made) or if the object comes from Canandmag::GetSettingsAsync() and not all settings have been received (use AllSettingsReceived() to check if all are present)
cppreference on std::optional may be helpful here.
Example blocking fetch:
std::optional< bool > redux::sensors::canandmag::CanandmagSettings::GetDisableZeroButton | ( | ) |
Gets whether or not the sensor should disallow zeroing and factory resets from the onboard button (0 for allow, 1 for disallow, std::nullopt for unset).
std::optional< bool > redux::sensors::canandmag::CanandmagSettings::GetInvertDirection | ( | ) |
Gets whether or not the encoder has an inverted direction (0 for no, 1 for yes, std::nullopt for unset).
std::optional< units::second_t > redux::sensors::canandmag::CanandmagSettings::GetPositionFramePeriod | ( | ) |
Gets the position frame period in seconds [0..65.535], or std::nullopt if the value has not been set on this object. A value of 0 means position messages are disabled.
std::optional< units::second_t > redux::sensors::canandmag::CanandmagSettings::GetStatusFramePeriod | ( | ) |
Gets the status frame period in seconds [0.001..16.383], or std::nullopt if the value has not been set on this object. A value of 0 means status messages are disabled.
std::optional< units::millisecond_t > redux::sensors::canandmag::CanandmagSettings::GetVelocityFilterWidth | ( | ) |
Gets the velocity filter width in milliseconds [0.25..63.75], or std::nullopt if the value has not been set on this object.
std::optional< units::second_t > redux::sensors::canandmag::CanandmagSettings::GetVelocityFramePeriod | ( | ) |
Gets the velocity frame period in seconds [0..65.535], or std::nullopt if the value has not been set on this object. A value of 0 means velocity messages are disabled.
std::optional< units::turn_t > redux::sensors::canandmag::CanandmagSettings::GetZeroOffset | ( | ) |
Gets the zero offset of the encoder.
The zero offset is subtracted from the raw reading of the encoder's magnetic sensor to get the adjusted absolute position as returned by Canandmag.GetAbsPosition().
void redux::sensors::canandmag::CanandmagSettings::SetDisableZeroButton | ( | bool | disable | ) |
Sets whether or not the sensor should disallow zeroing and factory resets from the onboard button. By factory default, the sensor will allow the zero button to function when pressed (disable=false)
disable | whether to disable the onboard zeroing button's functionality |
void redux::sensors::canandmag::CanandmagSettings::SetInvertDirection | ( | bool | invert | ) |
Inverts the direction read from the sensor. By factory default, the sensor will read counterclockwise from its reading face as positive (invert=false).
invert | whether to invert (negate) readings from the encoder |
void redux::sensors::canandmag::CanandmagSettings::SetPositionFramePeriod | ( | units::second_t | period | ) |
Sets the position frame period in seconds. By factory default, position frames are sent every 20 milliseconds (period=0.020_s) If 0 is passed in, position frames will be disabled and the methods Canandmag::GetPosition() and Canandmag::GetAbsPosition() will not return new values.
period | the new period for position frames in seconds in range [0_s, 65.535_s]. |
void redux::sensors::canandmag::CanandmagSettings::SetStatusFramePeriod | ( | units::second_t | period | ) |
Sets the status frame period in seconds. By factory default, the encoder will broadcast 1 status message per second (period=1.000_s).
period | the new period for status frames in seconds in range [0.001_s, 16.383_s]. |
|
overridevirtual |
Gets the array of settings addresses this settings class records.
Reimplemented from redux::canand::CanandSettings.
void redux::sensors::canandmag::CanandmagSettings::SetVelocityFilterWidth | ( | units::millisecond_t | widthMs | ) |
Sets the velocity filter width in milliseconds to sample over. Velocity is computed by averaging all the points in the past widthMs milliseconds. By factory default, the velocity filter averages over the past 25 milliseconds.
widthMs | the new number of samples to average over. Minimum accepted is 0.25 milliseconds, maximum is 63.75 ms. |
void redux::sensors::canandmag::CanandmagSettings::SetVelocityFramePeriod | ( | units::second_t | period | ) |
Sets the velocity frame period in seconds. By factory default, velocity frames are sent every 20 milliseconds (period=0.020_s) If 0 is passed in, velocity frames will be disabled and Canandmag::GetVelocity() will not return new values.
period | the new period for velocity frames in seconds in range [0_s, 65.535_s]. |
void redux::sensors::canandmag::CanandmagSettings::SetZeroOffset | ( | units::turn_t | offset | ) |
Sets the zero offset of the encoder directly, rather than adjusting the zero offset relative to the currently read position.
The zero offset is subtracted from the raw reading of the encoder's magnetic sensor to get the adjusted absolute position as returned by Canandmag.GetAbsPosition().
Users are encouraged to use Canandmag.SetAbsPosition instead.
offset | the new offset in rotations [0..1) |