Loading [MathJax]/extensions/MathZoom.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Diff_MotionMagicDutyCycle_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
15
16namespace ctre {
17namespace phoenix6 {
18namespace controls {
19namespace compound {
20
21/**
22 * \private
23 * Requires Phoenix Pro and CANivore;
24 * Differential control with Motion Magic® average target and position
25 * difference target using dutycycle control.
26 */
27class Diff_MotionMagicDutyCycle_Position : public ControlRequest
28{
29 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
30 {
31 if (req.get() != this)
32 {
33 auto const reqCast = dynamic_cast<Diff_MotionMagicDutyCycle_Position *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<Diff_MotionMagicDutyCycle_Position>(*this);
41 }
42 }
43
44 return c_ctre_phoenix6_RequestControlDiff_MotionMagicDutyCycle_Position(network, deviceHash, UpdateFreqHz.to<double>(), AverageRequest.Position.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);
45 }
46
47public:
48 /**
49 * \brief Average MotionMagicDutyCycle request of the mechanism.
50 */
51 MotionMagicDutyCycle AverageRequest;
52 /**
53 * \brief Differential PositionDutyCycle request of the mechanism.
54 */
55 PositionDutyCycle DifferentialRequest;
56
57 /**
58 * \brief The period at which this control will update at.
59 * This is designated in Hertz, with a minimum of 20 Hz
60 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
61 *
62 * If this field is set to 0 Hz, the control request will
63 * be sent immediately as a one-shot frame. This may be useful
64 * for advanced applications that require outputs to be
65 * synchronized with data acquisition. In this case, we
66 * recommend not exceeding 50 ms between control calls.
67 */
68 units::frequency::hertz_t UpdateFreqHz{100_Hz};
69
70 /**
71 * \brief Requires Phoenix Pro and CANivore;
72 * Differential control with Motion Magic® average target and position
73 * difference target using dutycycle control.
74 *
75 * \param AverageRequest Average MotionMagicDutyCycle request of the
76 * mechanism.
77 * \param DifferentialRequest Differential PositionDutyCycle request of the
78 * mechanism.
79 */
80 Diff_MotionMagicDutyCycle_Position(MotionMagicDutyCycle AverageRequest, PositionDutyCycle DifferentialRequest) : ControlRequest{"Diff_MotionMagicDutyCycle_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 MotionMagicDutyCycle request of the mechanism.
90 *
91 * \param newAverageRequest Parameter to modify
92 * \returns Itself
93 */
94 Diff_MotionMagicDutyCycle_Position &WithAverageRequest(MotionMagicDutyCycle 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_MotionMagicDutyCycle_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_MotionMagicDutyCycle_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_MotionMagicDutyCycle_Position" << std::endl;
142 ss << " AverageRequest:" << std::endl;
143 ss << " Position: " << AverageRequest.Position.to<double>() << " rotations" << std::endl;
144 ss << " EnableFOC: " << AverageRequest.EnableFOC << std::endl;
145 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << " fractional" << std::endl;
146 ss << " Slot: " << AverageRequest.Slot << std::endl;
147 ss << " OverrideBrakeDurNeutral: " << AverageRequest.OverrideBrakeDurNeutral << std::endl;
148 ss << " LimitForwardMotion: " << AverageRequest.LimitForwardMotion << std::endl;
149 ss << " LimitReverseMotion: " << AverageRequest.LimitReverseMotion << std::endl;
150 ss << " IgnoreHardwareLimits: " << AverageRequest.IgnoreHardwareLimits << std::endl;
151 ss << " UseTimesync: " << AverageRequest.UseTimesync << std::endl;
152 ss << " DifferentialRequest:" << std::endl;
153 ss << " Position: " << DifferentialRequest.Position.to<double>() << " rotations" << std::endl;
154 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << " rotations per second" << std::endl;
155 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
156 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << " fractional" << std::endl;
157 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
158 ss << " OverrideBrakeDurNeutral: " << DifferentialRequest.OverrideBrakeDurNeutral << std::endl;
159 ss << " LimitForwardMotion: " << DifferentialRequest.LimitForwardMotion << std::endl;
160 ss << " LimitReverseMotion: " << DifferentialRequest.LimitReverseMotion << std::endl;
161 ss << " IgnoreHardwareLimits: " << DifferentialRequest.IgnoreHardwareLimits << std::endl;
162 ss << " UseTimesync: " << DifferentialRequest.UseTimesync << std::endl;
163 return ss.str();
164 }
165
166 /**
167 * \brief Gets information about this control request.
168 *
169 * \returns Map of control parameter names and corresponding applied values
170 */
171 std::map<std::string, std::string> GetControlInfo() const override
172 {
173 std::map<std::string, std::string> controlInfo;
174 std::stringstream ss;
175 controlInfo["Name"] = GetName();
176 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
177 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
178 return controlInfo;
179 }
180};
181
182}
183}
184}
185}
186
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_MotionMagicDutyCycle_Position(const char *canbus, uint32_t ecuEncoding, double updateTime, double AverageRequest_Position, 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:53
ControlRequest(ControlRequest const &)=default
int Slot
Select which gains are applied by selecting the slot.
Definition MotionMagicDutyCycle.hpp:88
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition MotionMagicDutyCycle.hpp:95
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition MotionMagicDutyCycle.hpp:120
units::dimensionless::scalar_t FeedForward
Feedforward to apply in fractional units between -1 and +1.
Definition MotionMagicDutyCycle.hpp:82
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition MotionMagicDutyCycle.hpp:131
units::angle::turn_t Position
Position to drive toward in rotations.
Definition MotionMagicDutyCycle.hpp:61
bool LimitForwardMotion
Set to true to force forward limiting.
Definition MotionMagicDutyCycle.hpp:101
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15% on supp...
Definition MotionMagicDutyCycle.hpp:75
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition MotionMagicDutyCycle.hpp:107
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
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
Definition span.hpp:401