CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
TalonFXSimState.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 CoreTalonFX;
24}
25}
26
27namespace sim {
28
29 /**
30 * \brief Class to control the state of a simulated hardware#TalonFX.
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 Represents the type of motor connected to the simulated Talon FX.
47 */
48 enum class MotorType {
49 /** \brief WCP Kraken X60 */
50 KrakenX60 = 0,
51 /** \brief WCP Kraken X44 */
52 KrakenX44 = 1,
53 };
54
55 /**
56 * \brief The orientation of the TalonFX relative to the robot chassis.
57 *
58 * This value should not be changed based on the TalonFX invert.
59 * Rather, this value should be changed when the mechanical linkage
60 * between the TalonFX and the robot changes.
61 */
63
64 /**
65 * \brief Creates an object to control the state of the given hardware#TalonFX.
66 *
67 * \details This constructor defaults to a counter-clockwise positive orientation
68 * relative to the robot chassis. Note the recommended method of accessing
69 * simulation features is to use hardware#TalonFX#GetSimState.
70 *
71 * \param device Device to which this simulation state is attached
72 */
76 /**
77 * \brief Creates an object to control the state of the given hardware#TalonFX.
78 *
79 * \details Note the recommended method of accessing simulation features is to
80 * use hardware#TalonFX#GetSimState.
81 *
82 * \param device Device to which this simulation state is attached
83 * \param orientation Orientation of the device relative to the robot chassis
84 */
86 /* disallow copy, allow move */
91
92 /**
93 * \brief Sets the type of motor connected to the simulated Talon FX.
94 *
95 * \param motorType The type of motor connected
96 * \returns Status code
97 */
99
100 /**
101 * \brief Gets the last status code generated by a simulation function.
102 *
103 * \details Not all functions return a status code but can potentially report errors.
104 * This function can be used to retrieve those status codes.
105 *
106 * \returns Last status code generated by a simulation function
107 */
109
110 /**
111 * \brief Gets the simulated output voltage of the motor.
112 *
113 * \returns Voltage applied to the motor in Volts
114 */
115 units::voltage::volt_t GetMotorVoltage() const;
116 /**
117 * \brief Gets the simulated output torque current of the motor.
118 *
119 * \details Phoenix 6 simulation automatically calculates current.
120 *
121 * \returns Torque current applied to the motor in Amperes
122 */
123 units::current::ampere_t GetTorqueCurrent() const;
124 /**
125 * \brief Gets the simulated supply current of the TalonFX.
126 *
127 * \details Phoenix 6 simulation automatically calculates current.
128 *
129 * \returns Supply current of the TalonFX in Amperes
130 */
131 units::current::ampere_t GetSupplyCurrent() const;
132
133 /**
134 * \brief Sets the simulated supply voltage of the TalonFX.
135 *
136 * \details The minimum allowed supply voltage is 4 V - values below this
137 * will be promoted to 4 V.
138 *
139 * \param volts The supply voltage in Volts
140 * \returns Status code
141 */
142 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
143
144 /**
145 * \brief Sets the simulated forward limit switch of the TalonFX.
146 *
147 * \param closed Whether the limit switch is closed
148 * \returns Status code
149 */
151 /**
152 * \brief Sets the simulated reverse limit switch of the TalonFX.
153 *
154 * \param closed Whether the limit switch is closed
155 * \returns Status code
156 */
158
159 /**
160 * \brief Sets the simulated raw rotor position of the TalonFX. This is the position
161 * of the rotor (before gear ratio) used for the RotorSensor feedback source.
162 *
163 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFX#SetPosition will be accounted for in the callee.
164 *
165 * \details The TalonFX integrates this to calculate the true reported rotor position.
166 *
167 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
168 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
169 * Changes to `rawPositionInput` will be integrated into the emulated position.
170 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
171 *
172 * \param rotations The raw position in rotations
173 * \returns Status code
174 */
175 ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations);
176 /**
177 * \brief Adds to the simulated rotor position of the TalonFX. This adds to the position
178 * of the rotor (before gear ratio) used for the RotorSensor feedback source.
179 *
180 * \param dRotations The change in position in rotations
181 * \returns Status code
182 */
183 ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations);
184 /**
185 * \brief Sets the simulated rotor velocity of the TalonFX. This is the velocity
186 * of the rotor (before gear ratio) used for the RotorSensor feedback source.
187 *
188 * \param rps The new velocity in rotations per second
189 * \returns Status code
190 */
191 ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps);
192 /**
193 * \brief Sets the simulated rotor acceleration of the TalonFX. This is the acceleration
194 * of the rotor (before gear ratio) used for the RotorSensor feedback source.
195 *
196 * \param rpss The new acceleration in rotations per second²
197 * \returns Status code
198 */
199 ctre::phoenix::StatusCode SetRotorAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss);
200 };
201
202}
203
204}
205}
Class description for the Talon FX integrated motor controller.
Definition CoreTalonFX.hpp:3113
Class to control the state of a simulated hardware::TalonFX.
Definition TalonFXSimState.hpp:40
units::current::ampere_t GetSupplyCurrent() const
Gets the simulated supply current of the TalonFX.
ctre::phoenix::StatusCode SetRotorAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss)
Sets the simulated rotor acceleration of the TalonFX.
ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations)
Sets the simulated raw rotor position of the TalonFX.
units::voltage::volt_t GetMotorVoltage() const
Gets the simulated output voltage of the motor.
ctre::phoenix::StatusCode SetMotorType(MotorType motorType)
Sets the type of motor connected to the simulated Talon FX.
ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations)
Adds to the simulated rotor position of the TalonFX.
ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps)
Sets the simulated rotor velocity of the TalonFX.
TalonFXSimState(TalonFXSimState &&)=default
MotorType
Represents the type of motor connected to the simulated Talon FX.
Definition TalonFXSimState.hpp:48
units::current::ampere_t GetTorqueCurrent() const
Gets the simulated output torque current of the motor.
ctre::phoenix::StatusCode SetForwardLimit(bool closed)
Sets the simulated forward limit switch of the TalonFX.
ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts)
Sets the simulated supply voltage of the TalonFX.
TalonFXSimState(hardware::core::CoreTalonFX const &device, ChassisReference orientation)
Creates an object to control the state of the given hardware::TalonFX.
ctre::phoenix::StatusCode SetReverseLimit(bool closed)
Sets the simulated reverse limit switch of the TalonFX.
ChassisReference Orientation
The orientation of the TalonFX relative to the robot chassis.
Definition TalonFXSimState.hpp:62
TalonFXSimState & operator=(TalonFXSimState const &)=delete
TalonFXSimState & operator=(TalonFXSimState &&)=default
ctre::phoenix::StatusCode GetLastStatusCode() const
Gets the last status code generated by a simulation function.
TalonFXSimState(TalonFXSimState const &)=delete
TalonFXSimState(hardware::core::CoreTalonFX const &device)
Creates an object to control the state of the given hardware::TalonFX.
Definition TalonFXSimState.hpp:73
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