CTRE Phoenix 6 C++ 24.3.0
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 */
33 {
34 private:
35 int _id;
36
37 public:
38 /**
39 * \brief The orientation of the TalonFX relative to the robot chassis.
40 *
41 * This value should not be changed based on the TalonFX invert.
42 * Rather, this value should be changed when the mechanical linkage
43 * between the TalonFX and the robot changes.
44 */
46
47 /**
48 * \brief Creates an object to control the state of the given hardware#TalonFX.
49 *
50 * \details This constructor defaults to a counter-clockwise positive orientation
51 * relative to the robot chassis. Note the recommended method of accessing
52 * simulation features is to use hardware#TalonFX#GetSimState.
53 *
54 * \param device
55 * Device to which this simulation state is attached
56 */
59 {}
60 /**
61 * \brief Creates an object to control the state of the given hardware#TalonFX.
62 *
63 * \details Note the recommended method of accessing simulation features is to
64 * use hardware#TalonFX#GetSimState.
65 *
66 * \param device
67 * Device to which this simulation state is attached
68 * \param orientation
69 * Orientation of the device relative to the robot chassis
70 */
72 /* disallow copy, allow move */
77
78 /**
79 * \brief Gets the last status code generated by a simulation function.
80 *
81 * \details Not all functions return a status code but can potentially report errors.
82 * This function can be used to retrieve those status codes.
83 *
84 * \returns Last status code generated by a simulation function
85 */
86 ctre::phoenix::StatusCode GetLastStatusCode() const;
87 /**
88 * \brief Gets the simulated output voltage of the motor.
89 *
90 * \returns Voltage applied to the motor in Volts
91 */
92 units::voltage::volt_t GetMotorVoltage() const;
93 /**
94 * \brief Gets the simulated output torque current of the motor.
95 *
96 * \details Phoenix 6 simulation automatically calculates current.
97 *
98 * \returns Torque current applied to the motor in Amperes
99 */
100 units::current::ampere_t GetTorqueCurrent() const;
101 /**
102 * \brief Gets the simulated supply current of the TalonFX.
103 *
104 * \details Phoenix 6 simulation automatically calculates current.
105 *
106 * \returns Supply current of the TalonFX in Amperes
107 */
108 units::current::ampere_t GetSupplyCurrent() const;
109
110 /**
111 * \brief Sets the simulated supply voltage of the TalonFX.
112 *
113 * \details The minimum allowed supply voltage is 4 V - values below this
114 * will be promoted to 4 V.
115 *
116 * \param volts
117 * The supply voltage in Volts
118 * \returns Status code
119 */
120 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
121 /**
122 * \brief Sets the simulated forward limit switch of the TalonFX.
123 *
124 * \param closed
125 * Whether the limit switch is closed
126 * \returns Status code
127 */
128 ctre::phoenix::StatusCode SetForwardLimit(bool closed);
129 /**
130 * \brief Sets the simulated reverse limit switch of the TalonFX.
131 *
132 * \param closed
133 * Whether the limit switch is closed
134 * \returns Status code
135 */
136 ctre::phoenix::StatusCode SetReverseLimit(bool closed);
137 /**
138 * \brief Sets the simulated raw rotor position of the TalonFX.
139 *
140 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFX#SetPosition will be accounted for in the callee.
141 *
142 * \details The TalonFX integrates this to calculate the true reported rotor position.
143 *
144 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
145 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
146 * Changes to `rawPositionInput` will be integrated into the emulated position.
147 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
148 *
149 * \param rotations
150 * The raw position in rotations
151 * \returns Status code
152 */
153 ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations);
154 /**
155 * \brief Adds to the simulated rotor position of the TalonFX.
156 *
157 * \param dRotations
158 * The change in position in rotations
159 * \returns Status code
160 */
161 ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations);
162 /**
163 * \brief Sets the simulated rotor velocity of the TalonFX.
164 *
165 * \param rps
166 * The new velocity in rotations per second
167 * \returns Status code
168 */
169 ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps);
170 /**
171 * \brief Sets the simulated rotor acceleration of the TalonFX.
172 *
173 * \param rpss
174 * The new acceleration in rotations per second²
175 * \returns Status code
176 */
177 ctre::phoenix::StatusCode SetRotorAcceleration(units::angular_acceleration::turns_per_second_squared_t rpss);
178 };
179
180}
181
182}
183}
Class description for the Talon FX integrated motor controller.
Definition: CoreTalonFX.hpp:2734
Class to control the state of a simulated hardware::TalonFX.
Definition: TalonFXSimState.hpp:33
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 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
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:45
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:57
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: string_util.hpp:15