CTRE Phoenix 6 C++ 24.3.0
Diff_VelocityVoltage_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
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 velocity average target and velocity difference
27 * target using voltage control.
28 */
29class Diff_VelocityVoltage_Velocity : 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_VelocityVoltage_Velocity *>(req.get());
36 if (reqCast != nullptr)
37 {
38 *reqCast = *this;
39 }
40 else
41 {
42 req = std::make_shared<Diff_VelocityVoltage_Velocity>(*this);
43 }
44 }
45
46 return c_ctre_phoenix6_RequestControlDiff_VelocityVoltage_Velocity(network, deviceHash, UpdateFreqHz.to<double>(), cancelOtherRequests, AverageRequest.Velocity.to<double>(), AverageRequest.Acceleration.to<double>(), AverageRequest.EnableFOC, AverageRequest.FeedForward.to<double>(), AverageRequest.Slot, AverageRequest.OverrideBrakeDurNeutral, AverageRequest.LimitForwardMotion, AverageRequest.LimitReverseMotion, DifferentialRequest.Velocity.to<double>(), DifferentialRequest.Acceleration.to<double>(), DifferentialRequest.EnableFOC, DifferentialRequest.FeedForward.to<double>(), DifferentialRequest.Slot, DifferentialRequest.OverrideBrakeDurNeutral, DifferentialRequest.LimitForwardMotion, DifferentialRequest.LimitReverseMotion);
47 }
48
49public:
50 /**
51 * Average VelocityVoltage request of the mechanism.
52 */
53 VelocityVoltage AverageRequest;
54 /**
55 * Differential VelocityVoltage request of the mechanism.
56 */
57 VelocityVoltage 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 velocity average target and velocity
75 * difference target using voltage control.
76 *
77 * \param AverageRequest Average VelocityVoltage request of the mechanism.
78 * \param DifferentialRequest Differential VelocityVoltage request of the
79 * mechanism.
80 */
81 Diff_VelocityVoltage_Velocity(VelocityVoltage AverageRequest, VelocityVoltage DifferentialRequest) : ControlRequest{"Diff_VelocityVoltage_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 VelocityVoltage request of the mechanism.
91 *
92 * \param newAverageRequest Parameter to modify
93 * \returns Itself
94 */
95 Diff_VelocityVoltage_Velocity& WithAverageRequest(VelocityVoltage 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 VelocityVoltage request of the mechanism.
106 *
107 * \param newDifferentialRequest Parameter to modify
108 * \returns Itself
109 */
110 Diff_VelocityVoltage_Velocity& WithDifferentialRequest(VelocityVoltage 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_VelocityVoltage_Velocity &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
130 {
131 UpdateFreqHz = newUpdateFreqHz;
132 return *this;
133 }
134 /**
135 * 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 << "class: Diff_VelocityVoltage_Velocity" << std::endl;
143 ss << "AverageRequest:" << std::endl;
144 ss << " Velocity: " << AverageRequest.Velocity.to<double>() << std::endl;
145 ss << " Acceleration: " << AverageRequest.Acceleration.to<double>() << std::endl;
146 ss << " EnableFOC: " << AverageRequest.EnableFOC << std::endl;
147 ss << " FeedForward: " << AverageRequest.FeedForward.to<double>() << std::endl;
148 ss << " Slot: " << AverageRequest.Slot << std::endl;
149 ss << " OverrideBrakeDurNeutral: " << AverageRequest.OverrideBrakeDurNeutral << std::endl;
150 ss << " LimitForwardMotion: " << AverageRequest.LimitForwardMotion << std::endl;
151 ss << " LimitReverseMotion: " << AverageRequest.LimitReverseMotion << std::endl;
152 ss << "DifferentialRequest:" << std::endl;
153 ss << " Velocity: " << DifferentialRequest.Velocity.to<double>() << std::endl;
154 ss << " Acceleration: " << DifferentialRequest.Acceleration.to<double>() << std::endl;
155 ss << " EnableFOC: " << DifferentialRequest.EnableFOC << std::endl;
156 ss << " FeedForward: " << DifferentialRequest.FeedForward.to<double>() << 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 return ss.str();
162 }
163
164 /**
165 * \brief Gets information about this control request.
166 *
167 * \returns Map of control parameter names and corresponding applied values
168 */
169 std::map<std::string, std::string> GetControlInfo() const override
170 {
171 std::map<std::string, std::string> controlInfo;
172 std::stringstream ss;
173 controlInfo["Name"] = GetName();
174 ss << AverageRequest.ToString(); controlInfo["AverageRequest"] = ss.str(); ss.str(std::string{});
175 ss << DifferentialRequest.ToString(); controlInfo["DifferentialRequest"] = ss.str(); ss.str(std::string{});
176 return controlInfo;
177 }
178};
179
180}
181}
182}
183}
184
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_VelocityVoltage_Velocity(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests, double AverageRequest_Velocity, double AverageRequest_Acceleration, bool AverageRequest_EnableFOC, double AverageRequest_FeedForward, int AverageRequest_Slot, bool AverageRequest_OverrideBrakeDurNeutral, bool AverageRequest_LimitForwardMotion, bool AverageRequest_LimitReverseMotion, double DifferentialRequest_Velocity, double DifferentialRequest_Acceleration, bool DifferentialRequest_EnableFOC, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideBrakeDurNeutral, bool DifferentialRequest_LimitForwardMotion, bool DifferentialRequest_LimitReverseMotion)
std::string const & GetName() const
Definition: ControlRequest.hpp:51
ControlRequest(ControlRequest const &)=default
Definition: string_util.hpp:15