CTRE Phoenix 6 C++ 24.2.0
Diff_PositionTorqueCurrentFOC_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>
14#include <units/frequency.h>
15#include <units/time.h>
16
17
18namespace ctre {
19namespace phoenix6 {
20namespace controls {
21namespace compound {
22
23/**
24 * \private
25 * Requires Phoenix Pro and CANivore;
26 * Differential control with position average target and position difference
27 * target using torque current control.
28 */
29class Diff_PositionTorqueCurrentFOC_Position : public ControlRequest
30{
31 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req) override
32 {
33 if (req.get() != this)
34 {
35 auto const reqCast = dynamic_cast<Diff_PositionTorqueCurrentFOC_Position *>(req.get());
36 if (reqCast != nullptr)
37 {
38 *reqCast = *this;
39 }
40 else
41 {
42 req = std::make_shared<Diff_PositionTorqueCurrentFOC_Position>(*this);
43 }
44 }
45
46 return c_ctre_phoenix6_RequestControlDiff_PositionTorqueCurrentFOC_Position(network, deviceHash, UpdateFreqHz.to<double>(), cancelOtherRequests, AverageRequest.Position.to<double>(), AverageRequest.Velocity.to<double>(), AverageRequest.FeedForward.to<double>(), AverageRequest.Slot, AverageRequest.OverrideCoastDurNeutral, AverageRequest.LimitForwardMotion, AverageRequest.LimitReverseMotion, DifferentialRequest.Position.to<double>(), DifferentialRequest.Velocity.to<double>(), DifferentialRequest.FeedForward.to<double>(), DifferentialRequest.Slot, DifferentialRequest.OverrideCoastDurNeutral, DifferentialRequest.LimitForwardMotion, DifferentialRequest.LimitReverseMotion);
47 }
48
49public:
50 /**
51 * Average PositionTorqueCurrentFOC request of the mechanism.
52 */
53 PositionTorqueCurrentFOC AverageRequest;
54 /**
55 * Differential PositionTorqueCurrentFOC request of the mechanism.
56 */
57 PositionTorqueCurrentFOC DifferentialRequest;
58
59 /**
60 * \brief The period at which this control will update at.
61 * This is designated in Hertz, with a minimum of 20 Hz
62 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
63 *
64 * If this field is set to 0 Hz, the control request will
65 * be sent immediately as a one-shot frame. This may be useful
66 * for advanced applications that require outputs to be
67 * synchronized with data acquisition. In this case, we
68 * recommend not exceeding 50 ms between control calls.
69 */
70 units::frequency::hertz_t UpdateFreqHz{100_Hz}; // Default to 100_Hz
71
72 /**
73 * \brief Requires Phoenix Pro and CANivore;
74 * Differential control with position
75 * average target and position difference target using torque current
76 * control.
77 *
78 * \param AverageRequest Average PositionTorqueCurrentFOC request of the
79 * mechanism.
80 * \param DifferentialRequest Differential PositionTorqueCurrentFOC request
81 * of the mechanism.
82 */
83 Diff_PositionTorqueCurrentFOC_Position(PositionTorqueCurrentFOC AverageRequest, PositionTorqueCurrentFOC DifferentialRequest) : ControlRequest{"Diff_PositionTorqueCurrentFOC_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 * \param newAverageRequest Parameter to modify
92 * \returns Itself
93 */
94 Diff_PositionTorqueCurrentFOC_Position& WithAverageRequest(PositionTorqueCurrentFOC 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 * \param newDifferentialRequest Parameter to modify
104 * \returns Itself
105 */
106 Diff_PositionTorqueCurrentFOC_Position& WithDifferentialRequest(PositionTorqueCurrentFOC newDifferentialRequest)
107 {
108 DifferentialRequest = std::move(newDifferentialRequest);
109 return *this;
110 }
111 /**
112 * \brief Sets the period at which this control will update at.
113 * This is designated in Hertz, with a minimum of 20 Hz
114 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
115 *
116 * If this field is set to 0 Hz, the control request will
117 * be sent immediately as a one-shot frame. This may be useful
118 * for advanced applications that require outputs to be
119 * synchronized with data acquisition. In this case, we
120 * recommend not exceeding 50 ms between control calls.
121 *
122 * \param newUpdateFreqHz Parameter to modify
123 * \returns Itself
124 */
125 Diff_PositionTorqueCurrentFOC_Position &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
126 {
127 UpdateFreqHz = newUpdateFreqHz;
128 return *this;
129 }
130 /**
131 * Returns a string representation of the object.
132 *
133 * \returns a string representation of the object.
134 */
135 std::string ToString() const override
136 {
137 std::stringstream ss;
138 ss << "class: Diff_PositionTorqueCurrentFOC_Position" << std::endl;
139 ss << "AverageRequest:" << std::endl;
140 ss << " Position: " << AverageRequest.Position.to<double>() << std::endl;
141 ss << " Velocity: " << AverageRequest.Velocity.to<double>() << std::endl;
142 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << std::endl;
143 ss << " Slot: " << AverageRequest.Slot << std::endl;
144 ss << " OverrideCoastDurNeutral: " << AverageRequest.OverrideCoastDurNeutral << std::endl;
145 ss << " LimitForwardMotion: " << AverageRequest.LimitForwardMotion << std::endl;
146 ss << " LimitReverseMotion: " << AverageRequest.LimitReverseMotion << std::endl;
147 ss << "DifferentialRequest:" << std::endl;
148 ss << " Position: " << DifferentialRequest.Position.to<double>() << std::endl;
149 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << std::endl;
150 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << std::endl;
151 ss << " Slot: " << DifferentialRequest.Slot << std::endl;
152 ss << " OverrideCoastDurNeutral: " << DifferentialRequest.OverrideCoastDurNeutral << std::endl;
153 ss << " LimitForwardMotion: " << DifferentialRequest.LimitForwardMotion << std::endl;
154 ss << " LimitReverseMotion: " << DifferentialRequest.LimitReverseMotion << std::endl;
155 return ss.str();
156 }
157
158 /**
159 * \brief Gets information about this control request.
160 *
161 * \returns Map of control parameter names and corresponding applied values
162 */
163 std::map<std::string, std::string> GetControlInfo() const override
164 {
165 std::map<std::string, std::string> controlInfo;
166 std::stringstream ss;
167 controlInfo["Name"] = GetName();
168 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
169 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
170 return controlInfo;
171 }
172};
173
174}
175}
176}
177}
178
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_PositionTorqueCurrentFOC_Position(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests, double AverageRequest_Position, double AverageRequest_Velocity, double AverageRequest_FeedForward, int AverageRequest_Slot, bool AverageRequest_OverrideCoastDurNeutral, bool AverageRequest_LimitForwardMotion, bool AverageRequest_LimitReverseMotion, double DifferentialRequest_Position, double DifferentialRequest_Velocity, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideCoastDurNeutral, bool DifferentialRequest_LimitForwardMotion, bool DifferentialRequest_LimitReverseMotion)
std::string const & GetName() const
Definition: ControlRequest.hpp:51
ControlRequest(ControlRequest const &)=default
Definition: RcManualEvent.hpp:12