CTRE Phoenix 6 C++ 25.2.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 */
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 /**
135 * \brief Sets the simulated supply voltage of the TalonFXS.
136 *
137 * \details The minimum allowed supply voltage is 4 V - values below this
138 * will be promoted to 4 V.
139 *
140 * \param volts The supply voltage in Volts
141 * \returns Status code
142 */
143 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
144
145 /**
146 * \brief Sets the simulated forward limit switch of the TalonFXS.
147 *
148 * \param closed Whether the limit switch is closed
149 * \returns Status code
150 */
152 /**
153 * \brief Sets the simulated reverse limit switch of the TalonFXS.
154 *
155 * \param closed Whether the limit switch is closed
156 * \returns Status code
157 */
159
160 /**
161 * \brief Sets the simulated raw rotor position of the TalonFXS. This is the position
162 * of the rotor (before gear ratio) used for the Commutation feedback source.
163 *
164 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFXS#SetPosition will be accounted for in the callee.
165 *
166 * \details The TalonFXS integrates this to calculate the true reported rotor position.
167 *
168 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
169 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
170 * Changes to `rawPositionInput` will be integrated into the emulated position.
171 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
172 *
173 * \param rotations The raw position in rotations
174 * \returns Status code
175 */
176 ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations);
177 /**
178 * \brief Adds to the simulated rotor position of the TalonFXS. This adds to the position
179 * of the rotor (before gear ratio) used for the Commutation feedback source.
180 *
181 * \param dRotations The change in position in rotations
182 * \returns Status code
183 */
184 ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations);
185 /**
186 * \brief Sets the simulated rotor velocity of the TalonFXS. This is the velocity
187 * of the rotor (before gear ratio) used for the Commutation feedback source.
188 *
189 * \param rps The new velocity in rotations per second
190 * \returns Status code
191 */
192 ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps);
193 /**
194 * \brief Sets the simulated rotor acceleration of the TalonFXS. This is the acceleration
195 * of the rotor (before gear ratio) used for the Commutation feedback source.
196 *
197 * \param rpss The new acceleration in rotations per second²
198 * \returns Status code
199 */
200 ctre::phoenix::StatusCode SetRotorAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss);
201
202 /**
203 * \brief Sets the simulated raw quadrature position of the TalonFXS. This is the position
204 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
205 *
206 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFXS#SetPosition will be accounted for in the callee.
207 *
208 * \details The TalonFXS integrates this to calculate the true reported quadrature position.
209 *
210 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
211 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
212 * Changes to `rawPositionInput` will be integrated into the emulated position.
213 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
214 *
215 * \param rotations The raw position in rotations
216 * \returns Status code
217 */
219 /**
220 * \brief Adds to the simulated quadrature position of the TalonFXS. This adds to the position
221 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
222 *
223 * \param dRotations The change in position in rotations
224 * \returns Status code
225 */
226 ctre::phoenix::StatusCode AddQuadraturePosition(units::angle::turn_t dRotations);
227 /**
228 * \brief Sets the simulated quadrature velocity of the TalonFXS. This is the velocity
229 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
230 *
231 * \param rps The new velocity in rotations per second
232 * \returns Status code
233 */
234 ctre::phoenix::StatusCode SetQuadratureVelocity(units::angular_velocity::turns_per_second_t rps);
235 /**
236 * \brief Sets the simulated quadrature acceleration of the TalonFXS. This is the acceleration
237 * of an external quadrature encoder after any gear ratio between the rotor and the sensor.
238 *
239 * \param rpss The new acceleration in rotations per second²
240 * \returns Status code
241 */
242 ctre::phoenix::StatusCode SetQuadratureAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss);
243
244 /**
245 * \brief Sets the simulated pulse width position of the TalonFXS. This is the position
246 * of an external PWM encoder after any gear ratio between the rotor and the sensor.
247 *
248 * \param rotations The new position in rotations
249 * \returns Status code
250 */
251 ctre::phoenix::StatusCode SetPulseWidthPosition(units::angle::turn_t rotations);
252 /**
253 * \brief Sets the simulated pulse width velocity of the TalonFXS. This is the velocity
254 * of an external PWM encoder after any gear ratio between the rotor and the sensor.
255 *
256 * \param rps The new velocity in rotations per second
257 * \returns Status code
258 */
259 ctre::phoenix::StatusCode SetPulseWidthVelocity(units::angular_velocity::turns_per_second_t rps);
260 };
261
262}
263
264}
265}
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.
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 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