CTRE Phoenix 6 C++ 25.3.0
Loading...
Searching...
No Matches
MusicTone.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#include <units/frequency.h>
13#include <units/frequency.h>
14#include <units/time.h>
15
16
17namespace ctre {
18namespace phoenix6 {
19namespace controls {
20
21/**
22 * Plays a single tone at the user specified frequency.
23 */
25{
26 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
27 {
28 if (req.get() != this)
29 {
30 auto const reqCast = dynamic_cast<MusicTone *>(req.get());
31 if (reqCast != nullptr)
32 {
33 *reqCast = *this;
34 }
35 else
36 {
37 req = std::make_shared<MusicTone>(*this);
38 }
39 }
40
41 return c_ctre_phoenix6_RequestControlMusicTone(network, deviceHash, UpdateFreqHz.to<double>(), AudioFrequency.to<double>());
42 }
43
44public:
45 /**
46 * \brief Sound frequency to play. A value of zero will silence the device. The
47 * effective frequency range is 10-20000 Hz. Any nonzero frequency less than 10
48 * Hz will be capped to 10 Hz. Any frequency above 20 kHz will be capped to 20
49 * kHz.
50 *
51 * - Units: Hz
52 *
53 */
54 units::frequency::hertz_t AudioFrequency;
55
56 /**
57 * \brief The period at which this control will update at.
58 * This is designated in Hertz, with a minimum of 20 Hz
59 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
60 *
61 * If this field is set to 0 Hz, the control request will
62 * be sent immediately as a one-shot frame. This may be useful
63 * for advanced applications that require outputs to be
64 * synchronized with data acquisition. In this case, we
65 * recommend not exceeding 50 ms between control calls.
66 */
67 units::frequency::hertz_t UpdateFreqHz{100_Hz};
68
69 /**
70 * \brief Plays a single tone at the user specified frequency.
71 *
72 * \param AudioFrequency Sound frequency to play. A value of zero will
73 * silence the device. The effective frequency range is
74 * 10-20000 Hz. Any nonzero frequency less than 10 Hz
75 * will be capped to 10 Hz. Any frequency above 20 kHz
76 * will be capped to 20 kHz.
77 */
78 MusicTone(units::frequency::hertz_t AudioFrequency) : ControlRequest{"MusicTone"},
80 {}
81
82 /**
83 * \brief Modifies this Control Request's AudioFrequency parameter and returns itself for
84 * method-chaining and easier to use request API.
85 *
86 * Sound frequency to play. A value of zero will silence the device. The
87 * effective frequency range is 10-20000 Hz. Any nonzero frequency less than 10
88 * Hz will be capped to 10 Hz. Any frequency above 20 kHz will be capped to 20
89 * kHz.
90 *
91 * - Units: Hz
92 *
93 *
94 * \param newAudioFrequency Parameter to modify
95 * \returns Itself
96 */
97 MusicTone &WithAudioFrequency(units::frequency::hertz_t newAudioFrequency)
98 {
99 AudioFrequency = std::move(newAudioFrequency);
100 return *this;
101 }
102 /**
103 * \brief Sets the period at which this control will update at.
104 * This is designated in Hertz, with a minimum of 20 Hz
105 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
106 *
107 * If this field is set to 0 Hz, the control request will
108 * be sent immediately as a one-shot frame. This may be useful
109 * for advanced applications that require outputs to be
110 * synchronized with data acquisition. In this case, we
111 * recommend not exceeding 50 ms between control calls.
112 *
113 * \param newUpdateFreqHz Parameter to modify
114 * \returns Itself
115 */
116 MusicTone &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
117 {
118 UpdateFreqHz = newUpdateFreqHz;
119 return *this;
120 }
121 /**
122 * \brief Returns a string representation of the object.
123 *
124 * \returns a string representation of the object.
125 */
126 std::string ToString() const override
127 {
128 std::stringstream ss;
129 ss << "Control: MusicTone" << std::endl;
130 ss << " AudioFrequency: " << AudioFrequency.to<double>() << " Hz" << std::endl;
131 return ss.str();
132 }
133
134 /**
135 * \brief Gets information about this control request.
136 *
137 * \returns Map of control parameter names and corresponding applied values
138 */
139 std::map<std::string, std::string> GetControlInfo() const override
140 {
141 std::map<std::string, std::string> controlInfo;
142 std::stringstream ss;
143 controlInfo["Name"] = GetName();
144 ss << AudioFrequency.to<double>(); controlInfo["AudioFrequency"] = ss.str(); ss.str(std::string{});
145 return controlInfo;
146 }
147};
148
149}
150}
151}
152
CTREXPORT int c_ctre_phoenix6_RequestControlMusicTone(const char *canbus, uint32_t ecuEncoding, double updateTime, double AudioFrequency)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Plays a single tone at the user specified frequency.
Definition MusicTone.hpp:25
MusicTone & WithAudioFrequency(units::frequency::hertz_t newAudioFrequency)
Modifies this Control Request's AudioFrequency parameter and returns itself for method-chaining and e...
Definition MusicTone.hpp:97
MusicTone & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition MusicTone.hpp:116
units::frequency::hertz_t AudioFrequency
Sound frequency to play.
Definition MusicTone.hpp:54
MusicTone(units::frequency::hertz_t AudioFrequency)
Plays a single tone at the user specified frequency.
Definition MusicTone.hpp:78
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition MusicTone.hpp:139
std::string ToString() const override
Returns a string representation of the object.
Definition MusicTone.hpp:126
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition MusicTone.hpp:67
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition MotionMagicExpoTorqueCurrentFOC.hpp:18
Definition span.hpp:401