CTRE Phoenix 6 C++ 24.3.0
CANcoderSimState.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
12#include <units/angle.h>
13#include <units/angular_velocity.h>
14#include <units/voltage.h>
15
16namespace ctre {
17namespace phoenix6 {
18
19namespace hardware {
20namespace core {
21 /* forward proto */
22 class CoreCANcoder;
23}
24}
25
26namespace sim {
27
28 /**
29 * \brief Class to control the state of a simulated hardware#CANcoder.
30 */
32 {
33 private:
34 int _id;
35
36 public:
37 /**
38 * \brief The orientation of the CANcoder relative to the robot chassis.
39 *
40 * This value should not be changed based on the CANcoder invert.
41 * Rather, this value should be changed when the mechanical linkage
42 * between the CANcoder and the robot changes.
43 */
45
46 /**
47 * \brief Creates an object to control the state of the given hardware#CANcoder.
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#CANcoder#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#CANcoder.
61 *
62 * \details Note the recommended method of accessing simulation features is to
63 * use hardware#CANcoder#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 Sets the simulated supply voltage of the CANcoder.
79 *
80 * \details The minimum allowed supply voltage is 4 V - values below this
81 * will be promoted to 4 V.
82 *
83 * \param volts
84 * The supply voltage in Volts
85 * \returns Status code
86 */
87 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
88 /**
89 * \brief Sets the simulated raw position of the CANcoder.
90 *
91 * Inputs to this function over time should be continuous, as user calls of hardware#CANcoder#SetPosition will be accounted for in the callee.
92 *
93 * \details The CANcoder integrates this to calculate the true reported position.
94 *
95 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
96 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
97 * Changes to `rawPositionInput` will be integrated into the emulated position.
98 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
99 *
100 * \param rotations
101 * The raw position in rotations
102 * \returns Status code
103 */
104 ctre::phoenix::StatusCode SetRawPosition(units::angle::turn_t rotations);
105 /**
106 * \brief Adds to the simulated position of the CANcoder.
107 *
108 * \param dRotations
109 * The change in position in rotations
110 * \returns Status code
111 */
112 ctre::phoenix::StatusCode AddPosition(units::angle::turn_t dRotations);
113 /**
114 * \brief Sets the simulated velocity of the CANcoder.
115 *
116 * \param rps
117 * The new velocity in rotations per second
118 * \returns Status code
119 */
120 ctre::phoenix::StatusCode SetVelocity(units::angular_velocity::turns_per_second_t rps);
121 /**
122 * \brief Sets the simulated magnet health of the CANcoder.
123 *
124 * \param value
125 * The magnet health to simulate. This directly correlates to the
126 * red/green/orange state of the simulated LED.
127 * \returns Status code
128 */
130 };
131
132}
133
134}
135}
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition: CoreCANcoder.hpp:504
Magnet health as measured by CANcoder.
Definition: SpnEnums.hpp:2019
Class to control the state of a simulated hardware::CANcoder.
Definition: CANcoderSimState.hpp:32
ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts)
Sets the simulated supply voltage of the CANcoder.
ChassisReference Orientation
The orientation of the CANcoder relative to the robot chassis.
Definition: CANcoderSimState.hpp:44
ctre::phoenix::StatusCode SetVelocity(units::angular_velocity::turns_per_second_t rps)
Sets the simulated velocity of the CANcoder.
CANcoderSimState & operator=(CANcoderSimState &&)=default
CANcoderSimState(CANcoderSimState const &)=delete
CANcoderSimState(hardware::core::CoreCANcoder const &device, ChassisReference orientation)
Creates an object to control the state of the given hardware::CANcoder.
CANcoderSimState(hardware::core::CoreCANcoder const &device)
Creates an object to control the state of the given hardware::CANcoder.
Definition: CANcoderSimState.hpp:56
ctre::phoenix::StatusCode SetRawPosition(units::angle::turn_t rotations)
Sets the simulated raw position of the CANcoder.
ctre::phoenix::StatusCode AddPosition(units::angle::turn_t dRotations)
Adds to the simulated position of the CANcoder.
ctre::phoenix::StatusCode SetMagnetHealth(ctre::phoenix6::signals::MagnetHealthValue value)
Sets the simulated magnet health of the CANcoder.
CANcoderSimState(CANcoderSimState &&)=default
CANcoderSimState & operator=(CANcoderSimState const &)=delete
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