CTRE Phoenix Pro C++ 23.0.12
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 phoenixpro {
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 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<CoastOut *>(req.get());
38 if (reqCast != nullptr)
39 {
40 *reqCast = *this;
41 }
42 else
43 {
44 req = std::make_shared<CoastOut>(*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_RequestControlCoastOut(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 coast neutral output of actuator. The bridge is disabled
80 * and the rotor is allowed to coast.
81 *
82 */
83 CoastOut() : ControlRequest{"CoastOut"}, 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 CoastOut &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: CoastOut" << 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_RequestControlCoastOut(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests)
Request coast neutral output of actuator.
Definition: CoastOut.hpp:27
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: CoastOut.hpp:76
CoastOut & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: CoastOut.hpp:102
units::time::second_t ConfigTimeout
The timeout when sending configs associated with this control.
Definition: CoastOut.hpp:63
void ForceApplyConfigs()
Forces configs to be applied the next time this is used in a setControl.
Definition: CoastOut.hpp:125
std::string ToString() const
Returns a string representation of the object.
Definition: CoastOut.hpp:112
CoastOut()
Request coast neutral output of actuator.
Definition: CoastOut.hpp:83
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:65
Definition: string_util.hpp:14