CTRE Phoenix 6 C++ 24.2.0
Diff_VelocityDutyCycle_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>
15#include <units/frequency.h>
16#include <units/time.h>
17
18
19namespace ctre {
20namespace phoenix6 {
21namespace controls {
22namespace compound {
23
24/**
25 * \private
26 * Requires Phoenix Pro and CANivore;
27 * Differential control with velocity average target and position difference
28 * target using dutycycle control.
29 */
30class Diff_VelocityDutyCycle_Position : public ControlRequest
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_VelocityDutyCycle_Position *>(req.get());
37 if (reqCast != nullptr)
38 {
39 *reqCast = *this;
40 }
41 else
42 {
43 req = std::make_shared<Diff_VelocityDutyCycle_Position>(*this);
44 }
45 }
46
47 return c_ctre_phoenix6_RequestControlDiff_VelocityDutyCycle_Position(network, deviceHash, UpdateFreqHz.to<double>(), cancelOtherRequests, AverageRequest.Velocity.to<double>(), AverageRequest.Acceleration.to<double>(), AverageRequest.EnableFOC, AverageRequest.FeedForward.to<double>(), AverageRequest.Slot, AverageRequest.OverrideBrakeDurNeutral, AverageRequest.LimitForwardMotion, AverageRequest.LimitReverseMotion, DifferentialRequest.Position.to<double>(), DifferentialRequest.Velocity.to<double>(), DifferentialRequest.EnableFOC, DifferentialRequest.FeedForward.to<double>(), DifferentialRequest.Slot, DifferentialRequest.OverrideBrakeDurNeutral, DifferentialRequest.LimitForwardMotion, DifferentialRequest.LimitReverseMotion);
48 }
49
50public:
51 /**
52 * Average VelocityDutyCYcle request of the mechanism.
53 */
54 VelocityDutyCycle AverageRequest;
55 /**
56 * Differential PositionDutyCycle request of the mechanism.
57 */
58 PositionDutyCycle DifferentialRequest;
59
60 /**
61 * \brief The period at which this control will update at.
62 * This is designated in Hertz, with a minimum of 20 Hz
63 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
64 *
65 * If this field is set to 0 Hz, the control request will
66 * be sent immediately as a one-shot frame. This may be useful
67 * for advanced applications that require outputs to be
68 * synchronized with data acquisition. In this case, we
69 * recommend not exceeding 50 ms between control calls.
70 */
71 units::frequency::hertz_t UpdateFreqHz{100_Hz}; // Default to 100_Hz
72
73 /**
74 * \brief Requires Phoenix Pro and CANivore;
75 * Differential control with velocity
76 * average target and position difference target using dutycycle control.
77 *
78 * \param AverageRequest Average VelocityDutyCYcle request of the mechanism.
79 * \param DifferentialRequest Differential PositionDutyCycle request of the
80 * mechanism.
81 */
82 Diff_VelocityDutyCycle_Position(VelocityDutyCycle AverageRequest, PositionDutyCycle DifferentialRequest) : ControlRequest{"Diff_VelocityDutyCycle_Position"},
83 AverageRequest{std::move(AverageRequest)},
84 DifferentialRequest{std::move(DifferentialRequest)}
85 {}
86
87 /**
88 * \brief Modifies this Control Request's AverageRequest parameter and returns itself for
89 * method-chaining and easier to use request API.
90 * \param newAverageRequest Parameter to modify
91 * \returns Itself
92 */
93 Diff_VelocityDutyCycle_Position& WithAverageRequest(VelocityDutyCycle newAverageRequest)
94 {
95 AverageRequest = std::move(newAverageRequest);
96 return *this;
97 }
98
99 /**
100 * \brief Modifies this Control Request's DifferentialRequest parameter and returns itself for
101 * method-chaining and easier to use request API.
102 * \param newDifferentialRequest Parameter to modify
103 * \returns Itself
104 */
105 Diff_VelocityDutyCycle_Position& WithDifferentialRequest(PositionDutyCycle newDifferentialRequest)
106 {
107 DifferentialRequest = std::move(newDifferentialRequest);
108 return *this;
109 }
110 /**
111 * \brief Sets the period at which this control will update at.
112 * This is designated in Hertz, with a minimum of 20 Hz
113 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
114 *
115 * If this field is set to 0 Hz, the control request will
116 * be sent immediately as a one-shot frame. This may be useful
117 * for advanced applications that require outputs to be
118 * synchronized with data acquisition. In this case, we
119 * recommend not exceeding 50 ms between control calls.
120 *
121 * \param newUpdateFreqHz Parameter to modify
122 * \returns Itself
123 */
124 Diff_VelocityDutyCycle_Position &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
125 {
126 UpdateFreqHz = newUpdateFreqHz;
127 return *this;
128 }
129 /**
130 * Returns a string representation of the object.
131 *
132 * \returns a string representation of the object.
133 */
134 std::string ToString() const override
135 {
136 std::stringstream ss;
137 ss << "class: Diff_VelocityDutyCycle_Position" << std::endl;
138 ss << "AverageRequest:" << std::endl;
139 ss << " Velocity: " << AverageRequest.Velocity.to<double>() << std::endl;
140 ss << " Acceleration: " << AverageRequest.Acceleration.to<double>() << std::endl;
141 ss << " EnableFOC: " << AverageRequest.EnableFOC << std::endl;
142 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << std::endl;
143 ss << " Slot: " << AverageRequest.Slot << std::endl;
144 ss << " OverrideBrakeDurNeutral: " << AverageRequest.OverrideBrakeDurNeutral << std::endl;
145 ss << " LimitForwardMotion: " << AverageRequest.LimitForwardMotion << std::endl;
146 ss << " LimitReverseMotion: " << AverageRequest.LimitReverseMotion << std::endl;
147 ss << "DifferentialRequest:" << std::endl;
148 ss << " Position: " << DifferentialRequest.Position.to<double>() << std::endl;
149 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << std::endl;
150 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
151 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << std::endl;
152 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
153 ss << " OverrideBrakeDurNeutral: " << DifferentialRequest.OverrideBrakeDurNeutral << std::endl;
154 ss << " LimitForwardMotion: " << DifferentialRequest.LimitForwardMotion << std::endl;
155 ss << " LimitReverseMotion: " << DifferentialRequest.LimitReverseMotion << std::endl;
156 return ss.str();
157 }
158
159 /**
160 * \brief Gets information about this control request.
161 *
162 * \returns Map of control parameter names and corresponding applied values
163 */
164 std::map<std::string, std::string> GetControlInfo() const override
165 {
166 std::map<std::string, std::string> controlInfo;
167 std::stringstream ss;
168 controlInfo["Name"] = GetName();
169 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
170 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
171 return controlInfo;
172 }
173};
174
175}
176}
177}
178}
179
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_VelocityDutyCycle_Position(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, bool AverageRequest_LimitForwardMotion, bool AverageRequest_LimitReverseMotion, double DifferentialRequest_Position, double DifferentialRequest_Velocity, bool DifferentialRequest_EnableFOC, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideBrakeDurNeutral, bool DifferentialRequest_LimitForwardMotion, bool DifferentialRequest_LimitReverseMotion)
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
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:74
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:70
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:93
int Slot
Select which gains are applied by selecting the slot.
Definition: PositionDutyCycle.hpp:80
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition: PositionDutyCycle.hpp:87
std::string ToString() const override
Returns a string representation of the object.
Definition: PositionDutyCycle.hpp:290
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition: PositionDutyCycle.hpp:99
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:80
units::angular_acceleration::turns_per_second_squared_t Acceleration
Acceleration to drive toward in rotations per second squared.
Definition: VelocityDutyCycle.hpp:59
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition: VelocityDutyCycle.hpp:87
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition: VelocityDutyCycle.hpp:54
units::dimensionless::scalar_t FeedForward
Feedforward to apply in fractional units between -1 and +1.
Definition: VelocityDutyCycle.hpp:74
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%.
Definition: VelocityDutyCycle.hpp:70
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition: VelocityDutyCycle.hpp:99
std::string ToString() const override
Returns a string representation of the object.
Definition: VelocityDutyCycle.hpp:290
bool LimitForwardMotion
Set to true to force forward limiting.
Definition: VelocityDutyCycle.hpp:93
Definition: RcManualEvent.hpp:12