Loading [MathJax]/jax/output/HTML-CSS/config.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModulateVBatOut.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
11#include <sstream>
12
13#include <units/frequency.h>
14#include <units/time.h>
15#include <units/dimensionless.h>
16
17namespace ctre {
18namespace phoenix6 {
19namespace controls {
20
21/**
22 * Modulates the CANdle VBat output to the specified duty cycle. This can be
23 * used to control a single-color LED strip.
24 *
25 * Note that configs::CANdleFeaturesConfigs::VBatOutputMode must be set to
26 * signals::VBatOutputModeValue::Modulated.
27 *
28 *
29 */
31{
32 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
33 {
34 if (req.get() != this)
35 {
36 auto const reqCast = dynamic_cast<ModulateVBatOut *>(req.get());
37 if (reqCast != nullptr)
38 {
39 *reqCast = *this;
40 }
41 else
42 {
43 req = std::make_shared<ModulateVBatOut>(*this);
44 }
45 }
46
47 return c_ctre_phoenix6_RequestControlModulateVBatOut(network, deviceHash, UpdateFreqHz.to<double>(), Output.to<double>());
48 }
49
50public:
51 /**
52 * \brief Proportion of VBat to output in fractional units between 0.0 and 1.0.
53 *
54 * - Units: fractional
55 *
56 */
57 units::dimensionless::scalar_t Output;
58
59 /**
60 * \brief The period at which this control will update at.
61 * This is designated in Hertz, with a minimum of 20 Hz
62 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
63 *
64 * If this field is set to 0 Hz, the control request will
65 * be sent immediately as a one-shot frame. This may be useful
66 * for advanced applications that require outputs to be
67 * synchronized with data acquisition. In this case, we
68 * recommend not exceeding 50 ms between control calls.
69 */
70 units::frequency::hertz_t UpdateFreqHz{50_Hz};
71
72 /**
73 * \brief Modulates the CANdle VBat output to the specified duty cycle. This can
74 * be used to control a single-color LED strip.
75 *
76 * Note that configs::CANdleFeaturesConfigs::VBatOutputMode must be set
77 * to signals::VBatOutputModeValue::Modulated.
78 *
79 * \details
80 *
81 * \param Output Proportion of VBat to output in fractional units between 0.0
82 * and 1.0.
83 */
84 ModulateVBatOut(units::dimensionless::scalar_t Output) : ControlRequest{"ModulateVBatOut"},
85 Output{std::move(Output)}
86 {}
87
88 /**
89 * \brief Modifies this Control Request's Output parameter and returns itself for
90 * method-chaining and easier to use request API.
91 *
92 * Proportion of VBat to output in fractional units between 0.0 and 1.0.
93 *
94 * - Units: fractional
95 *
96 *
97 * \param newOutput Parameter to modify
98 * \returns Itself
99 */
100 ModulateVBatOut &WithOutput(units::dimensionless::scalar_t newOutput)
101 {
102 Output = std::move(newOutput);
103 return *this;
104 }
105 /**
106 * \brief Sets the period at which this control will update at.
107 * This is designated in Hertz, with a minimum of 20 Hz
108 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
109 *
110 * If this field is set to 0 Hz, the control request will
111 * be sent immediately as a one-shot frame. This may be useful
112 * for advanced applications that require outputs to be
113 * synchronized with data acquisition. In this case, we
114 * recommend not exceeding 50 ms between control calls.
115 *
116 * \param newUpdateFreqHz Parameter to modify
117 * \returns Itself
118 */
119 ModulateVBatOut &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
120 {
121 UpdateFreqHz = newUpdateFreqHz;
122 return *this;
123 }
124 /**
125 * \brief Returns a string representation of the object.
126 *
127 * \returns a string representation of the object.
128 */
129 std::string ToString() const override
130 {
131 std::stringstream ss;
132 ss << "Control: ModulateVBatOut" << std::endl;
133 ss << " Output: " << Output.to<double>() << " fractional" << std::endl;
134 return ss.str();
135 }
136
137 /**
138 * \brief Gets information about this control request.
139 *
140 * \returns Map of control parameter names and corresponding applied values
141 */
142 std::map<std::string, std::string> GetControlInfo() const override
143 {
144 std::map<std::string, std::string> controlInfo;
145 std::stringstream ss;
146 controlInfo["Name"] = GetName();
147 ss << Output.to<double>(); controlInfo["Output"] = ss.str(); ss.str(std::string{});
148 return controlInfo;
149 }
150};
151
152}
153}
154}
155
CTREXPORT int c_ctre_phoenix6_RequestControlModulateVBatOut(const char *canbus, uint32_t ecuEncoding, double updateFrequency, double Output)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Modulates the CANdle VBat output to the specified duty cycle.
Definition ModulateVBatOut.hpp:31
units::dimensionless::scalar_t Output
Proportion of VBat to output in fractional units between 0.0 and 1.0.
Definition ModulateVBatOut.hpp:57
ModulateVBatOut(units::dimensionless::scalar_t Output)
Modulates the CANdle VBat output to the specified duty cycle.
Definition ModulateVBatOut.hpp:84
ModulateVBatOut & WithOutput(units::dimensionless::scalar_t newOutput)
Modifies this Control Request's Output parameter and returns itself for method-chaining and easier to...
Definition ModulateVBatOut.hpp:100
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition ModulateVBatOut.hpp:70
ModulateVBatOut & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition ModulateVBatOut.hpp:119
std::string ToString() const override
Returns a string representation of the object.
Definition ModulateVBatOut.hpp:129
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition ModulateVBatOut.hpp:142
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401