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_PositionDutyCycle_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>
14#include <units/frequency.h>
15#include <units/time.h>
16
17
18namespace ctre {
19namespace phoenix6 {
20namespace controls {
21namespace compound {
22
23/**
24 * Requires Phoenix Pro;
25 * Differential control with position average target and position difference
26 * target using dutycycle control.
27 */
29{
30 bool ApplyConfigsOnRequest{false};
31
32 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req) override
33 {
34 if (req.get() != this)
35 {
36 auto const reqCast = dynamic_cast<Diff_PositionDutyCycle_PositionDutyCycle *>(req.get());
37 if (reqCast != nullptr)
38 {
39 *reqCast = *this;
40 }
41 else
42 {
43 req = std::make_shared<Diff_PositionDutyCycle_PositionDutyCycle>(*this);
44 }
45 }
46
47 std::stringstream ss;
48
49 std::string strs{ss.str()};
50 c_ctre_phoenix6_requestConfigApply(network, deviceHash, ConfigTimeout.to<double>(), strs.c_str(), strs.length(), ApplyConfigsOnRequest);
51 ApplyConfigsOnRequest = false;
53 }
54
55public:
56 /**
57 * Average PositionDutyCycle request of the mechanism.
58 */
60 /**
61 * Differential PositionDutyCycle request of the mechanism.
62 */
64
65
66
67 /**
68 * \brief The timeout when sending configs associated with this control
69 */
70 units::time::second_t ConfigTimeout{0.1_s};
71
72 /**
73 * \brief The period at which this control will update at.
74 * This is designated in Hertz, with a minimum of 20 Hz
75 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
76 *
77 * If this field is set to 0 Hz, the control request will
78 * be sent immediately as a one-shot frame. This may be useful
79 * for advanced applications that require outputs to be
80 * synchronized with data acquisition. In this case, we
81 * recommend not exceeding 50 ms between control calls.
82 */
83 units::frequency::hertz_t UpdateFreqHz{100_Hz}; // Default to 100_Hz
84
85 /**
86 * \brief Requires Phoenix Pro;
87 * Differential control with position average
88 * target and position difference target using dutycycle control.
89 *
90 * \param AverageRequest Average PositionDutyCycle request of the mechanism.
91 * \param DifferentialRequest Differential PositionDutyCycle request of the
92 * mechanism.
93 */
97 {}
98
99 /**
100 * \brief Modifies this Control Request's AverageRequest parameter and returns itself for
101 * method-chaining and easier to use request API.
102 * \param newAverageRequest Parameter to modify
103 * \returns Itself
104 */
106 {
107 AverageRequest = std::move(newAverageRequest);
108 return *this;
109 }
110
111 /**
112 * \brief Modifies this Control Request's DifferentialRequest parameter and returns itself for
113 * method-chaining and easier to use request API.
114 * \param newDifferentialRequest Parameter to modify
115 * \returns Itself
116 */
118 {
119 DifferentialRequest = std::move(newDifferentialRequest);
120 return *this;
121 }
122 /**
123 * \brief Sets the period at which this control will update at.
124 * This is designated in Hertz, with a minimum of 20 Hz
125 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
126 *
127 * If this field is set to 0 Hz, the control request will
128 * be sent immediately as a one-shot frame. This may be useful
129 * for advanced applications that require outputs to be
130 * synchronized with data acquisition. In this case, we
131 * recommend not exceeding 50 ms between control calls.
132 *
133 * \param newUpdateFreqHz Parameter to modify
134 * \returns Itself
135 */
136 Diff_PositionDutyCycle_PositionDutyCycle &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
137 {
138 UpdateFreqHz = newUpdateFreqHz;
139 return *this;
140 }
141 /**
142 * Returns a string representation of the object.
143 *
144 * \returns a string representation of the object.
145 */
146 std::string ToString() const override
147 {
148 std::stringstream ss;
149 ss << "class: Diff_PositionDutyCycle_PositionDutyCycle" << std::endl;
150 ss << "AverageRequest:" << std::endl;
151 ss << " Position: " << AverageRequest.Position.to<double>() << std::endl;
152 ss << " Velocity: " << AverageRequest.Velocity.to<double>() << std::endl;
153 ss << " EnableFOC: " << AverageRequest.EnableFOC << std::endl;
154 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << std::endl;
155 ss << " Slot: " << AverageRequest.Slot << std::endl;
156 ss << " OverrideBrakeDurNeutral: " << AverageRequest.OverrideBrakeDurNeutral << std::endl;
157 ss << "DifferentialRequest:" << std::endl;
158 ss << " Position: " << DifferentialRequest.Position.to<double>() << std::endl;
159 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << std::endl;
160 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
161 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << std::endl;
162 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
163 ss << " OverrideBrakeDurNeutral: " << DifferentialRequest.OverrideBrakeDurNeutral << std::endl;
164 return ss.str();
165 }
166
167 /**
168 * \brief Forces configs to be applied the next time this is used in a setControl.
169 * This is not necessary in the majority of cases, because Phoenix will make sure configs are
170 * properly set when they are not already set
171 */
172 void ForceApplyConfigs() { ApplyConfigsOnRequest = true; }
173
174 /**
175 * \brief Gets information about this control request.
176 *
177 * \returns Map of control parameter names and corresponding applied values
178 */
179 std::map<std::string, std::string> GetControlInfo() const override
180 {
181 std::map<std::string, std::string> controlInfo;
182 std::stringstream ss;
183 controlInfo["Name"] = GetName();
184 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
185 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
186 return controlInfo;
187 }
188};
189
190}
191}
192}
193}
194
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_PositionDutyCycle_PositionDutyCycle(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests, double AverageRequest_Position, double AverageRequest_Velocity, 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)
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 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
Requires Phoenix Pro; Differential control with position average target and position difference targe...
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:29
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:83
units::time::second_t ConfigTimeout
The timeout when sending configs associated with this control.
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:70
std::string ToString() const override
Returns a string representation of the object.
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:146
Diff_PositionDutyCycle_PositionDutyCycle(PositionDutyCycle AverageRequest, PositionDutyCycle DifferentialRequest)
Requires Phoenix Pro; Differential control with position average target and position difference targe...
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:94
Diff_PositionDutyCycle_PositionDutyCycle & WithDifferentialRequest(PositionDutyCycle newDifferentialRequest)
Modifies this Control Request's DifferentialRequest parameter and returns itself for method-chaining ...
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:117
PositionDutyCycle DifferentialRequest
Differential PositionDutyCycle request of the mechanism.
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:63
Diff_PositionDutyCycle_PositionDutyCycle & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:136
Diff_PositionDutyCycle_PositionDutyCycle & WithAverageRequest(PositionDutyCycle newAverageRequest)
Modifies this Control Request's AverageRequest parameter and returns itself for method-chaining and e...
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:105
void ForceApplyConfigs()
Forces configs to be applied the next time this is used in a setControl.
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:172
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:179
PositionDutyCycle AverageRequest
Average PositionDutyCycle request of the mechanism.
Definition: Diff_PositionDutyCycle_PositionDutyCycle.hpp:59
Definition: ManualEvent.hpp:12