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