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