ReduxLib C++ 2024.1.1-beta0
Loading...
Searching...
No Matches
redux::sensors::canandcoder::CanandcoderSettings Class Reference

#include <CanandcoderSettings.h>

Inheritance diagram for redux::sensors::canandcoder::CanandcoderSettings:
redux::canand::CanandSettings

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
 

Detailed Description

The settings class for the Canandcoder.

This class holds settings values that can be used to reconfigure Canandcoder via Canandcoder::SetSettings Additionally, objects of this class can be filled using Canandcoder.GetSettings which can be used to read the encoder's settings.

// Only settings that are explicitly set here will be edited, so other settings
// such as the status frame period will remain untouched.
stg.SetPositionFramePeriod(0_ms); // disables position readings
stg.SetVelocityFramePeriod(20_ms); // sets the rate of velocity measurements to every 20 ms
stg.SetInvertDirection(true); // inverts the encoder direction
enc.SetSettings(stg);
Definition: CanandcoderSettings.h:54
void SetPositionFramePeriod(units::second_t period)
void SetVelocityFramePeriod(units::second_t period)
Definition: Canandcoder.h:91

Objects returned by the blocking Canandcoder::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 Canandcoder::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:

Canandcoder canandcoder{0};
CanandcoderSettings stg = canandcoder.GetSettings();
if (stg.AllSettingsReceived()) { // check for timeout
fmt::print("status frame period: {}\n", *stg.GetStatusFramePeriod()); // print the status frame period (usually 1000 ms)
}
bool AllSettingsReceived() const
Definition: CanandSettings.h:55
std::optional< units::second_t > GetStatusFramePeriod()

Member Function Documentation

◆ GetDisableZeroButton()

std::optional< bool > redux::sensors::canandcoder::CanandcoderSettings::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).

Returns
whether or not the encoder has its onboard zero button's functionality disabled (0 for allow, 1 for disallow, std::nullopt for unset).

◆ GetInvertDirection()

std::optional< bool > redux::sensors::canandcoder::CanandcoderSettings::GetInvertDirection ( )

Gets whether or not the encoder has an inverted direction (0 for no, 1 for yes, std::nullopt for unset).

Returns
whether or not the encoder has an inverted direction (0 for no, 1 for yes, std::nullopt for unset).

◆ GetPositionFramePeriod()

std::optional< units::second_t > redux::sensors::canandcoder::CanandcoderSettings::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.

Returns
the position frame period in seconds [0..65.535], or std::nullopt if the value has not been set on this object.

◆ GetStatusFramePeriod()

std::optional< units::second_t > redux::sensors::canandcoder::CanandcoderSettings::GetStatusFramePeriod ( )

Gets the status frame period in seconds [1..65.535], or std::nullopt if the value has not been set on this object. A value of 0 means status messages are disabled.

Returns
the status frame period in seconds [1..65.535], or std::nullopt if the value has not been set on this object.

◆ GetVelocityFilterWidth()

std::optional< units::millisecond_t > redux::sensors::canandcoder::CanandcoderSettings::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.

Returns
the velocity filter width in milliseconds [0.25..63.75], or std::nullopt if the value has not been set on this object.

◆ GetVelocityFramePeriod()

std::optional< units::second_t > redux::sensors::canandcoder::CanandcoderSettings::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.

Returns
the velocity frame period in seconds [0..65.535], or std::nullopt if the value has not been set on this object.

◆ GetZeroOffset()

std::optional< units::turn_t > redux::sensors::canandcoder::CanandcoderSettings::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 Canandcoder.GetAbsPosition().

Returns
the zero offset [0..1), or std::nullopt if the value has not been set on this object.

◆ SetDisableZeroButton()

void redux::sensors::canandcoder::CanandcoderSettings::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)

Parameters
disablewhether to disable the onboard zeroing button's functionality

◆ SetInvertDirection()

void redux::sensors::canandcoder::CanandcoderSettings::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).

Parameters
invertwhether to invert (negate) readings from the encoder

◆ SetPositionFramePeriod()

void redux::sensors::canandcoder::CanandcoderSettings::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 Canandcoder::GetPosition() and Canandcoder::GetAbsPosition() will not return new values.

Parameters
periodthe new period for position frames in seconds in range [0_s, 65.535_s].

◆ SetStatusFramePeriod()

void redux::sensors::canandcoder::CanandcoderSettings::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=0.020_s).

Parameters
periodthe new period for status frames in seconds in range [1_s, 65.535_s].

◆ SettingAddresses()

const std::vector< uint8_t > & redux::sensors::canandcoder::CanandcoderSettings::SettingAddresses ( ) const
overridevirtual

Gets the array of settings addresses this settings class records.

Returns
DetailsKey array

Reimplemented from redux::canand::CanandSettings.

◆ SetVelocityFilterWidth()

void redux::sensors::canandcoder::CanandcoderSettings::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.

Parameters
widthMsthe new number of samples to average over. Minimum accepted is 0.25 milliseconds, maximum is 63.75 ms.

◆ SetVelocityFramePeriod()

void redux::sensors::canandcoder::CanandcoderSettings::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 Canandcoder::GetVelocity() will not return new values.

Parameters
periodthe new period for velocity frames in seconds in range [0_s, 65.535_s].

◆ SetZeroOffset()

void redux::sensors::canandcoder::CanandcoderSettings::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 Canandcoder.GetAbsPosition().

Users are encouraged to use Canandcoder.SetAbsPosition instead.

Parameters
offsetthe new offset in rotations [0..1)

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