Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 23.10.0-alpha-8
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 bool ApplyConfigsOnRequest{false};
29
30 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, bool cancelOtherRequests, std::shared_ptr<ControlRequest> &req) override
31 {
32 if (req.get() != this)
33 {
34 auto const reqCast = dynamic_cast<CoastOut *>(req.get());
35 if (reqCast != nullptr)
36 {
37 *reqCast = *this;
38 }
39 else
40 {
41 req = std::make_shared<CoastOut>(*this);
42 }
43 }
44
45 std::stringstream ss;
46
47 std::string strs{ss.str()};
48 c_ctre_phoenix6_requestConfigApply(network, deviceHash, ConfigTimeout.to<double>(), strs.c_str(), strs.length(), ApplyConfigsOnRequest);
49 ApplyConfigsOnRequest = false;
50 return c_ctre_phoenix6_RequestControlCoastOut(network, deviceHash, UpdateFreqHz.to<double>(), cancelOtherRequests);
51 }
52
53public:
54
55
56
57
58 /**
59 * \brief The timeout when sending configs associated with this control
60 */
61 units::time::second_t ConfigTimeout{0.1_s};
62
63 /**
64 * \brief The period at which this control will update at.
65 * This is designated in Hertz, with a minimum of 20 Hz
66 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
67 *
68 * If this field is set to 0 Hz, the control request will
69 * be sent immediately as a one-shot frame. This may be useful
70 * for advanced applications that require outputs to be
71 * synchronized with data acquisition. In this case, we
72 * recommend not exceeding 50 ms between control calls.
73 */
74 units::frequency::hertz_t UpdateFreqHz{20_Hz}; // Default to 20_Hz
75
76 /**
77 * \brief Request coast neutral output of actuator. The bridge is disabled and
78 * the rotor is allowed to coast.
79 *
80 */
81 CoastOut() : ControlRequest{"CoastOut"}
82 {}
83
84 /**
85 * \brief Sets the period at which this control will update at.
86 * This is designated in Hertz, with a minimum of 20 Hz
87 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
88 *
89 * If this field is set to 0 Hz, the control request will
90 * be sent immediately as a one-shot frame. This may be useful
91 * for advanced applications that require outputs to be
92 * synchronized with data acquisition. In this case, we
93 * recommend not exceeding 50 ms between control calls.
94 *
95 * \param newUpdateFreqHz Parameter to modify
96 * \returns Itself
97 */
98 CoastOut &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
99 {
100 UpdateFreqHz = newUpdateFreqHz;
101 return *this;
102 }
103 /**
104 * Returns a string representation of the object.
105 *
106 * \returns a string representation of the object.
107 */
108 std::string ToString() const override
109 {
110 std::stringstream ss;
111 ss << "class: CoastOut" << std::endl;
112
113 return ss.str();
114 }
115
116 /**
117 * \brief Forces configs to be applied the next time this is used in a setControl.
118 * This is not necessary in the majority of cases, because Phoenix will make sure configs are
119 * properly set when they are not already set
120 */
121 void ForceApplyConfigs() { ApplyConfigsOnRequest = true; }
122
123 /**
124 * \brief Gets information about this control request.
125 *
126 * \returns Map of control parameter names and corresponding applied values
127 */
128 std::map<std::string, std::string> GetControlInfo() const override
129 {
130 std::map<std::string, std::string> controlInfo;
131 std::stringstream ss;
132 controlInfo["Name"] = GetName();
133
134 return controlInfo;
135 }
136};
137
138}
139}
140}
141
CTREXPORT int c_ctre_phoenix6_RequestControlCoastOut(const char *canbus, uint32_t ecuEncoding, double updateTime, bool cancelOtherRequests)
CTREXPORT int c_ctre_phoenix6_requestConfigApply(const char *canbus, uint32_t ecuEncoding, double timeoutSeconds, const char *str, uint32_t strlen, bool forceApply)
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:108
units::time::second_t ConfigTimeout
The timeout when sending configs associated with this control.
Definition: CoastOut.hpp:61
void ForceApplyConfigs()
Forces configs to be applied the next time this is used in a setControl.
Definition: CoastOut.hpp:121
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition: CoastOut.hpp:128
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: CoastOut.hpp:74
CoastOut & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: CoastOut.hpp:98
CoastOut()
Request coast neutral output of actuator.
Definition: CoastOut.hpp:81
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: ManualEvent.hpp:12