CTRE Phoenix Pro C++ 23.0.12
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 phoenixpro {
20namespace controls {
21
22/**
23 * Request neutral output of actuator. The applied brake type is determined by
24 * the NeutralMode configuration.
25 */
27{
28 bool ApplyConfigsOnRequest;
29
30 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req)
31 {
32 std::stringstream ss;
33
34
35 if (req.get() != this)
36 {
37 auto const reqCast = dynamic_cast<NeutralOut *>(req.get());
38 if (reqCast != nullptr)
39 {
40 *reqCast = *this;
41 }
42 else
43 {
44 req = std::make_shared<NeutralOut>(*this);
45 }
46 }
47
48
49 std::string strs{ss.str()};
50 c_ctre_phoenixpro_requestConfigApply(network, deviceHash, ConfigTimeout.to<double>(), strs.c_str(), strs.length(), ApplyConfigsOnRequest);
51 ApplyConfigsOnRequest = false;
52 return c_ctre_phoenixpro_RequestControlNeutralOut(network, deviceHash, UpdateFreqHz.to<double>(), cancelOtherRequests);
53 }
54
55public:
56
57
58
59
60 /**
61 * \brief The timeout when sending configs associated with this control
62 */
63 units::time::second_t ConfigTimeout{0.1_s};
64
65 /**
66 * \brief The period at which this control will update at.
67 * This is designated in Hertz, with a minimum of 20 Hz
68 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
69 *
70 * If this field is set to 0 Hz, the control request will
71 * be sent immediately as a one-shot frame. This may be useful
72 * for advanced applications that require outputs to be
73 * synchronized with data acquisition. In this case, we
74 * recommend not exceeding 50 ms between control calls.
75 */
76 units::frequency::hertz_t UpdateFreqHz{100_Hz}; // Default to 100_Hz
77
78 /**
79 *\brief Request neutral output of actuator. The applied brake type is
80 * determined by the NeutralMode configuration.
81 *
82 */
83 NeutralOut() : ControlRequest{"NeutralOut"}, ApplyConfigsOnRequest{false}
84 {
85
86 }
87
88 /**
89 * \brief Sets the period at which this control will update at.
90 * This is designated in Hertz, with a minimum of 20 Hz
91 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
92 *
93 * If this field is set to 0 Hz, the control request will
94 * be sent immediately as a one-shot frame. This may be useful
95 * for advanced applications that require outputs to be
96 * synchronized with data acquisition. In this case, we
97 * recommend not exceeding 50 ms between control calls.
98 *
99 * \param newUpdateFreqHz Parameter to modify
100 * \returns Itself
101 */
102 NeutralOut &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
103 {
104 UpdateFreqHz = newUpdateFreqHz;
105 return *this;
106 }
107 /**
108 * Returns a string representation of the object.
109 *
110 * \returns a string representation of the object.
111 */
112 std::string ToString() const
113 {
114 std::stringstream ss;
115 ss << "class: NeutralOut" << std::endl;
116
117 return ss.str();
118 }
119
120 /**
121 * \brief Forces configs to be applied the next time this is used in a setControl.
122 * This is not necessary in the majority of cases, because Phoenix will make sure configs are
123 * properly set when they are not already set
124 */
125 void ForceApplyConfigs() { ApplyConfigsOnRequest = true; }
126};
127
128}
129}
130}
131
CTREXPORT int c_ctre_phoenixpro_requestConfigApply(const char *canbus, uint32_t ecuEncoding, double timeoutSeconds, const char *str, uint32_t strlen, bool forceApply)
CTREXPORT int c_ctre_phoenixpro_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:65
Request neutral output of actuator.
Definition: NeutralOut.hpp:27
units::time::second_t ConfigTimeout
The timeout when sending configs associated with this control.
Definition: NeutralOut.hpp:63
NeutralOut & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: NeutralOut.hpp:102
std::string ToString() const
Returns a string representation of the object.
Definition: NeutralOut.hpp:112
NeutralOut()
Request neutral output of actuator.
Definition: NeutralOut.hpp:83
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: NeutralOut.hpp:76
void ForceApplyConfigs()
Forces configs to be applied the next time this is used in a setControl.
Definition: NeutralOut.hpp:125
Definition: string_util.hpp:14