ReduxLib C++ 2024.3.2
Loading...
Searching...
No Matches
redux::sensors::canandmag::CanandmagSettings Class Reference

#include <CanandmagSettings.h>

Inheritance diagram for redux::sensors::canandmag::CanandmagSettings:
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 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.

// 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: CanandmagSettings.h:54
void SetVelocityFramePeriod(units::second_t period)
void SetPositionFramePeriod(units::second_t period)
Definition: Canandmag.h:91

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:

Canandmag canandmag{0};
CanandmagSettings stg = canandmag.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::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).

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::canandmag::CanandmagSettings::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::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.

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::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.

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

◆ GetVelocityFilterWidth()

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.

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::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.

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::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().

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

◆ SetDisableZeroButton()

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)

Parameters
disablewhether to disable the onboard zeroing button's functionality

◆ SetInvertDirection()

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).

Parameters
invertwhether to invert (negate) readings from the encoder

◆ SetPositionFramePeriod()

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.

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

◆ SetStatusFramePeriod()

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).

Parameters
periodthe new period for status frames in seconds in range [0.001_s, 16.383_s].

◆ SettingAddresses()

const std::vector< uint8_t > & redux::sensors::canandmag::CanandmagSettings::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::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.

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

◆ SetVelocityFramePeriod()

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.

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

◆ SetZeroOffset()

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.

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

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