1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright (C) Cross The Road Electronics. All rights reserved.
* License information can be found in CTRE_LICENSE.txt
* For support and suggestions contact support@ctr-electronics.com or file
* an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
*/
#pragma once
#include "ctre/phoenix/StatusCodes.h"
#include "ctre/phoenix6/signals/SpnEnums.hpp"
#include "ctre/phoenix6/sim/ChassisReference.hpp"
#include <units/angle.h>
#include <units/angular_velocity.h>
#include <units/voltage.h>
namespace ctre {
namespace phoenix6 {
namespace hardware {
namespace core {
/* forward proto */
class CoreCANcoder;
}
}
namespace sim {
/**
* \brief Class to control the state of a simulated hardware#CANcoder.
*/
class CANcoderSimState
{
private:
int _id;
public:
/**
* \brief The orientation of the CANcoder relative to the robot chassis.
*
* This value should not be changed based on the CANcoder invert.
* Rather, this value should be changed when the mechanical linkage
* between the CANcoder and the robot changes.
*/
ChassisReference Orientation;
/**
* \brief The offset of the CANcoder position relative to the robot chassis,
* in rotations. This offset is subtracted from the raw position, allowing
* for a non-zero magnet offset config to behave correctly in simulation.
*
* This value should not be changed after initialization unless the
* mechanical linkage between the CANcoder and the robot changes.
*/
units::angle::turn_t SensorOffset = 0_tr;
/**
* \brief Creates an object to control the state of the given hardware#CANcoder.
*
* \details This constructor defaults to a counter-clockwise positive orientation
* relative to the robot chassis. Note the recommended method of accessing
* simulation features is to use hardware#CANcoder#GetSimState.
*
* \param device Device to which this simulation state is attached
*/
CANcoderSimState(hardware::core::CoreCANcoder const &device) :
CANcoderSimState{device, ChassisReference::CounterClockwise_Positive}
{}
/**
* \brief Creates an object to control the state of the given hardware#CANcoder.
*
* \details Note the recommended method of accessing simulation features is to
* use hardware#CANcoder#GetSimState.
*
* \param device Device to which this simulation state is attached
* \param orientation Orientation of the device relative to the robot chassis
*/
CANcoderSimState(hardware::core::CoreCANcoder const &device, ChassisReference orientation);
/* disallow copy, allow move */
CANcoderSimState(CANcoderSimState const &) = delete;
CANcoderSimState(CANcoderSimState &&) = default;
CANcoderSimState &operator=(CANcoderSimState const &) = delete;
CANcoderSimState &operator=(CANcoderSimState &&) = default;
/**
* \brief Sets the simulated supply voltage of the CANcoder.
*
* \details The minimum allowed supply voltage is 4 V - values below this
* will be promoted to 4 V.
*
* \param volts The supply voltage in Volts
* \returns Status code
*/
ctre::phoenix::StatusCode SetSupplyVoltage(units::voltage::volt_t volts);
/**
* \brief Sets the simulated raw position of the CANcoder.
*
* Inputs to this function over time should be continuous, as user calls of hardware#CANcoder#SetPosition will be accounted for in the callee.
*
* \details The CANcoder integrates this to calculate the true reported position.
*
* When using the WPI Sim GUI, you will notice a readonly `position` and settable `rawPositionInput`.
* The readonly signal is the emulated position which will match self-test in Tuner and the hardware API.
* Changes to `rawPositionInput` will be integrated into the emulated position.
* This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.
*
* \param rotations The raw position in rotations
* \returns Status code
*/
ctre::phoenix::StatusCode SetRawPosition(units::angle::turn_t rotations);
/**
* \brief Adds to the simulated position of the CANcoder.
*
* \param dRotations
* The change in position in rotations
* \returns Status code
*/
ctre::phoenix::StatusCode AddPosition(units::angle::turn_t dRotations);
/**
* \brief Sets the simulated velocity of the CANcoder.
*
* \param rps The new velocity in rotations per second
* \returns Status code
*/
ctre::phoenix::StatusCode SetVelocity(units::angular_velocity::turns_per_second_t rps);
/**
* \brief Sets the simulated magnet health of the CANcoder.
*
* \param value The magnet health to simulate. This directly correlates to the
* red/green/orange state of the simulated LED.
* \returns Status code
*/
ctre::phoenix::StatusCode SetMagnetHealth(ctre::phoenix6::signals::MagnetHealthValue value);
};
}
}
}