CTRE Phoenix 6 C++ 24.3.0
NeutralOut.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 neutral output of actuator. The applied brake type is determined by
24 * the NeutralMode configuration.
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<NeutralOut *>(req.get());
33 if (reqCast != nullptr)
34 {
35 *reqCast = *this;
36 }
37 else
38 {
39 req = std::make_shared<NeutralOut>(*this);
40 }
41 }
42
43 return c_ctre_phoenix6_RequestControlNeutralOut(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 neutral output of actuator. The applied brake type is
64 * determined by the NeutralMode configuration.
65 *
66 */
67 NeutralOut() : ControlRequest{"NeutralOut"}
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 NeutralOut &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: NeutralOut" << 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_RequestControlNeutralOut(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests)
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
std::string const & GetName() const
Definition: ControlRequest.hpp:51
Request neutral output of actuator.
Definition: NeutralOut.hpp:27
NeutralOut & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: NeutralOut.hpp:84
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition: NeutralOut.hpp:107
NeutralOut()
Request neutral output of actuator.
Definition: NeutralOut.hpp:67
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: NeutralOut.hpp:60
std::string ToString() const override
Returns a string representation of the object.
Definition: NeutralOut.hpp:94
Definition: string_util.hpp:15