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_Position.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
14
15namespace ctre {
16namespace phoenix6 {
17namespace controls {
18namespace compound {
19
20/**
21 * \private
22 * Requires Phoenix Pro and CANivore;
23 * Differential control with position average target and position difference
24 * target using dutycycle control.
25 */
26class Diff_PositionDutyCycle_Position : public ControlRequest
27{
28 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
29 {
30 if (req.get() != this)
31 {
32 auto const reqCast = dynamic_cast<Diff_PositionDutyCycle_Position *>(req.get());
33 if (reqCast != nullptr)
34 {
35 *reqCast = *this;
36 }
37 else
38 {
39 req = std::make_shared<Diff_PositionDutyCycle_Position>(*this);
40 }
41 }
42
43 return c_ctre_phoenix6_RequestControlDiff_PositionDutyCycle_Position(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.Position.to<double>(), DifferentialRequest.Velocity.to<double>(), DifferentialRequest.EnableFOC, DifferentialRequest.FeedForward.to<double>(), DifferentialRequest.Slot, DifferentialRequest.OverrideBrakeDurNeutral, DifferentialRequest.LimitForwardMotion, DifferentialRequest.LimitReverseMotion, DifferentialRequest.IgnoreHardwareLimits, DifferentialRequest.UseTimesync);
44 }
45
46public:
47 /**
48 * \brief Average PositionDutyCycle request of the mechanism.
49 */
50 PositionDutyCycle AverageRequest;
51 /**
52 * \brief Differential PositionDutyCycle request of the mechanism.
53 */
54 PositionDutyCycle DifferentialRequest;
55
56 /**
57 * \brief The period at which this control will update at.
58 * This is designated in Hertz, with a minimum of 20 Hz
59 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
60 *
61 * If this field is set to 0 Hz, the control request will
62 * be sent immediately as a one-shot frame. This may be useful
63 * for advanced applications that require outputs to be
64 * synchronized with data acquisition. In this case, we
65 * recommend not exceeding 50 ms between control calls.
66 */
67 units::frequency::hertz_t UpdateFreqHz{100_Hz};
68
69 /**
70 * \brief Requires Phoenix Pro and CANivore;
71 * Differential control with position average target and position
72 * difference target using dutycycle control.
73 *
74 * \param AverageRequest Average PositionDutyCycle request of the mechanism.
75 * \param DifferentialRequest Differential PositionDutyCycle request of the
76 * mechanism.
77 */
78 Diff_PositionDutyCycle_Position(PositionDutyCycle AverageRequest, PositionDutyCycle DifferentialRequest) : ControlRequest{"Diff_PositionDutyCycle_Position"},
79 AverageRequest{std::move(AverageRequest)},
80 DifferentialRequest{std::move(DifferentialRequest)}
81 {}
82
83 /**
84 * \brief Modifies this Control Request's AverageRequest parameter and returns itself for
85 * method-chaining and easier to use request API.
86 *
87 * Average PositionDutyCycle request of the mechanism.
88 *
89 * \param newAverageRequest Parameter to modify
90 * \returns Itself
91 */
92 Diff_PositionDutyCycle_Position &WithAverageRequest(PositionDutyCycle newAverageRequest)
93 {
94 AverageRequest = std::move(newAverageRequest);
95 return *this;
96 }
97
98 /**
99 * \brief Modifies this Control Request's DifferentialRequest parameter and returns itself for
100 * method-chaining and easier to use request API.
101 *
102 * Differential PositionDutyCycle request of the mechanism.
103 *
104 * \param newDifferentialRequest Parameter to modify
105 * \returns Itself
106 */
107 Diff_PositionDutyCycle_Position &WithDifferentialRequest(PositionDutyCycle newDifferentialRequest)
108 {
109 DifferentialRequest = std::move(newDifferentialRequest);
110 return *this;
111 }
112 /**
113 * \brief Sets the period at which this control will update at.
114 * This is designated in Hertz, with a minimum of 20 Hz
115 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
116 *
117 * If this field is set to 0 Hz, the control request will
118 * be sent immediately as a one-shot frame. This may be useful
119 * for advanced applications that require outputs to be
120 * synchronized with data acquisition. In this case, we
121 * recommend not exceeding 50 ms between control calls.
122 *
123 * \param newUpdateFreqHz Parameter to modify
124 * \returns Itself
125 */
126 Diff_PositionDutyCycle_Position &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
127 {
128 UpdateFreqHz = newUpdateFreqHz;
129 return *this;
130 }
131 /**
132 * \brief Returns a string representation of the object.
133 *
134 * \returns a string representation of the object.
135 */
136 std::string ToString() const override
137 {
138 std::stringstream ss;
139 ss << "Control: Diff_PositionDutyCycle_Position" << std::endl;
140 ss << " AverageRequest:" << std::endl;
141 ss << " Position: " << AverageRequest.Position.to<double>() << " rotations" << std::endl;
142 ss << " Velocity: " << AverageRequest.Velocity.to<double>() << " rotations per second" << std::endl;
143 ss << " EnableFOC: " << AverageRequest.EnableFOC << std::endl;
144 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << " fractional" << std::endl;
145 ss << " Slot: " << AverageRequest.Slot << std::endl;
146 ss << " OverrideBrakeDurNeutral: " << AverageRequest.OverrideBrakeDurNeutral << std::endl;
147 ss << " LimitForwardMotion: " << AverageRequest.LimitForwardMotion << std::endl;
148 ss << " LimitReverseMotion: " << AverageRequest.LimitReverseMotion << std::endl;
149 ss << " IgnoreHardwareLimits: " << AverageRequest.IgnoreHardwareLimits << std::endl;
150 ss << " UseTimesync: " << AverageRequest.UseTimesync << std::endl;
151 ss << " DifferentialRequest:" << std::endl;
152 ss << " Position: " << DifferentialRequest.Position.to<double>() << " rotations" << std::endl;
153 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << " rotations per second" << std::endl;
154 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
155 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << " fractional" << std::endl;
156 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
157 ss << " OverrideBrakeDurNeutral: " << DifferentialRequest.OverrideBrakeDurNeutral << std::endl;
158 ss << " LimitForwardMotion: " << DifferentialRequest.LimitForwardMotion << std::endl;
159 ss << " LimitReverseMotion: " << DifferentialRequest.LimitReverseMotion << std::endl;
160 ss << " IgnoreHardwareLimits: " << DifferentialRequest.IgnoreHardwareLimits << std::endl;
161 ss << " UseTimesync: " << DifferentialRequest.UseTimesync << std::endl;
162 return ss.str();
163 }
164
165 /**
166 * \brief Gets information about this control request.
167 *
168 * \returns Map of control parameter names and corresponding applied values
169 */
170 std::map<std::string, std::string> GetControlInfo() const override
171 {
172 std::map<std::string, std::string> controlInfo;
173 std::stringstream ss;
174 controlInfo["Name"] = GetName();
175 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
176 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
177 return controlInfo;
178 }
179};
180
181}
182}
183}
184}
185
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_PositionDutyCycle_Position(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_Position, double DifferentialRequest_Velocity, bool DifferentialRequest_EnableFOC, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideBrakeDurNeutral, bool DifferentialRequest_LimitForwardMotion, bool DifferentialRequest_LimitReverseMotion, bool DifferentialRequest_IgnoreHardwareLimits, bool DifferentialRequest_UseTimesync)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Request PID to target position with duty cycle feedforward.
Definition PositionDutyCycle.hpp:30
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
std::string ToString() const override
Returns a string representation of the object.
Definition PositionDutyCycle.hpp:379
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition PositionDutyCycle.hpp:110
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15