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