CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
DifferentialSensorsConfigs.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
11#include <units/dimensionless.h>
12
13namespace ctre {
14namespace phoenix6 {
15
16
17namespace configs {
18
19/**
20 * \brief Configs related to sensors used for differential control of
21 * a mechanism.
22 *
23 * \details Includes the differential sensor sources and IDs.
24 */
26public:
27 constexpr DifferentialSensorsConfigs() = default;
28
29 /**
30 * \brief Choose what sensor source is used for differential control
31 * of a mechanism. The default is Disabled. All other options
32 * require setting the DifferentialTalonFXSensorID, as the average of
33 * this Talon FX's sensor and the remote TalonFX's sensor is used for
34 * the differential controller's primary targets.
35 *
36 * Choose RemoteTalonFX_HalfDiff to use another TalonFX on the same
37 * CAN bus. Talon FX will update its differential position and
38 * velocity whenever the remote TalonFX publishes its information on
39 * CAN bus. The differential controller will use half of the
40 * difference between this TalonFX's sensor and the remote Talon FX's
41 * sensor for the differential component of the output.
42 *
43 * Choose RemotePigeon2Yaw, RemotePigeon2Pitch, and RemotePigeon2Roll
44 * to use another Pigeon2 on the same CAN bus (this also requires
45 * setting DifferentialRemoteSensorID). Talon FX will update its
46 * differential position to match the selected value whenever Pigeon2
47 * publishes its information on CAN bus. Note that the Talon FX
48 * differential position will be in rotations and not degrees.
49 *
50 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus
51 * (this also requires setting DifferentialRemoteSensorID). Talon FX
52 * will update its differential position and velocity to match the
53 * CANcoder whenever CANcoder publishes its information on CAN bus.
54 *
55 */
57 /**
58 * \brief Device ID of which remote Talon FX to use. This is used
59 * whenever the Differential Sensor Source is not disabled.
60 *
61 * The differential Talon FX must enable its Position and Velocity
62 * status signals. The update rate of the status signals determines
63 * the update rate of differential control.
64 *
65 * - Minimum Value: 0
66 * - Maximum Value: 62
67 * - Default Value: 0
68 * - Units:
69 */
71 /**
72 * \brief Device ID of which remote sensor to use on the differential
73 * axis. This is used when the Differential Sensor Source is not
74 * Disabled or RemoteTalonFX_HalfDiff.
75 *
76 * - Minimum Value: 0
77 * - Maximum Value: 62
78 * - Default Value: 0
79 * - Units:
80 */
82 /**
83 * \brief The ratio of sensor rotations to the differential
84 * mechanism's difference output, where a ratio greater than 1 is a
85 * reduction.
86 *
87 * When using RemoteTalonFX_HalfDiff, the sensor is considered half of
88 * the difference between the two devices' mechanism
89 * positions/velocities. As a result, this should be set to the gear
90 * ratio on the difference axis when using RemoteTalonFX_HalfDiff, or
91 * any gear ratio between the sensor and the mechanism differential
92 * when using another sensor source.
93 *
94 * We recommend against using this config to perform onboard unit
95 * conversions. Instead, unit conversions should be performed in
96 * robot code using the units library.
97 *
98 * If this is set to zero, the device will reset back to one.
99 *
100 * - Minimum Value: -1000
101 * - Maximum Value: 1000
102 * - Default Value: 1.0
103 * - Units: scalar
104 */
105 units::dimensionless::scalar_t SensorToDifferentialRatio = 1.0;
106
107 /**
108 * \brief Modifies this configuration's DifferentialSensorSource parameter and returns itself for
109 * method-chaining and easier to use config API.
110 *
111 * Choose what sensor source is used for differential control of a
112 * mechanism. The default is Disabled. All other options require
113 * setting the DifferentialTalonFXSensorID, as the average of this
114 * Talon FX's sensor and the remote TalonFX's sensor is used for the
115 * differential controller's primary targets.
116 *
117 * Choose RemoteTalonFX_HalfDiff to use another TalonFX on the same
118 * CAN bus. Talon FX will update its differential position and
119 * velocity whenever the remote TalonFX publishes its information on
120 * CAN bus. The differential controller will use half of the
121 * difference between this TalonFX's sensor and the remote Talon FX's
122 * sensor for the differential component of the output.
123 *
124 * Choose RemotePigeon2Yaw, RemotePigeon2Pitch, and RemotePigeon2Roll
125 * to use another Pigeon2 on the same CAN bus (this also requires
126 * setting DifferentialRemoteSensorID). Talon FX will update its
127 * differential position to match the selected value whenever Pigeon2
128 * publishes its information on CAN bus. Note that the Talon FX
129 * differential position will be in rotations and not degrees.
130 *
131 * Choose RemoteCANcoder to use another CANcoder on the same CAN bus
132 * (this also requires setting DifferentialRemoteSensorID). Talon FX
133 * will update its differential position and velocity to match the
134 * CANcoder whenever CANcoder publishes its information on CAN bus.
135 *
136 *
137 * \param newDifferentialSensorSource Parameter to modify
138 * \returns Itself
139 */
141 {
142 DifferentialSensorSource = std::move(newDifferentialSensorSource);
143 return *this;
144 }
145
146 /**
147 * \brief Modifies this configuration's DifferentialTalonFXSensorID parameter and returns itself for
148 * method-chaining and easier to use config API.
149 *
150 * Device ID of which remote Talon FX to use. This is used whenever
151 * the Differential Sensor Source is not disabled.
152 *
153 * The differential Talon FX must enable its Position and Velocity
154 * status signals. The update rate of the status signals determines
155 * the update rate of differential control.
156 *
157 * - Minimum Value: 0
158 * - Maximum Value: 62
159 * - Default Value: 0
160 * - Units:
161 *
162 * \param newDifferentialTalonFXSensorID Parameter to modify
163 * \returns Itself
164 */
165 constexpr DifferentialSensorsConfigs &WithDifferentialTalonFXSensorID(int newDifferentialTalonFXSensorID)
166 {
167 DifferentialTalonFXSensorID = std::move(newDifferentialTalonFXSensorID);
168 return *this;
169 }
170
171 /**
172 * \brief Modifies this configuration's DifferentialRemoteSensorID parameter and returns itself for
173 * method-chaining and easier to use config API.
174 *
175 * Device ID of which remote sensor to use on the differential axis.
176 * This is used when the Differential Sensor Source is not Disabled or
177 * RemoteTalonFX_HalfDiff.
178 *
179 * - Minimum Value: 0
180 * - Maximum Value: 62
181 * - Default Value: 0
182 * - Units:
183 *
184 * \param newDifferentialRemoteSensorID Parameter to modify
185 * \returns Itself
186 */
187 constexpr DifferentialSensorsConfigs &WithDifferentialRemoteSensorID(int newDifferentialRemoteSensorID)
188 {
189 DifferentialRemoteSensorID = std::move(newDifferentialRemoteSensorID);
190 return *this;
191 }
192
193 /**
194 * \brief Modifies this configuration's SensorToDifferentialRatio parameter and returns itself for
195 * method-chaining and easier to use config API.
196 *
197 * The ratio of sensor rotations to the differential mechanism's
198 * difference output, where a ratio greater than 1 is a reduction.
199 *
200 * When using RemoteTalonFX_HalfDiff, the sensor is considered half of
201 * the difference between the two devices' mechanism
202 * positions/velocities. As a result, this should be set to the gear
203 * ratio on the difference axis when using RemoteTalonFX_HalfDiff, or
204 * any gear ratio between the sensor and the mechanism differential
205 * when using another sensor source.
206 *
207 * We recommend against using this config to perform onboard unit
208 * conversions. Instead, unit conversions should be performed in
209 * robot code using the units library.
210 *
211 * If this is set to zero, the device will reset back to one.
212 *
213 * - Minimum Value: -1000
214 * - Maximum Value: 1000
215 * - Default Value: 1.0
216 * - Units: scalar
217 *
218 * \param newSensorToDifferentialRatio Parameter to modify
219 * \returns Itself
220 */
221 constexpr DifferentialSensorsConfigs &WithSensorToDifferentialRatio(units::dimensionless::scalar_t newSensorToDifferentialRatio)
222 {
223 SensorToDifferentialRatio = std::move(newSensorToDifferentialRatio);
224 return *this;
225 }
226
227
228
229 std::string ToString() const override;
230
231 std::string Serialize() const final;
232 ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final;
233};
234
235}
236}
237}
Configs related to sensors used for differential control of a mechanism.
Definition DifferentialSensorsConfigs.hpp:25
constexpr DifferentialSensorsConfigs & WithDifferentialTalonFXSensorID(int newDifferentialTalonFXSensorID)
Modifies this configuration's DifferentialTalonFXSensorID parameter and returns itself for method-cha...
Definition DifferentialSensorsConfigs.hpp:165
constexpr DifferentialSensorsConfigs & WithDifferentialSensorSource(signals::DifferentialSensorSourceValue newDifferentialSensorSource)
Modifies this configuration's DifferentialSensorSource parameter and returns itself for method-chaini...
Definition DifferentialSensorsConfigs.hpp:140
constexpr DifferentialSensorsConfigs & WithSensorToDifferentialRatio(units::dimensionless::scalar_t newSensorToDifferentialRatio)
Modifies this configuration's SensorToDifferentialRatio parameter and returns itself for method-chain...
Definition DifferentialSensorsConfigs.hpp:221
ctre::phoenix::StatusCode Deserialize(std::string const &to_deserialize) final
signals::DifferentialSensorSourceValue DifferentialSensorSource
Choose what sensor source is used for differential control of a mechanism.
Definition DifferentialSensorsConfigs.hpp:56
units::dimensionless::scalar_t SensorToDifferentialRatio
The ratio of sensor rotations to the differential mechanism's difference output, where a ratio greate...
Definition DifferentialSensorsConfigs.hpp:105
int DifferentialRemoteSensorID
Device ID of which remote sensor to use on the differential axis.
Definition DifferentialSensorsConfigs.hpp:81
constexpr DifferentialSensorsConfigs & WithDifferentialRemoteSensorID(int newDifferentialRemoteSensorID)
Modifies this configuration's DifferentialRemoteSensorID parameter and returns itself for method-chai...
Definition DifferentialSensorsConfigs.hpp:187
int DifferentialTalonFXSensorID
Device ID of which remote Talon FX to use.
Definition DifferentialSensorsConfigs.hpp:70
Definition Configuration.hpp:17
Definition motor_constants.h:14
Choose what sensor source is used for differential control of a mechanism.
Definition SpnEnums.hpp:2343
static constexpr int Disabled
Disable differential control.
Definition SpnEnums.hpp:2349