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