CTRE Phoenix Pro C++ 23.0.12
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 phoenixpro {
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.
51 *
52 * \param device
53 * Device to which this simulation state is attached
54 */
57 {}
58 /**
59 * \brief Creates an object to control the state of the given hardware#TalonFX.
60 *
61 * \param device
62 * Device to which this simulation state is attached
63 * \param orientation
64 * Orientation of the device relative to the robot chassis
65 */
67 /* disallow copy, allow move */
72
73 /**
74 * \brief Gets the last status code generated by a simulation function.
75 *
76 * \details Not all functions return a status code but can potentially report errors.
77 * This function can be used to retrieve those status codes.
78 *
79 * \returns Last status code generated by a simulation function
80 */
81 ctre::phoenix::StatusCode GetLastStatusCode() const;
82 /**
83 * \brief Gets the simulated output voltage of the motor.
84 *
85 * \returns Voltage applied to the motor in Volts
86 */
87 units::voltage::volt_t GetMotorVoltage() const;
88 /**
89 * \brief Gets the simulated output torque current of the motor.
90 *
91 * \returns Torque current applied to the motor in Amperes
92 */
93 units::current::ampere_t GetTorqueCurrent() const;
94 /**
95 * \brief Gets the simulated supply current of the TalonFX.
96 *
97 * \returns Supply current of the TalonFX in Amperes
98 */
99 units::current::ampere_t GetSupplyCurrent() const;
100
101 /**
102 * \brief Sets the simulated supply voltage of the TalonFX.
103 *
104 * \details The minimum allowed supply voltage is 4 V - values below this
105 * will be promoted to 4 V.
106 *
107 * \param volts
108 * The supply voltage in Volts
109 * \returns Status code
110 */
111 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
112 /**
113 * \brief Sets the simulated forward limit switch of the TalonFX.
114 *
115 * \param closed
116 * Whether the limit switch is closed
117 * \returns Status code
118 */
119 ctre::phoenix::StatusCode SetForwardLimit(bool closed);
120 /**
121 * \brief Sets the simulated reverse 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 SetReverseLimit(bool closed);
128 /**
129 * \brief Sets the simulated raw rotor position of the TalonFX.
130 *
131 * Inputs to this function over time should be continuous, as user calls of hardware#TalonFX#SetRotorPosition will be accounted for in the callee.
132 *
133 * \details The TalonFX integrates this to calculate the true reported rotor position.
134 *
135 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
136 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
137 * Changes to `rawPositionInput` will be integrated into the emulated position.
138 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
139 *
140 * \param rotations
141 * The raw position in rotations
142 * \returns Status code
143 */
144 ctre::phoenix::StatusCode SetRawRotorPosition(units::angle::turn_t rotations);
145 /**
146 * \brief Adds to the simulated rotor position of the TalonFX.
147 *
148 * \param dRotations
149 * The change in position in rotations
150 * \returns Status code
151 */
152 ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations);
153 /**
154 * \brief Sets the simulated rotor velocity of the TalonFX.
155 *
156 * \param rps
157 * The new velocity in rotations per second
158 * \returns Status code
159 */
160 ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps);
161 };
162
163}
164
165}
166}
Class description for the Talon FX integrated motor controller that runs on associated Falcon motors.
Definition: CoreTalonFX.hpp:1401
Class to control the state of a simulated hardware::TalonFX.
Definition: TalonFXSimState.hpp:32
ctre::phoenix::StatusCode SetForwardLimit(bool closed)
Sets the simulated forward limit switch of the TalonFX.
units::current::ampere_t GetSupplyCurrent() const
Gets the simulated supply current of the TalonFX.
TalonFXSimState & operator=(TalonFXSimState &&)=default
TalonFXSimState(TalonFXSimState const &)=delete
TalonFXSimState & operator=(TalonFXSimState const &)=delete
ctre::phoenix::StatusCode AddRotorPosition(units::angle::turn_t dRotations)
Adds to the simulated rotor position of the TalonFX.
units::voltage::volt_t GetMotorVoltage() const
Gets the simulated output voltage of the motor.
units::current::ampere_t GetTorqueCurrent() const
Gets the simulated output torque current of the motor.
ctre::phoenix::StatusCode GetLastStatusCode() const
Gets the last status code generated by a simulation function.
ctre::phoenix::StatusCode SetReverseLimit(bool closed)
Sets the simulated reverse limit switch 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 SetRawRotorPosition(units::angle::turn_t rotations)
Sets the simulated raw rotor position of the TalonFX.
TalonFXSimState(hardware::core::CoreTalonFX const &device)
Creates an object to control the state of the given hardware::TalonFX.
Definition: TalonFXSimState.hpp:55
ChassisReference Orientation
The orientation of the TalonFX relative to the robot chassis.
Definition: TalonFXSimState.hpp:44
TalonFXSimState(TalonFXSimState &&)=default
ctre::phoenix::StatusCode SetRotorVelocity(units::angular_velocity::turns_per_second_t rps)
Sets the simulated rotor velocity of the TalonFX.
ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts)
Sets the simulated supply voltage of the TalonFX.
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:14