CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
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 * \brief The offset of the CANcoder position relative to the robot chassis,
47 * in rotations. This offset is subtracted from the raw position, allowing
48 * for a non-zero magnet offset config to behave correctly in simulation.
49 *
50 * This value should not be changed after initialization unless the
51 * mechanical linkage between the CANcoder and the robot changes.
52 */
53 units::angle::turn_t SensorOffset = 0_tr;
54
55 /**
56 * \brief Creates an object to control the state of the given hardware#CANcoder.
57 *
58 * \details This constructor defaults to a counter-clockwise positive orientation
59 * relative to the robot chassis. Note the recommended method of accessing
60 * simulation features is to use hardware#CANcoder#GetSimState.
61 *
62 * \param device Device to which this simulation state is attached
63 */
67 /**
68 * \brief Creates an object to control the state of the given hardware#CANcoder.
69 *
70 * \details Note the recommended method of accessing simulation features is to
71 * use hardware#CANcoder#GetSimState.
72 *
73 * \param device Device to which this simulation state is attached
74 * \param orientation Orientation of the device relative to the robot chassis
75 */
77 /* disallow copy, allow move */
82
83 /**
84 * \brief Sets the simulated supply voltage of the CANcoder.
85 *
86 * \details The minimum allowed supply voltage is 4 V - values below this
87 * will be promoted to 4 V.
88 *
89 * \param volts The supply voltage in Volts
90 * \returns Status code
91 */
92 ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
93
94 /**
95 * \brief Sets the simulated raw position of the CANcoder.
96 *
97 * Inputs to this function over time should be continuous, as user calls of hardware#CANcoder#SetPosition will be accounted for in the callee.
98 *
99 * \details The CANcoder integrates this to calculate the true reported position.
100 *
101 * When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
102 * The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
103 * Changes to `rawPositionInput` will be integrated into the emulated position.
104 * This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
105 *
106 * \param rotations The raw position in rotations
107 * \returns Status code
108 */
109 ctre::phoenix::StatusCode SetRawPosition(units::angle::turn_t rotations);
110 /**
111 * \brief Adds to the simulated position of the CANcoder.
112 *
113 * \param dRotations
114 * The change in position in rotations
115 * \returns Status code
116 */
117 ctre::phoenix::StatusCode AddPosition(units::angle::turn_t dRotations);
118 /**
119 * \brief Sets the simulated velocity of the CANcoder.
120 *
121 * \param rps The new velocity in rotations per second
122 * \returns Status code
123 */
124 ctre::phoenix::StatusCode SetVelocity(units::angular_velocity::turns_per_second_t rps);
125
126 /**
127 * \brief Sets the simulated magnet health of the CANcoder.
128 *
129 * \param value The magnet health to simulate. This directly correlates to the
130 * red/green/orange state of the simulated LED.
131 * \returns Status code
132 */
134 };
135
136}
137
138}
139}
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CoreCANcoder.hpp:602
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:64
units::angle::turn_t SensorOffset
The offset of the CANcoder position relative to the robot chassis, in rotations.
Definition CANcoderSimState.hpp:53
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
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
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 motor_constants.h:14
Magnet health as measured by CANcoder.
Definition SpnEnums.hpp:2192