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_VelocityDutyCycle_PositionDutyCycle.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 velocity average target and position difference
27 * target using dutycycle control.
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_VelocityDutyCycle_PositionDutyCycle *>(req.get());
38 if (reqCast != nullptr)
39 {
40 *reqCast = *this;
41 }
42 else
43 {
44 req = std::make_shared<Diff_VelocityDutyCycle_PositionDutyCycle>(*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 VelocityDutyCYcle request of the mechanism.
59 */
61 /**
62 * Differential PositionDutyCycle 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 velocity average
89 * target and position difference target using dutycycle control.
90 *
91 * \param AverageRequest Average VelocityDutyCYcle request of the mechanism.
92 * \param DifferentialRequest Differential PositionDutyCycle 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_VelocityDutyCycle_PositionDutyCycle &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_VelocityDutyCycle_PositionDutyCycle" << std::endl;
151 ss << "AverageRequest:" << std::endl;
152 ss << " Velocity: " << AverageRequest.Velocity.to<double>() << std::endl;
153 ss << " Acceleration: " << AverageRequest.Acceleration.to<double>() << std::endl;
154 ss << " EnableFOC: " << AverageRequest.EnableFOC << std::endl;
155 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << std::endl;
156 ss << " Slot: " << AverageRequest.Slot << std::endl;
157 ss << " OverrideBrakeDurNeutral: " << AverageRequest.OverrideBrakeDurNeutral << std::endl;
158 ss << "DifferentialRequest:" << std::endl;
159 ss << " Position: " << DifferentialRequest.Position.to<double>() << std::endl;
160 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << std::endl;
161 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
162 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << std::endl;
163 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
164 ss << " OverrideBrakeDurNeutral: " << DifferentialRequest.OverrideBrakeDurNeutral << std::endl;
165 return ss.str();
166 }
167
168 /**
169 * \brief Forces configs to be applied the next time this is used in a setControl.
170 * This is not necessary in the majority of cases, because Phoenix will make sure configs are
171 * properly set when they are not already set
172 */
173 void ForceApplyConfigs() { ApplyConfigsOnRequest = true; }
174
175 /**
176 * \brief Gets information about this control request.
177 *
178 * \returns Map of control parameter names and corresponding applied values
179 */
180 std::map<std::string, std::string> GetControlInfo() const override
181 {
182 std::map<std::string, std::string> controlInfo;
183 std::stringstream ss;
184 controlInfo["Name"] = GetName();
185 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
186 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
187 return controlInfo;
188 }
189};
190
191}
192}
193}
194}
195
CTREXPORT int c_ctre_phoenix6_requestConfigApply(const char *canbus, uint32_t ecuEncoding, double timeoutSeconds, const char *str, uint32_t strlen, bool forceApply)
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_VelocityDutyCycle_PositionDutyCycle(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests, double AverageRequest_Velocity, double AverageRequest_Acceleration, bool AverageRequest_EnableFOC, double AverageRequest_FeedForward, int AverageRequest_Slot, bool AverageRequest_OverrideBrakeDurNeutral, double DifferentialRequest_Position, double DifferentialRequest_Velocity, bool DifferentialRequest_EnableFOC, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideBrakeDurNeutral)
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 PID to target position with duty cycle feedforward.
Definition: PositionDutyCycle.hpp:31
units::dimensionless::scalar_t FeedForward
Feedforward to apply in fractional units between -1 and +1.
Definition: PositionDutyCycle.hpp:80
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition: PositionDutyCycle.hpp:65
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%.
Definition: PositionDutyCycle.hpp:76
units::angle::turn_t Position
Position to drive toward in rotations.
Definition: PositionDutyCycle.hpp:61
int Slot
Select which gains are applied by selecting the slot.
Definition: PositionDutyCycle.hpp:86
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition: PositionDutyCycle.hpp:93
std::string ToString() const override
Returns a string representation of the object.
Definition: PositionDutyCycle.hpp:265
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 velocity average target and position difference targe...
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:30
Diff_VelocityDutyCycle_PositionDutyCycle(VelocityDutyCycle AverageRequest, PositionDutyCycle DifferentialRequest)
Requires Phoenix Pro; Differential control with velocity average target and position difference targe...
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:95
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:84
PositionDutyCycle DifferentialRequest
Differential PositionDutyCycle request of the mechanism.
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:64
VelocityDutyCycle AverageRequest
Average VelocityDutyCYcle request of the mechanism.
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:60
units::time::second_t ConfigTimeout
The timeout when sending configs associated with this control.
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:71
void ForceApplyConfigs()
Forces configs to be applied the next time this is used in a setControl.
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:173
Diff_VelocityDutyCycle_PositionDutyCycle & WithAverageRequest(VelocityDutyCycle newAverageRequest)
Modifies this Control Request's AverageRequest parameter and returns itself for method-chaining and e...
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:106
std::string ToString() const override
Returns a string representation of the object.
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:147
Diff_VelocityDutyCycle_PositionDutyCycle & WithDifferentialRequest(PositionDutyCycle newDifferentialRequest)
Modifies this Control Request's DifferentialRequest parameter and returns itself for method-chaining ...
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:118
Diff_VelocityDutyCycle_PositionDutyCycle & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:137
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition: Diff_VelocityDutyCycle_PositionDutyCycle.hpp:180
Definition: ManualEvent.hpp:12