Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Diff_PositionDutyCycle_Velocity.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 <sstream>
12
15
16namespace ctre {
17namespace phoenix6 {
18namespace controls {
19namespace compound {
20
21/**
22 * \private
23 * Requires Phoenix Pro and CANivore;
24 * Differential control with position average target and velocity difference
25 * target using dutycycle control.
26 */
27class Diff_PositionDutyCycle_Velocity : public ControlRequest
28{
29 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
30 {
31 if (req.get() != this)
32 {
33 auto const reqCast = dynamic_cast<Diff_PositionDutyCycle_Velocity *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<Diff_PositionDutyCycle_Velocity>(*this);
41 }
42 }
43
44 return c_ctre_phoenix6_RequestControlDiff_PositionDutyCycle_Velocity(network, deviceHash, UpdateFreqHz.to<double>(), AverageRequest.Position.to<double>(), AverageRequest.Velocity.to<double>(), AverageRequest.EnableFOC, AverageRequest.FeedForward.to<double>(), AverageRequest.Slot, AverageRequest.OverrideBrakeDurNeutral, AverageRequest.LimitForwardMotion, AverageRequest.LimitReverseMotion, AverageRequest.IgnoreHardwareLimits, AverageRequest.UseTimesync, DifferentialRequest.Velocity.to<double>(), DifferentialRequest.Acceleration.to<double>(), DifferentialRequest.EnableFOC, DifferentialRequest.FeedForward.to<double>(), DifferentialRequest.Slot, DifferentialRequest.OverrideBrakeDurNeutral, DifferentialRequest.LimitForwardMotion, DifferentialRequest.LimitReverseMotion, DifferentialRequest.IgnoreHardwareLimits, DifferentialRequest.UseTimesync);
45 }
46
47public:
48 /**
49 * \brief Average PositionDutyCycle request of the mechanism.
50 */
51 PositionDutyCycle AverageRequest;
52 /**
53 * \brief Differential VelocityDutyCycle request of the mechanism.
54 */
55 VelocityDutyCycle DifferentialRequest;
56
57 /**
58 * \brief The period at which this control will update at.
59 * This is designated in Hertz, with a minimum of 20 Hz
60 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
61 *
62 * If this field is set to 0 Hz, the control request will
63 * be sent immediately as a one-shot frame. This may be useful
64 * for advanced applications that require outputs to be
65 * synchronized with data acquisition. In this case, we
66 * recommend not exceeding 50 ms between control calls.
67 */
68 units::frequency::hertz_t UpdateFreqHz{100_Hz};
69
70 /**
71 * \brief Requires Phoenix Pro and CANivore;
72 * Differential control with position average target and velocity
73 * difference target using dutycycle control.
74 *
75 * \param AverageRequest Average PositionDutyCycle request of the mechanism.
76 * \param DifferentialRequest Differential VelocityDutyCycle request of the
77 * mechanism.
78 */
79 Diff_PositionDutyCycle_Velocity(PositionDutyCycle AverageRequest, VelocityDutyCycle DifferentialRequest) : ControlRequest{"Diff_PositionDutyCycle_Velocity"},
80 AverageRequest{std::move(AverageRequest)},
81 DifferentialRequest{std::move(DifferentialRequest)}
82 {}
83
84 /**
85 * \brief Modifies this Control Request's AverageRequest parameter and returns itself for
86 * method-chaining and easier to use request API.
87 *
88 * Average PositionDutyCycle request of the mechanism.
89 *
90 * \param newAverageRequest Parameter to modify
91 * \returns Itself
92 */
93 Diff_PositionDutyCycle_Velocity &WithAverageRequest(PositionDutyCycle newAverageRequest)
94 {
95 AverageRequest = std::move(newAverageRequest);
96 return *this;
97 }
98
99 /**
100 * \brief Modifies this Control Request's DifferentialRequest parameter and returns itself for
101 * method-chaining and easier to use request API.
102 *
103 * Differential VelocityDutyCycle request of the mechanism.
104 *
105 * \param newDifferentialRequest Parameter to modify
106 * \returns Itself
107 */
108 Diff_PositionDutyCycle_Velocity &WithDifferentialRequest(VelocityDutyCycle newDifferentialRequest)
109 {
110 DifferentialRequest = std::move(newDifferentialRequest);
111 return *this;
112 }
113 /**
114 * \brief Sets the period at which this control will update at.
115 * This is designated in Hertz, with a minimum of 20 Hz
116 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
117 *
118 * If this field is set to 0 Hz, the control request will
119 * be sent immediately as a one-shot frame. This may be useful
120 * for advanced applications that require outputs to be
121 * synchronized with data acquisition. In this case, we
122 * recommend not exceeding 50 ms between control calls.
123 *
124 * \param newUpdateFreqHz Parameter to modify
125 * \returns Itself
126 */
127 Diff_PositionDutyCycle_Velocity &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
128 {
129 UpdateFreqHz = newUpdateFreqHz;
130 return *this;
131 }
132 /**
133 * \brief Returns a string representation of the object.
134 *
135 * \returns a string representation of the object.
136 */
137 std::string ToString() const override
138 {
139 std::stringstream ss;
140 ss << "Control: Diff_PositionDutyCycle_Velocity" << std::endl;
141 ss << " AverageRequest:" << std::endl;
142 ss << " Position: " << AverageRequest.Position.to<double>() << " rotations" << std::endl;
143 ss << " Velocity: " << AverageRequest.Velocity.to<double>() << " rotations per second" << std::endl;
144 ss << " EnableFOC: " << AverageRequest.EnableFOC << std::endl;
145 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << " fractional" << std::endl;
146 ss << " Slot: " << AverageRequest.Slot << std::endl;
147 ss << " OverrideBrakeDurNeutral: " << AverageRequest.OverrideBrakeDurNeutral << std::endl;
148 ss << " LimitForwardMotion: " << AverageRequest.LimitForwardMotion << std::endl;
149 ss << " LimitReverseMotion: " << AverageRequest.LimitReverseMotion << std::endl;
150 ss << " IgnoreHardwareLimits: " << AverageRequest.IgnoreHardwareLimits << std::endl;
151 ss << " UseTimesync: " << AverageRequest.UseTimesync << std::endl;
152 ss << " DifferentialRequest:" << std::endl;
153 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << " rotations per second" << std::endl;
154 ss << " Acceleration: " << DifferentialRequest.Acceleration.to<double>() << " rotations per second²" << std::endl;
155 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
156 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << " fractional" << std::endl;
157 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
158 ss << " OverrideBrakeDurNeutral: " << DifferentialRequest.OverrideBrakeDurNeutral << std::endl;
159 ss << " LimitForwardMotion: " << DifferentialRequest.LimitForwardMotion << std::endl;
160 ss << " LimitReverseMotion: " << DifferentialRequest.LimitReverseMotion << std::endl;
161 ss << " IgnoreHardwareLimits: " << DifferentialRequest.IgnoreHardwareLimits << std::endl;
162 ss << " UseTimesync: " << DifferentialRequest.UseTimesync << std::endl;
163 return ss.str();
164 }
165
166 /**
167 * \brief Gets information about this control request.
168 *
169 * \returns Map of control parameter names and corresponding applied values
170 */
171 std::map<std::string, std::string> GetControlInfo() const override
172 {
173 std::map<std::string, std::string> controlInfo;
174 std::stringstream ss;
175 controlInfo["Name"] = GetName();
176 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
177 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
178 return controlInfo;
179 }
180};
181
182}
183}
184}
185}
186
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_PositionDutyCycle_Velocity(const char *canbus, uint32_t ecuEncoding, double updateTime, double AverageRequest_Position, double AverageRequest_Velocity, bool AverageRequest_EnableFOC, double AverageRequest_FeedForward, int AverageRequest_Slot, bool AverageRequest_OverrideBrakeDurNeutral, bool AverageRequest_LimitForwardMotion, bool AverageRequest_LimitReverseMotion, bool AverageRequest_IgnoreHardwareLimits, bool AverageRequest_UseTimesync, double DifferentialRequest_Velocity, double DifferentialRequest_Acceleration, bool DifferentialRequest_EnableFOC, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideBrakeDurNeutral, bool DifferentialRequest_LimitForwardMotion, bool DifferentialRequest_LimitReverseMotion, bool DifferentialRequest_IgnoreHardwareLimits, bool DifferentialRequest_UseTimesync)
std::string const & GetName() const
Definition ControlRequest.hpp:53
ControlRequest(ControlRequest const &)=default
units::dimensionless::scalar_t FeedForward
Feedforward to apply in fractional units between -1 and +1.
Definition PositionDutyCycle.hpp:85
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition PositionDutyCycle.hpp:123
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition PositionDutyCycle.hpp:64
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15% on supp...
Definition PositionDutyCycle.hpp:78
units::angle::turn_t Position
Position to drive toward in rotations.
Definition PositionDutyCycle.hpp:56
bool LimitForwardMotion
Set to true to force forward limiting.
Definition PositionDutyCycle.hpp:104
int Slot
Select which gains are applied by selecting the slot.
Definition PositionDutyCycle.hpp:91
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition PositionDutyCycle.hpp:98
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition PositionDutyCycle.hpp:134
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition PositionDutyCycle.hpp:110
int Slot
Select which gains are applied by selecting the slot.
Definition VelocityDutyCycle.hpp:91
units::angular_acceleration::turns_per_second_squared_t Acceleration
Acceleration to drive toward in rotations per second squared.
Definition VelocityDutyCycle.hpp:64
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition VelocityDutyCycle.hpp:98
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition VelocityDutyCycle.hpp:123
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition VelocityDutyCycle.hpp:56
units::dimensionless::scalar_t FeedForward
Feedforward to apply in fractional units between -1 and +1.
Definition VelocityDutyCycle.hpp:85
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15% on supp...
Definition VelocityDutyCycle.hpp:78
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition VelocityDutyCycle.hpp:110
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition VelocityDutyCycle.hpp:134
bool LimitForwardMotion
Set to true to force forward limiting.
Definition VelocityDutyCycle.hpp:104
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401