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