Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Diff_TorqueCurrentFOC_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 torque current average target and position
25 * difference target.
26 */
27class Diff_TorqueCurrentFOC_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_TorqueCurrentFOC_Position *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<Diff_TorqueCurrentFOC_Position>(*this);
41 }
42 }
43
44 return c_ctre_phoenix6_RequestControlDiff_TorqueCurrentFOC_Position(network, deviceHash, UpdateFreqHz.to<double>(), AverageRequest.Output.to<double>(), AverageRequest.MaxAbsDutyCycle.to<double>(), AverageRequest.Deadband.to<double>(), AverageRequest.OverrideCoastDurNeutral, AverageRequest.LimitForwardMotion, AverageRequest.LimitReverseMotion, AverageRequest.IgnoreHardwareLimits, AverageRequest.UseTimesync, DifferentialRequest.Position.to<double>(), DifferentialRequest.Velocity.to<double>(), DifferentialRequest.FeedForward.to<double>(), DifferentialRequest.Slot, DifferentialRequest.OverrideCoastDurNeutral, DifferentialRequest.LimitForwardMotion, DifferentialRequest.LimitReverseMotion, DifferentialRequest.IgnoreHardwareLimits, DifferentialRequest.UseTimesync);
45 }
46
47public:
48 /**
49 * \brief Average TorqueCurrentFOC request of the mechanism.
50 */
51 TorqueCurrentFOC AverageRequest;
52 /**
53 * \brief Differential PositionTorqueCurrentFOC request of the mechanism.
54 */
55 PositionTorqueCurrentFOC 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 torque current average target and position
73 * difference target.
74 *
75 * \param AverageRequest Average TorqueCurrentFOC request of the mechanism.
76 * \param DifferentialRequest Differential PositionTorqueCurrentFOC request
77 * of the mechanism.
78 */
79 Diff_TorqueCurrentFOC_Position(TorqueCurrentFOC AverageRequest, PositionTorqueCurrentFOC DifferentialRequest) : ControlRequest{"Diff_TorqueCurrentFOC_Position"},
80 AverageRequest{std::move(AverageRequest)},
81 DifferentialRequest{std::move(DifferentialRequest)}
82 {}
83
84 /**
85 * \brief Modifies this Control Request's AverageRequest parameter and returns itself for
86 * method-chaining and easier to use request API.
87 *
88 * Average TorqueCurrentFOC request of the mechanism.
89 *
90 * \param newAverageRequest Parameter to modify
91 * \returns Itself
92 */
93 Diff_TorqueCurrentFOC_Position &WithAverageRequest(TorqueCurrentFOC 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 *
103 * Differential PositionTorqueCurrentFOC request of the mechanism.
104 *
105 * \param newDifferentialRequest Parameter to modify
106 * \returns Itself
107 */
108 Diff_TorqueCurrentFOC_Position &WithDifferentialRequest(PositionTorqueCurrentFOC newDifferentialRequest)
109 {
110 DifferentialRequest = std::move(newDifferentialRequest);
111 return *this;
112 }
113 /**
114 * \brief Sets the period at which this control will update at.
115 * This is designated in Hertz, with a minimum of 20 Hz
116 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
117 *
118 * If this field is set to 0 Hz, the control request will
119 * be sent immediately as a one-shot frame. This may be useful
120 * for advanced applications that require outputs to be
121 * synchronized with data acquisition. In this case, we
122 * recommend not exceeding 50 ms between control calls.
123 *
124 * \param newUpdateFreqHz Parameter to modify
125 * \returns Itself
126 */
127 Diff_TorqueCurrentFOC_Position &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
128 {
129 UpdateFreqHz = newUpdateFreqHz;
130 return *this;
131 }
132 /**
133 * \brief Returns a string representation of the object.
134 *
135 * \returns a string representation of the object.
136 */
137 std::string ToString() const override
138 {
139 std::stringstream ss;
140 ss << "Control: Diff_TorqueCurrentFOC_Position" << std::endl;
141 ss << " AverageRequest:" << std::endl;
142 ss << " Output: " << AverageRequest.Output.to<double>() << " A" << std::endl;
143 ss << " MaxAbsDutyCycle: " << AverageRequest.MaxAbsDutyCycle.to<double>() << " fractional" << std::endl;
144 ss << " Deadband: " << AverageRequest.Deadband.to<double>() << " A" << std::endl;
145 ss << " OverrideCoastDurNeutral: " << AverageRequest.OverrideCoastDurNeutral << std::endl;
146 ss << " LimitForwardMotion: " << AverageRequest.LimitForwardMotion << std::endl;
147 ss << " LimitReverseMotion: " << AverageRequest.LimitReverseMotion << std::endl;
148 ss << " IgnoreHardwareLimits: " << AverageRequest.IgnoreHardwareLimits << std::endl;
149 ss << " UseTimesync: " << AverageRequest.UseTimesync << std::endl;
150 ss << " DifferentialRequest:" << std::endl;
151 ss << " Position: " << DifferentialRequest.Position.to<double>() << " rotations" << std::endl;
152 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << " rotations per second" << std::endl;
153 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << " A" << std::endl;
154 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
155 ss << " OverrideCoastDurNeutral: " << DifferentialRequest.OverrideCoastDurNeutral << std::endl;
156 ss << " LimitForwardMotion: " << DifferentialRequest.LimitForwardMotion << std::endl;
157 ss << " LimitReverseMotion: " << DifferentialRequest.LimitReverseMotion << std::endl;
158 ss << " IgnoreHardwareLimits: " << DifferentialRequest.IgnoreHardwareLimits << std::endl;
159 ss << " UseTimesync: " << DifferentialRequest.UseTimesync << std::endl;
160 return ss.str();
161 }
162
163 /**
164 * \brief Gets information about this control request.
165 *
166 * \returns Map of control parameter names and corresponding applied values
167 */
168 std::map<std::string, std::string> GetControlInfo() const override
169 {
170 std::map<std::string, std::string> controlInfo;
171 std::stringstream ss;
172 controlInfo["Name"] = GetName();
173 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
174 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
175 return controlInfo;
176 }
177};
178
179}
180}
181}
182}
183
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_TorqueCurrentFOC_Position(const char *canbus, uint32_t ecuEncoding, double updateTime, double AverageRequest_Output, double AverageRequest_MaxAbsDutyCycle, double AverageRequest_Deadband, bool AverageRequest_OverrideCoastDurNeutral, bool AverageRequest_LimitForwardMotion, bool AverageRequest_LimitReverseMotion, bool AverageRequest_IgnoreHardwareLimits, bool AverageRequest_UseTimesync, double DifferentialRequest_Position, double DifferentialRequest_Velocity, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideCoastDurNeutral, 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 PositionTorqueCurrentFOC.hpp:79
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition PositionTorqueCurrentFOC.hpp:65
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition PositionTorqueCurrentFOC.hpp:122
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition PositionTorqueCurrentFOC.hpp:111
units::angle::turn_t Position
Position to drive toward in rotations.
Definition PositionTorqueCurrentFOC.hpp:57
units::current::ampere_t FeedForward
Feedforward to apply in torque current in Amperes.
Definition PositionTorqueCurrentFOC.hpp:73
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition PositionTorqueCurrentFOC.hpp:98
bool LimitForwardMotion
Set to true to force forward limiting.
Definition PositionTorqueCurrentFOC.hpp:92
bool OverrideCoastDurNeutral
Set to true to coast the rotor when output is zero (or within deadband).
Definition PositionTorqueCurrentFOC.hpp:86
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition TorqueCurrentFOC.hpp:114
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition TorqueCurrentFOC.hpp:125
units::current::ampere_t Output
Amount of motor current in Amperes.
Definition TorqueCurrentFOC.hpp:57
bool OverrideCoastDurNeutral
Set to true to coast the rotor when output is zero (or within deadband).
Definition TorqueCurrentFOC.hpp:89
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition TorqueCurrentFOC.hpp:101
units::current::ampere_t Deadband
Deadband in Amperes.
Definition TorqueCurrentFOC.hpp:82
bool LimitForwardMotion
Set to true to force forward limiting.
Definition TorqueCurrentFOC.hpp:95
units::dimensionless::scalar_t MaxAbsDutyCycle
The maximum absolute motor output that can be applied, which effectively limits the velocity.
Definition TorqueCurrentFOC.hpp:69
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401