Loading [MathJax]/jax/output/HTML-CSS/config.js
CTRE Phoenix 6 C++ 23.10.0-alpha-8
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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_velocity.h>
13#include <units/current.h>
14#include <units/voltage.h>
15
16namespace ctre {
17namespace phoenix6 {
18
19namespace hardware {
20namespace core {
21 /* forward proto */
22 class CoreTalonFX;
23}
24}
25
26namespace sim {
27
28 /**
29 * \brief Class to control the state of a simulated hardware#TalonFX.
30 */
32 {
33 private:
34 int _id;
35
36 public:
37 /**
38 * \brief The orientation of the TalonFX relative to the robot chassis.
39 *
40 * This value should not be changed based on the TalonFX invert.
41 * Rather, this value should be changed when the mechanical linkage
42 * between the TalonFX and the robot changes.
43 */
45
46 /**
47 * \brief Creates an object to control the state of the given hardware#TalonFX.
48 *
49 * \details This constructor defaults to a counter-clockwise positive orientation
50 * relative to the robot chassis. Note the recommended method of accessing
51 * simulation features is to use hardware#TalonFX#GetSimState.
52 *
53 * \param device
54 * Device to which this simulation state is attached
55 */
58 {}
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
66 * Device to which this simulation state is attached
67 * \param orientation
68 * Orientation of the device relative to the robot chassis
69 */
71 /* disallow copy, allow move */
76
77 /**
78 * \brief Gets the last status code generated by a simulation function.
79 *
80 * \details Not all functions return a status code but can potentially report errors.
81 * This function can be used to retrieve those status codes.
82 *
83 * \returns Last status code generated by a simulation function
84 */
85 ctre::phoenix::StatusCode GetLastStatusCode() const;
86 /**
87 * \brief Gets the simulated output voltage of the motor.
88 *
89 * \returns Voltage applied to the motor in Volts
90 */
91 units::voltage::volt_t GetMotorVoltage() const;
92 /**
93 * \brief Gets the simulated output torque current of the motor.
94 *
95 * \details Phoenix 6 simulation automatically calculates current.
96 *
97 * \returns Torque current applied to the motor in Amperes
98 */
99 units::current::ampere_t GetTorqueCurrent() const;
100 /**
101 * \brief Gets the simulated supply current of the TalonFX.
102 *
103 * \details Phoenix 6 simulation automatically calculates current.
104 *
105 * \returns Supply current of the TalonFX in Amperes
106 */
107 units::current::ampere_t GetSupplyCurrent() const;
108
109 /**
110 * \brief Sets the simulated supply voltage of the TalonFX.
111 *
112 * \details The minimum allowed supply voltage is 4 V - values below this
113 * will be promoted to 4 V.
114 *
115 * \param volts
116 * The supply voltage in Volts
117 * \returns Status code
118 */
119 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
120 /**
121 * \brief Sets the simulated forward limit switch of the TalonFX.
122 *
123 * \param closed
124 * Whether the limit switch is closed
125 * \returns Status code
126 */
127 ctre::phoenix::StatusCode SetForwardLimit(bool closed);
128 /**
129 * \brief Sets the simulated reverse limit switch of the TalonFX.
130 *
131 * \param closed
132 * Whether the limit switch is closed
133 * \returns Status code
134 */
135 ctre::phoenix::StatusCode SetReverseLimit(bool closed);
136 /**
137 * \brief Sets the simulated raw rotor position of the TalonFX.
138 *
139 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFX#SetPosition will be accounted for in the callee.
140 *
141 * \details The TalonFX integrates this to calculate the true reported rotor position.
142 *
143 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
144 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
145 * Changes to `rawPositionInput` will be integrated into the emulated position.
146 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
147 *
148 * \param rotations
149 * The raw position in rotations
150 * \returns Status code
151 */
152 ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations);
153 /**
154 * \brief Adds to the simulated rotor position of the TalonFX.
155 *
156 * \param dRotations
157 * The change in position in rotations
158 * \returns Status code
159 */
160 ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations);
161 /**
162 * \brief Sets the simulated rotor velocity of the TalonFX.
163 *
164 * \param rps
165 * The new velocity in rotations per second
166 * \returns Status code
167 */
168 ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps);
169 };
170
171}
172
173}
174}
Class description for the Talon FX integrated motor controller that runs on associated Falcon motors.
Definition: CoreTalonFX.hpp:2367
Class to control the state of a simulated hardware::TalonFX.
Definition: TalonFXSimState.hpp:32
units::current::ampere_t GetSupplyCurrent() const
Gets the simulated supply current 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:44
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
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: ManualEvent.hpp:12