CTRE Phoenix 6 C++ 25.3.1
Loading...
Searching...
No Matches
Diff_VelocityTorqueCurrentFOC_Velocity.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 velocity average target and velocity difference
26 * target using torque current control.
27 */
28class Diff_VelocityTorqueCurrentFOC_Velocity : 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_VelocityTorqueCurrentFOC_Velocity *>(req.get());
35 if (reqCast != nullptr)
36 {
37 *reqCast = *this;
38 }
39 else
40 {
41 req = std::make_shared<Diff_VelocityTorqueCurrentFOC_Velocity>(*this);
42 }
43 }
44
45 return c_ctre_phoenix6_RequestControlDiff_VelocityTorqueCurrentFOC_Velocity(network, deviceHash, UpdateFreqHz.to<double>(), AverageRequest.Velocity.to<double>(), AverageRequest.Acceleration.to<double>(), AverageRequest.FeedForward.to<double>(), AverageRequest.Slot, AverageRequest.OverrideCoastDurNeutral, AverageRequest.LimitForwardMotion, AverageRequest.LimitReverseMotion, AverageRequest.IgnoreHardwareLimits, AverageRequest.UseTimesync, DifferentialRequest.Velocity.to<double>(), DifferentialRequest.Acceleration.to<double>(), DifferentialRequest.FeedForward.to<double>(), DifferentialRequest.Slot, DifferentialRequest.OverrideCoastDurNeutral, DifferentialRequest.LimitForwardMotion, DifferentialRequest.LimitReverseMotion, DifferentialRequest.IgnoreHardwareLimits, DifferentialRequest.UseTimesync);
46 }
47
48public:
49 /**
50 * \brief Average VelocityTorqueCurrentFOC request of the mechanism.
51 */
52 VelocityTorqueCurrentFOC AverageRequest;
53 /**
54 * \brief Differential VelocityTorqueCurrentFOC request of the mechanism.
55 */
56 VelocityTorqueCurrentFOC 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 velocity average target and velocity
74 * difference target using torque current control.
75 *
76 * \param AverageRequest Average VelocityTorqueCurrentFOC request of the
77 * mechanism.
78 * \param DifferentialRequest Differential VelocityTorqueCurrentFOC request
79 * of the mechanism.
80 */
81 Diff_VelocityTorqueCurrentFOC_Velocity(VelocityTorqueCurrentFOC AverageRequest, VelocityTorqueCurrentFOC DifferentialRequest) : ControlRequest{"Diff_VelocityTorqueCurrentFOC_Velocity"},
82 AverageRequest{std::move(AverageRequest)},
83 DifferentialRequest{std::move(DifferentialRequest)}
84 {}
85
86 /**
87 * \brief Modifies this Control Request's AverageRequest parameter and returns itself for
88 * method-chaining and easier to use request API.
89 *
90 * Average VelocityTorqueCurrentFOC request of the mechanism.
91 *
92 * \param newAverageRequest Parameter to modify
93 * \returns Itself
94 */
95 Diff_VelocityTorqueCurrentFOC_Velocity &WithAverageRequest(VelocityTorqueCurrentFOC newAverageRequest)
96 {
97 AverageRequest = std::move(newAverageRequest);
98 return *this;
99 }
100
101 /**
102 * \brief Modifies this Control Request's DifferentialRequest parameter and returns itself for
103 * method-chaining and easier to use request API.
104 *
105 * Differential VelocityTorqueCurrentFOC request of the mechanism.
106 *
107 * \param newDifferentialRequest Parameter to modify
108 * \returns Itself
109 */
110 Diff_VelocityTorqueCurrentFOC_Velocity &WithDifferentialRequest(VelocityTorqueCurrentFOC newDifferentialRequest)
111 {
112 DifferentialRequest = std::move(newDifferentialRequest);
113 return *this;
114 }
115 /**
116 * \brief Sets the period at which this control will update at.
117 * This is designated in Hertz, with a minimum of 20 Hz
118 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
119 *
120 * If this field is set to 0 Hz, the control request will
121 * be sent immediately as a one-shot frame. This may be useful
122 * for advanced applications that require outputs to be
123 * synchronized with data acquisition. In this case, we
124 * recommend not exceeding 50 ms between control calls.
125 *
126 * \param newUpdateFreqHz Parameter to modify
127 * \returns Itself
128 */
129 Diff_VelocityTorqueCurrentFOC_Velocity &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
130 {
131 UpdateFreqHz = newUpdateFreqHz;
132 return *this;
133 }
134 /**
135 * \brief Returns a string representation of the object.
136 *
137 * \returns a string representation of the object.
138 */
139 std::string ToString() const override
140 {
141 std::stringstream ss;
142 ss << "Control: Diff_VelocityTorqueCurrentFOC_Velocity" << std::endl;
143 ss << " AverageRequest:" << std::endl;
144 ss << " Velocity: " << AverageRequest.Velocity.to<double>() << " rotations per second" << std::endl;
145 ss << " Acceleration: " << AverageRequest.Acceleration.to<double>() << " rotations per second²" << std::endl;
146 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << " A" << std::endl;
147 ss << " Slot: " << AverageRequest.Slot << std::endl;
148 ss << " OverrideCoastDurNeutral: " << AverageRequest.OverrideCoastDurNeutral << 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 << " Velocity: " << DifferentialRequest.Velocity.to<double>() << " rotations per second" << std::endl;
155 ss << " Acceleration: " << DifferentialRequest.Acceleration.to<double>() << " rotations per second²" << std::endl;
156 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << " A" << std::endl;
157 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
158 ss << " OverrideCoastDurNeutral: " << DifferentialRequest.OverrideCoastDurNeutral << 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_VelocityTorqueCurrentFOC_Velocity(const char *canbus, uint32_t ecuEncoding, double updateTime, double AverageRequest_Velocity, double AverageRequest_Acceleration, double AverageRequest_FeedForward, int AverageRequest_Slot, bool AverageRequest_OverrideCoastDurNeutral, bool AverageRequest_LimitForwardMotion, bool AverageRequest_LimitReverseMotion, bool AverageRequest_IgnoreHardwareLimits, bool AverageRequest_UseTimesync, double DifferentialRequest_Velocity, double DifferentialRequest_Acceleration, 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
units::angular_acceleration::turns_per_second_squared_t Acceleration
Acceleration to drive toward in rotations per second squared.
Definition VelocityTorqueCurrentFOC.hpp:65
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition VelocityTorqueCurrentFOC.hpp:111
bool OverrideCoastDurNeutral
Set to true to coast the rotor when output is zero (or within deadband).
Definition VelocityTorqueCurrentFOC.hpp:86
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition VelocityTorqueCurrentFOC.hpp:57
units::current::ampere_t FeedForward
Feedforward to apply in torque current in Amperes.
Definition VelocityTorqueCurrentFOC.hpp:73
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition VelocityTorqueCurrentFOC.hpp:122
int Slot
Select which gains are applied by selecting the slot.
Definition VelocityTorqueCurrentFOC.hpp:79
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition VelocityTorqueCurrentFOC.hpp:98
bool LimitForwardMotion
Set to true to force forward limiting.
Definition VelocityTorqueCurrentFOC.hpp:92
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition MotionMagicExpoTorqueCurrentFOC.hpp:18
Definition span.hpp:401