Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.3.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 */
33 {
34 private:
35 int _id;
36
37 public:
38 /**
39 * \brief The orientation of the motor attached to the TalonFXS
40 * relative to the robot chassis. This include the Commutation
41 * sensor source.
42 *
43 * This value should not be changed based on the TalonFXS invert.
44 * Rather, this value should be changed when the mechanical linkage
45 * between the motor and the robot changes.
46 */
48 /**
49 * \brief The orientation of an external sensor attached to the TalonFXS
50 * relative to the robot chassis. This does NOT include the Commutation
51 * sensor source.
52 *
53 * This value should not be changed based on the TalonFXS invert.
54 * Rather, this value should be changed when the mechanical linkage
55 * between the external sensor and the robot changes.
56 */
58 /**
59 * \brief The number of quadrature edges per sensor rotation for an
60 * external quadrature sensor attached to the TalonFXS.
61 */
63
64 /**
65 * \brief Creates an object to control the state of the given hardware#TalonFXS.
66 *
67 * \details This constructor defaults to a counter-clockwise positive motor and eternal
68 * sensor orientation relative to the robot chassis. Note the recommended method
69 * of accessing simulation features is to use hardware#TalonFXS#GetSimState.
70 *
71 * \param device Device to which this simulation state is attached
72 */
80 /**
81 * \brief Creates an object to control the state of the given hardware#TalonFXS.
82 *
83 * \details Note the recommended method of accessing simulation features is to
84 * use hardware#TalonFXS#GetSimState.
85 *
86 * \param device Device to which this simulation state is attached
87 * \param motorOrientation Orientation of the motor (and commutation sensor) relative to the robot chassis
88 * \param extSensorOrientation Orientation of the external sensor relative to the robot chassis
89 */
91 hardware::core::CoreTalonFXS const &device,
92 ChassisReference motorOrientation,
93 ChassisReference extSensorOrientation
94 );
95 /* disallow copy, allow move */
100
101 /**
102 * \brief Gets the last status code generated by a simulation function.
103 *
104 * \details Not all functions return a status code but can potentially report errors.
105 * This function can be used to retrieve those status codes.
106 *
107 * \returns Last status code generated by a simulation function
108 */
110
111 /**
112 * \brief Gets the simulated output voltage of the motor.
113 *
114 * \returns Voltage applied to the motor in Volts
115 */
116 units::voltage::volt_t GetMotorVoltage() const;
117 /**
118 * \brief Gets the simulated output torque current of the motor.
119 *
120 * \details Phoenix 6 simulation automatically calculates current.
121 *
122 * \returns Torque current applied to the motor in Amperes
123 */
124 units::current::ampere_t GetTorqueCurrent() const;
125 /**
126 * \brief Gets the simulated supply current of the TalonFXS.
127 *
128 * \details Phoenix 6 simulation automatically calculates current.
129 *
130 * \returns Supply current of the TalonFXS in Amperes
131 */
132 units::current::ampere_t GetSupplyCurrent() const;
133 /**
134 * \brief Gets the simulated analog voltage of the TalonFXS.
135 *
136 * \returns Voltage of the simulated analog input pin on the TalonFXS.
137 */
138 units::volt_t GetAnalogVoltage() const;
139 /**
140 * \brief Sets the simulated supply voltage of the TalonFXS.
141 *
142 * \details The minimum allowed supply voltage is 4 V - values below this
143 * will be promoted to 4 V.
144 *
145 * \param volts The supply voltage in Volts
146 * \returns Status code
147 */
148 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
149
150 /**
151 * \brief Sets the simulated forward limit switch of the TalonFXS.
152 *
153 * \param closed Whether the limit switch is closed
154 * \returns Status code
155 */
157 /**
158 * \brief Sets the simulated reverse limit switch of the TalonFXS.
159 *
160 * \param closed Whether the limit switch is closed
161 * \returns Status code
162 */
164
165 /**
166 * \brief Sets the simulated raw rotor position of the TalonFXS. This is the position
167 * of the rotor (before gear ratio) used for the Commutation feedback source.
168 *
169 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFXS#SetPosition will be accounted for in the callee.
170 *
171 * \details The TalonFXS integrates this to calculate the true reported rotor position.
172 *
173 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
174 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
175 * Changes to `rawPositionInput` will be integrated into the emulated position.
176 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
177 *
178 * \param rotations The raw position in rotations
179 * \returns Status code
180 */
181 ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations);
182
183 /**
184 * \brief Sets the simulated voltage of the analog input pin on the TalonFXS data port.
185 *
186 * \param volts Voltage of the pin
187 * \returns Status code
188 */
190
191 /**
192 * \brief Adds to the simulated rotor position of the TalonFXS. This adds to the position
193 * of the rotor (before gear ratio) used for the Commutation feedback source.
194 *
195 * \param dRotations The change in position in rotations
196 * \returns Status code
197 */
198 ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations);
199 /**
200 * \brief Sets the simulated rotor velocity of the TalonFXS. This is the velocity
201 * of the rotor (before gear ratio) used for the Commutation feedback source.
202 *
203 * \param rps The new velocity in rotations per second
204 * \returns Status code
205 */
206 ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps);
207 /**
208 * \brief Sets the simulated rotor acceleration of the TalonFXS. This is the acceleration
209 * of the rotor (before gear ratio) used for the Commutation feedback source.
210 *
211 * \param rpss The new acceleration in rotations per second²
212 * \returns Status code
213 */
214 ctre::phoenix::StatusCode SetRotorAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss);
215
216 /**
217 * \brief Sets the simulated raw quadrature position of the TalonFXS. This is the position
218 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
219 *
220 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFXS#SetPosition will be accounted for in the callee.
221 *
222 * \details The TalonFXS integrates this to calculate the true reported quadrature position.
223 *
224 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
225 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
226 * Changes to `rawPositionInput` will be integrated into the emulated position.
227 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
228 *
229 * \param rotations The raw position in rotations
230 * \returns Status code
231 */
233 /**
234 * \brief Adds to the simulated quadrature position of the TalonFXS. This adds to the position
235 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
236 *
237 * \param dRotations The change in position in rotations
238 * \returns Status code
239 */
240 ctre::phoenix::StatusCode AddQuadraturePosition(units::angle::turn_t dRotations);
241 /**
242 * \brief Sets the simulated quadrature velocity of the TalonFXS. This is the velocity
243 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
244 *
245 * \param rps The new velocity in rotations per second
246 * \returns Status code
247 */
248 ctre::phoenix::StatusCode SetQuadratureVelocity(units::angular_velocity::turns_per_second_t rps);
249 /**
250 * \brief Sets the simulated quadrature acceleration of the TalonFXS. This is the acceleration
251 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
252 *
253 * \param rpss The new acceleration in rotations per second²
254 * \returns Status code
255 */
256 ctre::phoenix::StatusCode SetQuadratureAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss);
257
258 /**
259 * \brief Sets the simulated pulse width position of the TalonFXS. This is the position
260 * of an external PWM encoder after any gear ratio between the rotor and the sensor.
261 *
262 * \param rotations The new position in rotations
263 * \returns Status code
264 */
265 ctre::phoenix::StatusCode SetPulseWidthPosition(units::angle::turn_t rotations);
266 /**
267 * \brief Sets the simulated pulse width velocity of the TalonFXS. This is the velocity
268 * of an external PWM encoder after any gear ratio between the rotor and the sensor.
269 *
270 * \param rps The new velocity in rotations per second
271 * \returns Status code
272 */
273 ctre::phoenix::StatusCode SetPulseWidthVelocity(units::angular_velocity::turns_per_second_t rps);
274 };
275
276}
277
278}
279}
Class description for the Talon FXS motor controller.
Definition CoreTalonFXS.hpp:3113
Class to control the state of a simulated hardware::TalonFXS.
Definition TalonFXSSimState.hpp:33
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:62
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:57
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:73
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:47
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:27
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 MotionMagicExpoTorqueCurrentFOC.hpp:18