CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
ControlRequest.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 <map>
12#include <memory>
13#include <string>
14
15namespace ctre {
16namespace phoenix6 {
17
18namespace hardware {
19 class ParentDevice;
20}
21
22namespace controls {
23
24 /**
25 * \brief Common interface implemented by all control requests.
26 */
29 virtual ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const = 0;
30
31 protected:
32 /* don't allow copy and move of the base class, only derived classes */
33 constexpr ControlRequest(ControlRequest const &) = default;
34 constexpr ControlRequest(ControlRequest &&) = default;
35 constexpr ControlRequest &operator=(ControlRequest const &) = default;
36 constexpr ControlRequest &operator=(ControlRequest &&) = default;
37
38 public:
39 /**
40 * \brief Constructs a new Control Request.
41 */
42 constexpr ControlRequest() = default;
43 constexpr virtual ~ControlRequest() {}
44
45 /**
46 * \brief Gets the name of this control request.
47 *
48 * \returns Name of the control request
49 */
50 constexpr virtual std::string_view GetName() const = 0;
51
52 /**
53 * \brief Gets information about this control request.
54 *
55 * \returns Map of control parameter names and corresponding applied values
56 */
57 virtual std::map<std::string, std::string> GetControlInfo() const = 0;
58
59 virtual std::string ToString() const = 0;
60 };
61
62 /**
63 * \brief Generic Empty Control class used to do nothing.
64 */
65 class EmptyControl final : public ControlRequest {
66 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
67
68 public:
69 /**
70 * \brief Constructs an empty control request.
71 */
72 constexpr EmptyControl() = default;
73 constexpr ~EmptyControl() override {}
74
75 /**
76 * \brief Gets the name of this control request.
77 *
78 * \returns Name of the control request
79 */
80 constexpr std::string_view GetName() const override
81 {
82 return "EmptyControl";
83 }
84
85 std::string ToString() const override
86 {
87 return "class: EmptyControl";
88 }
89
90 /**
91 * \brief Gets information about this control request.
92 *
93 * \returns Map of control parameter names and corresponding applied values
94 */
95 std::map<std::string, std::string> GetControlInfo() const override;
96
97 constexpr EmptyControl &WithUpdateFreqHz(units::frequency::hertz_t) { return *this; }
98 };
99
100}
101
102}
103}
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
constexpr ControlRequest(ControlRequest &&)=default
constexpr ControlRequest()=default
Constructs a new Control Request.
virtual constexpr std::string_view GetName() const =0
Gets the name of this control request.
constexpr ControlRequest(ControlRequest const &)=default
virtual constexpr ~ControlRequest()
Definition ControlRequest.hpp:43
constexpr ControlRequest & operator=(ControlRequest &&)=default
constexpr ControlRequest & operator=(ControlRequest const &)=default
virtual std::map< std::string, std::string > GetControlInfo() const =0
Gets information about this control request.
virtual std::string ToString() const =0
Generic Empty Control class used to do nothing.
Definition ControlRequest.hpp:65
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
constexpr EmptyControl()=default
Constructs an empty control request.
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition ControlRequest.hpp:80
constexpr EmptyControl & WithUpdateFreqHz(units::frequency::hertz_t)
Definition ControlRequest.hpp:97
constexpr ~EmptyControl() override
Definition ControlRequest.hpp:73
std::string ToString() const override
Definition ControlRequest.hpp:85
Parent class for all devices.
Definition ParentDevice.hpp:23
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14