CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
TalonFXSSimState.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/angle.h>
12#include <units/angular_acceleration.h>
13#include <units/angular_velocity.h>
14#include <units/current.h>
15#include <units/voltage.h>
16
17namespace ctre {
18namespace phoenix6 {
19
20namespace hardware {
21namespace core {
22 /* forward proto */
23 class CoreTalonFXS;
24}
25}
26
27namespace sim {
28
29 /**
30 * \brief Class to control the state of a simulated hardware#TalonFXS.
31 *
32 * For simulated PID control and current limits to behave correctly,
33 * #SetRawRotorPosition and #SetRotorVelocity must be updated
34 * periodically. This is typically done by sending the motor output from
35 * #GetMotorVoltage() or #GetTorqueCurrent() to a physics simulator
36 * (such as WPILib's `DCMotorSim`), which then calculates the new motor
37 * position and velocity.
38 */
40 {
41 private:
42 int _id;
43
44 public:
45 /**
46 * \brief The orientation of the motor attached to the TalonFXS
47 * relative to the robot chassis. This include the Commutation
48 * sensor source.
49 *
50 * This value should not be changed based on the TalonFXS invert.
51 * Rather, this value should be changed when the mechanical linkage
52 * between the motor and the robot changes.
53 */
55
56 /**
57 * \brief The orientation of an external sensor attached to the TalonFXS
58 * relative to the robot chassis. This does NOT include the Commutation
59 * sensor source.
60 *
61 * This value should not be changed based on the TalonFXS invert.
62 * Rather, this value should be changed when the mechanical linkage
63 * between the external sensor and the robot changes.
64 */
66 /**
67 * \brief The offset of an absolute external sensor attached to the Talon FXS
68 * relative to the robot chassis, in rotations. This offset is subtracted
69 * from the Pulse Width position, allowing for a non-zero sensor offset
70 * config to behave correctly in simulation.
71 *
72 * This value should not be changed after initialization unless the
73 * mechanical linkage between the external sensor and the robot changes.
74 */
75 units::angle::turn_t PulseWidthSensorOffset = 0_tr;
76 /**
77 * \brief The number of quadrature edges per sensor rotation for an
78 * external quadrature sensor attached to the TalonFXS.
79 */
81
82 /**
83 * \brief Creates an object to control the state of the given hardware#TalonFXS.
84 *
85 * \details This constructor defaults to a counter-clockwise positive motor and eternal
86 * sensor orientation relative to the robot chassis. Note the recommended method
87 * of accessing simulation features is to use hardware#TalonFXS#GetSimState.
88 *
89 * \param device Device to which this simulation state is attached
90 */
98 /**
99 * \brief Creates an object to control the state of the given hardware#TalonFXS.
100 *
101 * \details Note the recommended method of accessing simulation features is to
102 * use hardware#TalonFXS#GetSimState.
103 *
104 * \param device Device to which this simulation state is attached
105 * \param motorOrientation Orientation of the motor (and commutation sensor) relative to the robot chassis
106 * \param extSensorOrientation Orientation of the external sensor relative to the robot chassis
107 */
109 hardware::core::CoreTalonFXS const &device,
110 ChassisReference motorOrientation,
111 ChassisReference extSensorOrientation
112 );
113 /* disallow copy, allow move */
118
119 /**
120 * \brief Gets the last status code generated by a simulation function.
121 *
122 * \details Not all functions return a status code but can potentially report errors.
123 * This function can be used to retrieve those status codes.
124 *
125 * \returns Last status code generated by a simulation function
126 */
128
129 /**
130 * \brief Gets the simulated output voltage of the motor.
131 *
132 * \returns Voltage applied to the motor in Volts
133 */
134 units::voltage::volt_t GetMotorVoltage() const;
135 /**
136 * \brief Gets the simulated output torque current of the motor.
137 *
138 * \details Phoenix 6 simulation automatically calculates current.
139 *
140 * \returns Torque current applied to the motor in Amperes
141 */
142 units::current::ampere_t GetTorqueCurrent() const;
143 /**
144 * \brief Gets the simulated supply current of the TalonFXS.
145 *
146 * \details Phoenix 6 simulation automatically calculates current.
147 *
148 * \returns Supply current of the TalonFXS in Amperes
149 */
150 units::current::ampere_t GetSupplyCurrent() const;
151 /**
152 * \brief Gets the simulated analog voltage of the TalonFXS.
153 *
154 * \returns Voltage of the simulated analog input pin on the TalonFXS.
155 */
156 units::volt_t GetAnalogVoltage() const;
157 /**
158 * \brief Sets the simulated supply voltage of the TalonFXS.
159 *
160 * \details The minimum allowed supply voltage is 4 V - values below this
161 * will be promoted to 4 V.
162 *
163 * \param volts The supply voltage in Volts
164 * \returns Status code
165 */
166 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
167
168 /**
169 * \brief Sets the simulated forward limit switch of the TalonFXS.
170 *
171 * \param closed Whether the limit switch is closed
172 * \returns Status code
173 */
175 /**
176 * \brief Sets the simulated reverse limit switch of the TalonFXS.
177 *
178 * \param closed Whether the limit switch is closed
179 * \returns Status code
180 */
182
183 /**
184 * \brief Sets the simulated raw rotor position of the TalonFXS. This is the position
185 * of the rotor (before gear ratio) used for the Commutation feedback source.
186 *
187 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFXS#SetPosition will be accounted for in the callee.
188 *
189 * \details The TalonFXS integrates this to calculate the true reported rotor position.
190 *
191 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
192 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
193 * Changes to `rawPositionInput` will be integrated into the emulated position.
194 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
195 *
196 * \param rotations The raw position in rotations
197 * \returns Status code
198 */
199 ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations);
200
201 /**
202 * \brief Sets the simulated voltage of the analog input pin on the TalonFXS data port.
203 *
204 * \param volts Voltage of the pin
205 * \returns Status code
206 */
208
209 /**
210 * \brief Adds to the simulated rotor position of the TalonFXS. This adds to the position
211 * of the rotor (before gear ratio) used for the Commutation feedback source.
212 *
213 * \param dRotations The change in position in rotations
214 * \returns Status code
215 */
216 ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations);
217 /**
218 * \brief Sets the simulated rotor velocity of the TalonFXS. This is the velocity
219 * of the rotor (before gear ratio) used for the Commutation feedback source.
220 *
221 * \param rps The new velocity in rotations per second
222 * \returns Status code
223 */
224 ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps);
225 /**
226 * \brief Sets the simulated rotor acceleration of the TalonFXS. This is the acceleration
227 * of the rotor (before gear ratio) used for the Commutation feedback source.
228 *
229 * \param rpss The new acceleration in rotations per second²
230 * \returns Status code
231 */
232 ctre::phoenix::StatusCode SetRotorAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss);
233
234 /**
235 * \brief Sets the simulated raw quadrature position of the TalonFXS. This is the position
236 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
237 *
238 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFXS#SetPosition will be accounted for in the callee.
239 *
240 * \details The TalonFXS integrates this to calculate the true reported quadrature position.
241 *
242 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
243 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
244 * Changes to `rawPositionInput` will be integrated into the emulated position.
245 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
246 *
247 * \param rotations The raw position in rotations
248 * \returns Status code
249 */
251 /**
252 * \brief Adds to the simulated quadrature position of the TalonFXS. This adds to the position
253 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
254 *
255 * \param dRotations The change in position in rotations
256 * \returns Status code
257 */
258 ctre::phoenix::StatusCode AddQuadraturePosition(units::angle::turn_t dRotations);
259 /**
260 * \brief Sets the simulated quadrature velocity of the TalonFXS. This is the velocity
261 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
262 *
263 * \param rps The new velocity in rotations per second
264 * \returns Status code
265 */
266 ctre::phoenix::StatusCode SetQuadratureVelocity(units::angular_velocity::turns_per_second_t rps);
267 /**
268 * \brief Sets the simulated quadrature acceleration of the TalonFXS. This is the acceleration
269 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
270 *
271 * \param rpss The new acceleration in rotations per second²
272 * \returns Status code
273 */
274 ctre::phoenix::StatusCode SetQuadratureAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss);
275
276 /**
277 * \brief Sets the simulated pulse width position of the TalonFXS. This is the position
278 * of an external PWM encoder after any gear ratio between the rotor and the sensor.
279 *
280 * \param rotations The new position in rotations
281 * \returns Status code
282 */
283 ctre::phoenix::StatusCode SetPulseWidthPosition(units::angle::turn_t rotations);
284 /**
285 * \brief Sets the simulated pulse width velocity of the TalonFXS. This is the velocity
286 * of an external PWM encoder after any gear ratio between the rotor and the sensor.
287 *
288 * \param rps The new velocity in rotations per second
289 * \returns Status code
290 */
291 ctre::phoenix::StatusCode SetPulseWidthVelocity(units::angular_velocity::turns_per_second_t rps);
292 };
293
294}
295
296}
297}
Class description for the Talon FXS motor controller.
Definition CoreTalonFXS.hpp:3531
Class to control the state of a simulated hardware::TalonFXS.
Definition TalonFXSSimState.hpp:40
ctre::phoenix::StatusCode SetQuadratureAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss)
Sets the simulated quadrature acceleration of the TalonFXS.
units::volt_t GetAnalogVoltage() const
Gets the simulated analog voltage of the TalonFXS.
TalonFXSSimState & operator=(TalonFXSSimState &&)=default
ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations)
Adds to the simulated rotor position of the TalonFXS.
TalonFXSSimState(hardware::core::CoreTalonFXS const &device, ChassisReference motorOrientation, ChassisReference extSensorOrientation)
Creates an object to control the state of the given hardware::TalonFXS.
int QuadratureEdgesPerRotation
The number of quadrature edges per sensor rotation for an external quadrature sensor attached to the ...
Definition TalonFXSSimState.hpp:80
ctre::phoenix::StatusCode SetRawQuadraturePosition(units::angle::turn_t rotations)
Sets the simulated raw quadrature position of the TalonFXS.
ctre::phoenix::StatusCode AddQuadraturePosition(units::angle::turn_t dRotations)
Adds to the simulated quadrature position of the TalonFXS.
ctre::phoenix::StatusCode SetForwardLimit(bool closed)
Sets the simulated forward limit switch of the TalonFXS.
ctre::phoenix::StatusCode SetPulseWidthPosition(units::angle::turn_t rotations)
Sets the simulated pulse width position of the TalonFXS.
ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts)
Sets the simulated supply voltage of the TalonFXS.
ChassisReference ExtSensorOrientation
The orientation of an external sensor attached to the TalonFXS relative to the robot chassis.
Definition TalonFXSSimState.hpp:65
ctre::phoenix::StatusCode GetLastStatusCode() const
Gets the last status code generated by a simulation function.
TalonFXSSimState & operator=(TalonFXSSimState const &)=delete
ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps)
Sets the simulated rotor velocity of the TalonFXS.
TalonFXSSimState(TalonFXSSimState const &)=delete
ctre::phoenix::StatusCode SetQuadratureVelocity(units::angular_velocity::turns_per_second_t rps)
Sets the simulated quadrature velocity of the TalonFXS.
TalonFXSSimState(TalonFXSSimState &&)=default
TalonFXSSimState(hardware::core::CoreTalonFXS const &device)
Creates an object to control the state of the given hardware::TalonFXS.
Definition TalonFXSSimState.hpp:91
units::voltage::volt_t GetMotorVoltage() const
Gets the simulated output voltage of the motor.
ChassisReference MotorOrientation
The orientation of the motor attached to the TalonFXS relative to the robot chassis.
Definition TalonFXSSimState.hpp:54
units::angle::turn_t PulseWidthSensorOffset
The offset of an absolute external sensor attached to the Talon FXS relative to the robot chassis,...
Definition TalonFXSSimState.hpp:75
units::current::ampere_t GetTorqueCurrent() const
Gets the simulated output torque current of the motor.
ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations)
Sets the simulated raw rotor position of the TalonFXS.
ctre::phoenix::StatusCode SetReverseLimit(bool closed)
Sets the simulated reverse limit switch of the TalonFXS.
units::current::ampere_t GetSupplyCurrent() const
Gets the simulated supply current of the TalonFXS.
ctre::phoenix::StatusCode SetAnalogVoltage(units::volt_t volts)
Sets the simulated voltage of the analog input pin on the TalonFXS data port.
ctre::phoenix::StatusCode SetPulseWidthVelocity(units::angular_velocity::turns_per_second_t rps)
Sets the simulated pulse width velocity of the TalonFXS.
ctre::phoenix::StatusCode SetRotorAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss)
Sets the simulated rotor acceleration of the TalonFXS.
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
ChassisReference
Represents the orientation of a device relative to the robot chassis.
Definition ChassisReference.hpp:16
@ CounterClockwise_Positive
The device should read a counter-clockwise rotation as positive motion.
Definition motor_constants.h:14