CTRE Phoenix 6 C++ 24.3.0
CoastOut.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>
13
14#include <units/frequency.h>
15#include <units/time.h>
16
17
18namespace ctre {
19namespace phoenix6 {
20namespace controls {
21
22/**
23 * Request coast neutral output of actuator. The bridge is disabled and the
24 * rotor is allowed to coast.
25 */
27{
28 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req) override
29 {
30 if (req.get() != this)
31 {
32 auto const reqCast = dynamic_cast<CoastOut *>(req.get());
33 if (reqCast != nullptr)
34 {
35 *reqCast = *this;
36 }
37 else
38 {
39 req = std::make_shared<CoastOut>(*this);
40 }
41 }
42
43 return c_ctre_phoenix6_RequestControlCoastOut(network, deviceHash, UpdateFreqHz.to<double>(), cancelOtherRequests);
44 }
45
46public:
47
48
49 /**
50 * \brief The period at which this control will update at.
51 * This is designated in Hertz, with a minimum of 20 Hz
52 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
53 *
54 * If this field is set to 0 Hz, the control request will
55 * be sent immediately as a one-shot frame. This may be useful
56 * for advanced applications that require outputs to be
57 * synchronized with data acquisition. In this case, we
58 * recommend not exceeding 50 ms between control calls.
59 */
60 units::frequency::hertz_t UpdateFreqHz{20_Hz}; // Default to 20_Hz
61
62 /**
63 * \brief Request coast neutral output of actuator. The bridge is disabled and
64 * the rotor is allowed to coast.
65 *
66 */
67 CoastOut() : ControlRequest{"CoastOut"}
68 {}
69
70 /**
71 * \brief Sets the period at which this control will update at.
72 * This is designated in Hertz, with a minimum of 20 Hz
73 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
74 *
75 * If this field is set to 0 Hz, the control request will
76 * be sent immediately as a one-shot frame. This may be useful
77 * for advanced applications that require outputs to be
78 * synchronized with data acquisition. In this case, we
79 * recommend not exceeding 50 ms between control calls.
80 *
81 * \param newUpdateFreqHz Parameter to modify
82 * \returns Itself
83 */
84 CoastOut &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
85 {
86 UpdateFreqHz = newUpdateFreqHz;
87 return *this;
88 }
89 /**
90 * Returns a string representation of the object.
91 *
92 * \returns a string representation of the object.
93 */
94 std::string ToString() const override
95 {
96 std::stringstream ss;
97 ss << "class: CoastOut" << std::endl;
98
99 return ss.str();
100 }
101
102 /**
103 * \brief Gets information about this control request.
104 *
105 * \returns Map of control parameter names and corresponding applied values
106 */
107 std::map<std::string, std::string> GetControlInfo() const override
108 {
109 std::map<std::string, std::string> controlInfo;
110 std::stringstream ss;
111 controlInfo["Name"] = GetName();
112
113 return controlInfo;
114 }
115};
116
117}
118}
119}
120
CTREXPORT int c_ctre_phoenix6_RequestControlCoastOut(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests)
Request coast neutral output of actuator.
Definition: CoastOut.hpp:27
std::string ToString() const override
Returns a string representation of the object.
Definition: CoastOut.hpp:94
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition: CoastOut.hpp:107
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: CoastOut.hpp:60
CoastOut & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: CoastOut.hpp:84
CoastOut()
Request coast neutral output of actuator.
Definition: CoastOut.hpp:67
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
std::string const & GetName() const
Definition: ControlRequest.hpp:51
Definition: string_util.hpp:15