ReduxLib C++ 2024.3.2
Loading...
Searching...
No Matches
CanandgyroSettings.h
1// Copyright (c) Redux Robotics and other contributors.
2// This is open source and can be modified and shared under the 3-clause BSD license.
3
4#pragma once
5#include <cinttypes>
6#include <unordered_map>
7#include <optional>
8#include <units/time.h>
9#include <units/angle.h>
10#include "redux/canand/CanandSettings.h"
11
13
14/**
15 * The settings class for the Canandgyro.
16 *
17 * <p>
18 * This class holds settings values that can be used to reconfigure Canandgyro via Canandgyro::SetSettings
19 * Additionally, objects of this class can be filled using Canandgyro.GetSettings which can be used to
20 * read the encoder's settings.
21 * </p>
22 *
23 * ```cpp
24 * Canandgyro enc = Canandgyro{0};
25 *
26 * // Only settings that are explicitly set here will be edited, so other settings
27 * // such as the status frame period will remain untouched.
28 * CanandgyroSettings stg;
29 * stg.SetAngularVelocityFramePeriod(0_ms); // disables angular velocity readings
30 * stg.SetYawFramePeriod(5_ms); // sets the rate of yaw measurements to every 5 ms
31 *
32 * enc.SetSettings(stg);
33 *
34 * ```
35 * Objects returned by the blocking Canandgyro::GetSettings() method will generally have all setting values populated and the getters will not return std::nullopt
36 * assuming no timeout occured.
37 *
38 * However, they may return std::nullopt if the object is either manually constructed and the corresponding getter hasn't been called yet
39 * (e.g. calling GetStatusFramePeriod before SetStatusFramePeriod on an object you made)
40 * or if the object comes from Canandgyro::GetSettingsAsync() and not all settings have been received (use AllSettingsReceived() to check if all are present)
41 *
42 * <a href="https://en.cppreference.com/w/cpp/utility/optional">cppreference on std::optional</a> may be helpful here.
43 *
44 * Example blocking fetch:
45 * ```cpp
46 * Canandgyro canandgyro{0};
47 * CanandgyroSettings stg = canandgyro.GetSettings();
48 * if (stg.AllSettingsReceived()) { // check for timeout
49 * fmt::print("status frame period: {}\n", *stg.GetStatusFramePeriod()); // print the status frame period (usually 1000 ms)
50 * }
51 * ```
52 *
53 */
55 public:
56 CanandgyroSettings() = default;
57
58 const std::vector<uint8_t>& SettingAddresses() const override;
59
60 /**
61 * Sets the dedicated yaw frame period in seconds.
62 *
63 * By factory default, yaw frames are sent every 10 milliseconds (period = 0.010_s).
64 * If 0 is passed in, yaw frames will be disabled and Canandgyro#getYaw} will not
65 * return new values (unless configured to derive yaw from the angular position frame)
66 *
67 * @param period the new frame period in seconds [0_s, 65.535_s] inclusive
68 */
69 void SetYawFramePeriod(units::second_t period);
70
71 /**
72 * Sets the angular position frame period in seconds.
73 *
74 * By factory default, angular position frames are sent every 20 milliseconds (period = 0.020_s).
75 * If 0 is passed in, angular position frames will be disabled and methods returning angular
76 * position data will not return new values.
77 *
78 * <p>The one exception is Canandgyro.GetYaw which by default uses the yaw frame instead.</p>
79 *
80 * @param period the new frame period in seconds [0_s, 65.535_s] inclusive
81 */
82 void SetAngularPositionFramePeriod(units::second_t period);
83
84 /**
85 * Sets the angular velocity frame period in seconds.
86 *
87 * By factory default, angular velocity frames are sent every 100 milliseconds (period = 0.100_s).
88 * If 0 is passed in, angular velocity frames will be disabled and methods returning angular
89 * velocity data will not return new values.
90 *
91 * @param period the new frame period in seconds [0_s, 65.535_s] inclusive
92 */
93 void SetAngularVelocityFramePeriod(units::second_t period);
94
95 /**
96 * Sets the angular velocity frame period in seconds.
97 *
98 * By factory default, acceleration frames are sent every 100 milliseconds (period = 0.100_s).
99 * If 0 is passed in, acceleration frames will be disabled and methods returning acceleration
100 * data will not return new values.
101 *
102 * @param period the new frame period in seconds [0_s, 65.535_s] inclusive
103 */
104 void SetAccelerationFramePeriod(units::second_t period);
105
106 /**
107 * Sets the status frame period in seconds.
108 *
109 * By factory default, the device will broadcast 10 status messages every second (period=0.1_s).
110 *
111 * @param period the new period for status frames in seconds in range [0.001_s, 16.383_s].
112 */
113 void SetStatusFramePeriod(units::second_t period);
114
115 /**
116 * Gets the dedicated yaw frame period in seconds [0..65.535], or std::nullopt if the value has not
117 * been set on this object.
118 *
119 * A value of 0 means yaw frames are disabled.
120 * @return the frame period in seconds [0..65.535], or std::nullopt if the value has not been set on
121 * this object.
122 */
123 std::optional<units::second_t> GetYawFramePeriod();
124
125 /**
126 * Gets the angular position frame period in seconds [0..65.535], or std::nullopt if the value has
127 * not been set on this object.
128 *
129 * A value of 0 means angular position frames are disabled.
130 * @return the frame period in seconds [0..65.535], or std::nullopt if the value has not been set on
131 * this object.
132 */
133 std::optional<units::second_t> GetAngularPositionFramePeriod();
134
135 /**
136 * Gets the angular velocity frame period in seconds [0..65.535], or std::nullopt if the value has
137 * not been set on this object.
138 *
139 * A value of 0 means angular velocity frames are disabled.
140 * @return the frame period in seconds [0..65.535], or std::nullopt if the value has not been set on
141 * this object.
142 */
143 std::optional<units::second_t> GetAngularVelocityFramePeriod();
144
145 /**
146 * Gets the acceleration frame period in seconds [0..65.535], or std::nullopt if the value has not
147 * been set on this object.
148 *
149 * A value of 0 means acceleration frames are disabled.
150 * @return the frame period in seconds [0..65.535], or std::nullopt if the value has not been set on
151 * this object.
152 */
153 std::optional<units::second_t> GetAccelerationFramePeriod();
154
155 /**
156 * Gets the status frame period in seconds [0.001..16.383], or std::nullopt if the value has not beeno
157 * set on this object.
158 * @return the status frame period in seconds [0.001..16.383], or std::nullopt if the value has not been
159 * set on this object.
160 */
161 std::optional<units::second_t> GetStatusFramePeriod();
162
163};
164}
Definition: CanandSettings.h:20
Definition: CanandgyroSettings.h:54
void SetYawFramePeriod(units::second_t period)
const std::vector< uint8_t > & SettingAddresses() const override
std::optional< units::second_t > GetAccelerationFramePeriod()
void SetAngularPositionFramePeriod(units::second_t period)
std::optional< units::second_t > GetStatusFramePeriod()
std::optional< units::second_t > GetAngularPositionFramePeriod()
void SetAngularVelocityFramePeriod(units::second_t period)
void SetAccelerationFramePeriod(units::second_t period)
void SetStatusFramePeriod(units::second_t period)
std::optional< units::second_t > GetAngularVelocityFramePeriod()
std::optional< units::second_t > GetYawFramePeriod()
Definition: Canandgyro.h:32