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