CTRE Phoenix 6 C++ 25.0.0-beta-4
Loading...
Searching...
No Matches
Diff_DutyCycleOut_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
12#include <sstream>
15#include <units/frequency.h>
16#include <units/time.h>
17
18
19namespace ctre {
20namespace phoenix6 {
21namespace controls {
22namespace compound {
23
24/**
25 * \private
26 * Requires Phoenix Pro and CANivore;
27 * Differential control with duty cycle average target and velocity difference
28 * target.
29 */
30class Diff_DutyCycleOut_Velocity : public ControlRequest
31{
32 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
33 {
34 if (req.get() != this)
35 {
36 auto const reqCast = dynamic_cast<Diff_DutyCycleOut_Velocity *>(req.get());
37 if (reqCast != nullptr)
38 {
39 *reqCast = *this;
40 }
41 else
42 {
43 req = std::make_shared<Diff_DutyCycleOut_Velocity>(*this);
44 }
45 }
46
47 return c_ctre_phoenix6_RequestControlDiff_DutyCycleOut_Velocity(network, deviceHash, UpdateFreqHz.to<double>(), AverageRequest.Output.to<double>(), AverageRequest.EnableFOC, 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);
48 }
49
50public:
51 /**
52 * \brief Average DutyCycleOut request of the mechanism.
53 */
54 DutyCycleOut AverageRequest;
55 /**
56 * \brief Differential VelocityDutyCycle request of the mechanism.
57 */
58 VelocityDutyCycle DifferentialRequest;
59
60 /**
61 * \brief The period at which this control will update at.
62 * This is designated in Hertz, with a minimum of 20 Hz
63 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
64 *
65 * If this field is set to 0 Hz, the control request will
66 * be sent immediately as a one-shot frame. This may be useful
67 * for advanced applications that require outputs to be
68 * synchronized with data acquisition. In this case, we
69 * recommend not exceeding 50 ms between control calls.
70 */
71 units::frequency::hertz_t UpdateFreqHz{100_Hz};
72
73 /**
74 * \brief Requires Phoenix Pro and CANivore;
75 * Differential control with duty cycle average target and velocity
76 * difference target.
77 *
78 * \param AverageRequest Average DutyCycleOut request of the mechanism.
79 * \param DifferentialRequest Differential VelocityDutyCycle request of the
80 * mechanism.
81 */
82 Diff_DutyCycleOut_Velocity(DutyCycleOut AverageRequest, VelocityDutyCycle DifferentialRequest) : ControlRequest{"Diff_DutyCycleOut_Velocity"},
83 AverageRequest{std::move(AverageRequest)},
84 DifferentialRequest{std::move(DifferentialRequest)}
85 {}
86
87 /**
88 * \brief Modifies this Control Request's AverageRequest parameter and returns itself for
89 * method-chaining and easier to use request API.
90 *
91 * Average DutyCycleOut request of the mechanism.
92 *
93 * \param newAverageRequest Parameter to modify
94 * \returns Itself
95 */
96 Diff_DutyCycleOut_Velocity &WithAverageRequest(DutyCycleOut newAverageRequest)
97 {
98 AverageRequest = std::move(newAverageRequest);
99 return *this;
100 }
101
102 /**
103 * \brief Modifies this Control Request's DifferentialRequest parameter and returns itself for
104 * method-chaining and easier to use request API.
105 *
106 * Differential VelocityDutyCycle request of the mechanism.
107 *
108 * \param newDifferentialRequest Parameter to modify
109 * \returns Itself
110 */
111 Diff_DutyCycleOut_Velocity &WithDifferentialRequest(VelocityDutyCycle newDifferentialRequest)
112 {
113 DifferentialRequest = std::move(newDifferentialRequest);
114 return *this;
115 }
116 /**
117 * \brief Sets the period at which this control will update at.
118 * This is designated in Hertz, with a minimum of 20 Hz
119 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
120 *
121 * If this field is set to 0 Hz, the control request will
122 * be sent immediately as a one-shot frame. This may be useful
123 * for advanced applications that require outputs to be
124 * synchronized with data acquisition. In this case, we
125 * recommend not exceeding 50 ms between control calls.
126 *
127 * \param newUpdateFreqHz Parameter to modify
128 * \returns Itself
129 */
130 Diff_DutyCycleOut_Velocity &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
131 {
132 UpdateFreqHz = newUpdateFreqHz;
133 return *this;
134 }
135 /**
136 * \brief Returns a string representation of the object.
137 *
138 * \returns a string representation of the object.
139 */
140 std::string ToString() const override
141 {
142 std::stringstream ss;
143 ss << "Control: Diff_DutyCycleOut_Velocity" << std::endl;
144 ss << "AverageRequest:" << std::endl;
145 ss << " Output: " << AverageRequest.Output.to<double>() << std::endl;
146 ss << " EnableFOC: " << AverageRequest.EnableFOC << 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>() << std::endl;
154 ss << " Acceleration: " << DifferentialRequest.Acceleration.to<double>() << std::endl;
155 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
156 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << 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_DutyCycleOut_Velocity(const char *canbus, uint32_t ecuEncoding, double updateTime, double AverageRequest_Output, bool AverageRequest_EnableFOC, 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:52
ControlRequest(ControlRequest const &)=default
bool LimitForwardMotion
Set to true to force forward limiting.
Definition DutyCycleOut.hpp:78
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition DutyCycleOut.hpp:72
units::dimensionless::scalar_t Output
Proportion of supply voltage to apply in fractional units between -1 and +1.
Definition DutyCycleOut.hpp:52
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition DutyCycleOut.hpp:108
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition DutyCycleOut.hpp:97
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%.
Definition DutyCycleOut.hpp:65
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition DutyCycleOut.hpp:84
int Slot
Select which gains are applied by selecting the slot.
Definition VelocityDutyCycle.hpp:82
units::angular_acceleration::turns_per_second_squared_t Acceleration
Acceleration to drive toward in rotations per second squared.
Definition VelocityDutyCycle.hpp:59
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition VelocityDutyCycle.hpp:89
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition VelocityDutyCycle.hpp:114
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition VelocityDutyCycle.hpp:54
units::dimensionless::scalar_t FeedForward
Feedforward to apply in fractional units between -1 and +1.
Definition VelocityDutyCycle.hpp:76
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%.
Definition VelocityDutyCycle.hpp:72
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition VelocityDutyCycle.hpp:101
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition VelocityDutyCycle.hpp:125
bool LimitForwardMotion
Set to true to force forward limiting.
Definition VelocityDutyCycle.hpp:95
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition StatusCodes.h:18
Definition span.hpp:401