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