Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 23.10.0-alpha-8
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Diff_DutyCycleOut_VelocityDutyCycle.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 * Requires Phoenix Pro;
26 * Differential control with duty cycle average target and velocity difference
27 * target.
28 */
30{
31 bool ApplyConfigsOnRequest{false};
32
33 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req) override
34 {
35 if (req.get() != this)
36 {
37 auto const reqCast = dynamic_cast<Diff_DutyCycleOut_VelocityDutyCycle *>(req.get());
38 if (reqCast != nullptr)
39 {
40 *reqCast = *this;
41 }
42 else
43 {
44 req = std::make_shared<Diff_DutyCycleOut_VelocityDutyCycle>(*this);
45 }
46 }
47
48 std::stringstream ss;
49
50 std::string strs{ss.str()};
51 c_ctre_phoenix6_requestConfigApply(network, deviceHash, ConfigTimeout.to<double>(), strs.c_str(), strs.length(), ApplyConfigsOnRequest);
52 ApplyConfigsOnRequest = false;
54 }
55
56public:
57 /**
58 * Average DutyCycleOut request of the mechanism.
59 */
61 /**
62 * Differential VelocityDutyCycle request of the mechanism.
63 */
65
66
67
68 /**
69 * \brief The timeout when sending configs associated with this control
70 */
71 units::time::second_t ConfigTimeout{0.1_s};
72
73 /**
74 * \brief The period at which this control will update at.
75 * This is designated in Hertz, with a minimum of 20 Hz
76 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
77 *
78 * If this field is set to 0 Hz, the control request will
79 * be sent immediately as a one-shot frame. This may be useful
80 * for advanced applications that require outputs to be
81 * synchronized with data acquisition. In this case, we
82 * recommend not exceeding 50 ms between control calls.
83 */
84 units::frequency::hertz_t UpdateFreqHz{100_Hz}; // Default to 100_Hz
85
86 /**
87 * \brief Requires Phoenix Pro;
88 * Differential control with duty cycle average
89 * target and velocity difference target.
90 *
91 * \param AverageRequest Average DutyCycleOut request of the mechanism.
92 * \param DifferentialRequest Differential VelocityDutyCycle request of the
93 * mechanism.
94 */
98 {}
99
100 /**
101 * \brief Modifies this Control Request's AverageRequest parameter and returns itself for
102 * method-chaining and easier to use request API.
103 * \param newAverageRequest Parameter to modify
104 * \returns Itself
105 */
107 {
108 AverageRequest = std::move(newAverageRequest);
109 return *this;
110 }
111
112 /**
113 * \brief Modifies this Control Request's DifferentialRequest parameter and returns itself for
114 * method-chaining and easier to use request API.
115 * \param newDifferentialRequest Parameter to modify
116 * \returns Itself
117 */
119 {
120 DifferentialRequest = std::move(newDifferentialRequest);
121 return *this;
122 }
123 /**
124 * \brief Sets the period at which this control will update at.
125 * This is designated in Hertz, with a minimum of 20 Hz
126 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
127 *
128 * If this field is set to 0 Hz, the control request will
129 * be sent immediately as a one-shot frame. This may be useful
130 * for advanced applications that require outputs to be
131 * synchronized with data acquisition. In this case, we
132 * recommend not exceeding 50 ms between control calls.
133 *
134 * \param newUpdateFreqHz Parameter to modify
135 * \returns Itself
136 */
137 Diff_DutyCycleOut_VelocityDutyCycle &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
138 {
139 UpdateFreqHz = newUpdateFreqHz;
140 return *this;
141 }
142 /**
143 * Returns a string representation of the object.
144 *
145 * \returns a string representation of the object.
146 */
147 std::string ToString() const override
148 {
149 std::stringstream ss;
150 ss << "class: Diff_DutyCycleOut_VelocityDutyCycle" << std::endl;
151 ss << "AverageRequest:" << std::endl;
152 ss << " Output: " << AverageRequest.Output.to<double>() << std::endl;
153 ss << " EnableFOC: " << AverageRequest.EnableFOC << std::endl;
154 ss << " OverrideBrakeDurNeutral: " << AverageRequest.OverrideBrakeDurNeutral << std::endl;
155 ss << "DifferentialRequest:" << std::endl;
156 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << std::endl;
157 ss << " Acceleration: " << DifferentialRequest.Acceleration.to<double>() << std::endl;
158 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
159 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << std::endl;
160 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
161 ss << " OverrideBrakeDurNeutral: " << DifferentialRequest.OverrideBrakeDurNeutral << std::endl;
162 return ss.str();
163 }
164
165 /**
166 * \brief Forces configs to be applied the next time this is used in a setControl.
167 * This is not necessary in the majority of cases, because Phoenix will make sure configs are
168 * properly set when they are not already set
169 */
170 void ForceApplyConfigs() { ApplyConfigsOnRequest = true; }
171
172 /**
173 * \brief Gets information about this control request.
174 *
175 * \returns Map of control parameter names and corresponding applied values
176 */
177 std::map<std::string, std::string> GetControlInfo() const override
178 {
179 std::map<std::string, std::string> controlInfo;
180 std::stringstream ss;
181 controlInfo["Name"] = GetName();
182 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
183 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
184 return controlInfo;
185 }
186};
187
188}
189}
190}
191}
192
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_DutyCycleOut_VelocityDutyCycle(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests, double AverageRequest_Output, bool AverageRequest_EnableFOC, bool AverageRequest_OverrideBrakeDurNeutral, double DifferentialRequest_Velocity, double DifferentialRequest_Acceleration, bool DifferentialRequest_EnableFOC, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideBrakeDurNeutral)
CTREXPORT int c_ctre_phoenix6_requestConfigApply(const char *canbus, uint32_t ecuEncoding, double timeoutSeconds, const char *str, uint32_t strlen, bool forceApply)
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
std::string const & GetName() const
Definition: ControlRequest.hpp:51
Request a specified motor duty cycle.
Definition: DutyCycleOut.hpp:28
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition: DutyCycleOut.hpp:76
units::dimensionless::scalar_t Output
Proportion of supply voltage to apply in fractional units between -1 and +1.
Definition: DutyCycleOut.hpp:58
std::string ToString() const override
Returns a string representation of the object.
Definition: DutyCycleOut.hpp:203
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%.
Definition: DutyCycleOut.hpp:69
Request PID to target velocity with duty cycle feedforward.
Definition: VelocityDutyCycle.hpp:31
int Slot
Select which gains are applied by selecting the slot.
Definition: VelocityDutyCycle.hpp:86
units::angular_acceleration::turns_per_second_squared_t Acceleration
Acceleration to drive toward in rotations per second squared.
Definition: VelocityDutyCycle.hpp:65
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition: VelocityDutyCycle.hpp:93
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition: VelocityDutyCycle.hpp:61
units::dimensionless::scalar_t FeedForward
Feedforward to apply in fractional units between -1 and +1.
Definition: VelocityDutyCycle.hpp:80
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%.
Definition: VelocityDutyCycle.hpp:76
std::string ToString() const override
Returns a string representation of the object.
Definition: VelocityDutyCycle.hpp:266
Requires Phoenix Pro; Differential control with duty cycle average target and velocity difference tar...
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:30
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:177
VelocityDutyCycle DifferentialRequest
Differential VelocityDutyCycle request of the mechanism.
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:64
units::time::second_t ConfigTimeout
The timeout when sending configs associated with this control.
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:71
DutyCycleOut AverageRequest
Average DutyCycleOut request of the mechanism.
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:60
std::string ToString() const override
Returns a string representation of the object.
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:147
Diff_DutyCycleOut_VelocityDutyCycle & WithDifferentialRequest(VelocityDutyCycle newDifferentialRequest)
Modifies this Control Request's DifferentialRequest parameter and returns itself for method-chaining ...
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:118
Diff_DutyCycleOut_VelocityDutyCycle & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:137
Diff_DutyCycleOut_VelocityDutyCycle & WithAverageRequest(DutyCycleOut newAverageRequest)
Modifies this Control Request's AverageRequest parameter and returns itself for method-chaining and e...
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:106
Diff_DutyCycleOut_VelocityDutyCycle(DutyCycleOut AverageRequest, VelocityDutyCycle DifferentialRequest)
Requires Phoenix Pro; Differential control with duty cycle average target and velocity difference tar...
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:95
void ForceApplyConfigs()
Forces configs to be applied the next time this is used in a setControl.
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:170
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: Diff_DutyCycleOut_VelocityDutyCycle.hpp:84
Definition: ManualEvent.hpp:12