ReduxLib C++ 2023.1.0
Loading...
Searching...
No Matches
redux::sensors::canandcoder::CANandcoderSettings Class Reference

#include <CANandcoder.h>

Public Member Functions

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)
 
bool AllSettingsReceived ()
 
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 ()
 

Friends

class CANandcoder
 

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.

CANandcoder enc = CANandcoder{0};

// Only settings that are explicitly set here will be edited, so other settings 
// such as the status frame period will remain untouched.
CANandcoderSettings stg;
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);

Note that all GetWhateverSetting(); functions return a std::optional, as CANandcoderSettings objects may not always have a value set for a setting. This is particularly true of instances returned by CANandcoder::GetSettingsAsync(), and you will need to use CANandcoderSettings::AllSettingsReceived() to check if all are present.

However, objects returned by the blocking CANandcoder::GetSettings() method will always have all setting values populated.

Example blocking fetch:

CANandcoder canandcoder{0};
std::optional<CANandcoderSettings> stg = canandcoder.GetSettings(stg);
if (stg.has_value()) {
  fmt.print("status frame period: {}\n", *(*stg).GetStatusFramePeriod()); // print the status frame period (usually 1000 ms)
}

Member Function Documentation

◆ AllSettingsReceived()

bool redux::sensors::canandcoder::CANandcoderSettings::AllSettingsReceived ( )

Returns whether or not all settings fields have been written into the object – if this returned false, we have not gotten all the settings from the encoder if this is a CANandcoderSettings object returned from CANandcoder::getSettings()

Returns
whether the settings object has been filled

◆ 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..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 [1..16.383], 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.

◆ 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, 16.383_s].

◆ 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].

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