CTRE Phoenix 6 C++ 25.2.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
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::frequency::hertz_t AudioFrequency;
52
53 /**
54 * \brief The period at which this control will update at.
55 * This is designated in Hertz, with a minimum of 20 Hz
56 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
57 *
58 * If this field is set to 0 Hz, the control request will
59 * be sent immediately as a one-shot frame. This may be useful
60 * for advanced applications that require outputs to be
61 * synchronized with data acquisition. In this case, we
62 * recommend not exceeding 50 ms between control calls.
63 */
64 units::frequency::hertz_t UpdateFreqHz{100_Hz};
65
66 /**
67 * \brief Plays a single tone at the user specified frequency.
68 *
69 * \param AudioFrequency Sound frequency to play. A value of zero will
70 * silence the device. The effective frequency range is
71 * 10-20000 Hz. Any nonzero frequency less than 10 Hz
72 * will be capped to 10 Hz. Any frequency above 20 kHz
73 * will be capped to 20 kHz.
74 */
75 MusicTone(units::frequency::hertz_t AudioFrequency) : ControlRequest{"MusicTone"},
77 {}
78
79 /**
80 * \brief Modifies this Control Request's AudioFrequency parameter and returns itself for
81 * method-chaining and easier to use request API.
82 *
83 * Sound frequency to play. A value of zero will silence the device. The
84 * effective frequency range is 10-20000 Hz. Any nonzero frequency less than 10
85 * Hz will be capped to 10 Hz. Any frequency above 20 kHz will be capped to 20
86 * kHz.
87 *
88 * \param newAudioFrequency Parameter to modify
89 * \returns Itself
90 */
91 MusicTone &WithAudioFrequency(units::frequency::hertz_t newAudioFrequency)
92 {
93 AudioFrequency = std::move(newAudioFrequency);
94 return *this;
95 }
96 /**
97 * \brief Sets the period at which this control will update at.
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 *
101 * If this field is set to 0 Hz, the control request will
102 * be sent immediately as a one-shot frame. This may be useful
103 * for advanced applications that require outputs to be
104 * synchronized with data acquisition. In this case, we
105 * recommend not exceeding 50 ms between control calls.
106 *
107 * \param newUpdateFreqHz Parameter to modify
108 * \returns Itself
109 */
110 MusicTone &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
111 {
112 UpdateFreqHz = newUpdateFreqHz;
113 return *this;
114 }
115 /**
116 * \brief Returns a string representation of the object.
117 *
118 * \returns a string representation of the object.
119 */
120 std::string ToString() const override
121 {
122 std::stringstream ss;
123 ss << "Control: MusicTone" << std::endl;
124 ss << " AudioFrequency: " << AudioFrequency.to<double>() << " Hz" << std::endl;
125 return ss.str();
126 }
127
128 /**
129 * \brief Gets information about this control request.
130 *
131 * \returns Map of control parameter names and corresponding applied values
132 */
133 std::map<std::string, std::string> GetControlInfo() const override
134 {
135 std::map<std::string, std::string> controlInfo;
136 std::stringstream ss;
137 controlInfo["Name"] = GetName();
138 ss << AudioFrequency.to<double>(); controlInfo["AudioFrequency"] = ss.str(); ss.str(std::string{});
139 return controlInfo;
140 }
141};
142
143}
144}
145}
146
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:91
MusicTone & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition MusicTone.hpp:110
units::frequency::hertz_t AudioFrequency
Sound frequency to play.
Definition MusicTone.hpp:51
MusicTone(units::frequency::hertz_t AudioFrequency)
Plays a single tone at the user specified frequency.
Definition MusicTone.hpp:75
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition MusicTone.hpp:133
std::string ToString() const override
Returns a string representation of the object.
Definition MusicTone.hpp:120
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition MusicTone.hpp:64
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition MotionMagicExpoTorqueCurrentFOC.hpp:18
Definition span.hpp:401