CTRE Phoenix 6 C++ 25.2.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
11#include <units/frequency.h>
12#include <map>
13#include <memory>
14#include <sstream>
15#include <string>
16
17namespace ctre {
18namespace phoenix6 {
19
20namespace hardware {
21 class ParentDevice;
22}
23
24namespace controls {
25
26 /**
27 * \brief Abstract Control Request class that other control requests extend for use.
28 */
30 {
32 virtual ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const = 0;
33
34 protected:
35 std::string name;
36
37 /* don't allow copy and move of the base class, only derived classes */
38 ControlRequest(ControlRequest const &) = default;
42
43 public:
44 /**
45 * \brief Constructs a new Control Request with the given name.
46 *
47 * \param name Name of the control request
48 */
49 ControlRequest(std::string name) : name{std::move(name)}
50 {
51 }
52
53 std::string const &GetName() const
54 {
55 return name;
56 }
57
58 /**
59 * \brief Gets information about this control request.
60 *
61 * \returns Map of control parameter names and corresponding applied values
62 */
63 virtual std::map<std::string, std::string> GetControlInfo() const = 0;
64
65 virtual ~ControlRequest() = default;
66 virtual std::string ToString() const = 0;
67 };
68
69 /**
70 * \brief Generic Empty Control class used to do nothing.
71 */
73 {
74 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
75 {
76 if (req.get() != this)
77 {
78 auto const reqCast = dynamic_cast<EmptyControl *>(req.get());
79 if (reqCast != nullptr)
80 {
81 *reqCast = *this;
82 }
83 else
84 {
85 req = std::make_shared<EmptyControl>(*this);
86 }
87 }
88
89 return c_ctre_phoenix6_RequestControlEmpty(network, deviceHash, 0);
90 }
91
92 public:
93 /**
94 * \brief Constructs an empty control request.
95 */
96 EmptyControl() : ControlRequest{"EmptyControl"}
97 {
98 }
99
100 /**
101 * \brief Gets information about this control request.
102 *
103 * \returns Map of control parameter names and corresponding applied values
104 */
105 std::map<std::string, std::string> GetControlInfo() const override
106 {
107 std::map<std::string, std::string> controlInfo;
108 controlInfo["Name"] = GetName();
109 return controlInfo;
110 }
111
112 std::string ToString() const override
113 {
114 std::stringstream ss;
115 ss << "class: EmptyControl" << std::endl;
116 return ss.str();
117 }
118
119 EmptyControl &WithUpdateFreqHz(units::frequency::hertz_t) { return *this; }
120 };
121
122}
123
124}
125}
CTREXPORT int c_ctre_phoenix6_RequestControlEmpty(const char *canbus, uint32_t ecuEncoding, double updateTime)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
ControlRequest & operator=(ControlRequest &&)=default
ControlRequest & operator=(ControlRequest const &)=default
std::string name
Definition ControlRequest.hpp:35
std::string const & GetName() const
Definition ControlRequest.hpp:53
ControlRequest(ControlRequest const &)=default
virtual std::map< std::string, std::string > GetControlInfo() const =0
Gets information about this control request.
ControlRequest(ControlRequest &&)=default
virtual std::string ToString() const =0
ControlRequest(std::string name)
Constructs a new Control Request with the given name.
Definition ControlRequest.hpp:49
Generic Empty Control class used to do nothing.
Definition ControlRequest.hpp:73
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition ControlRequest.hpp:105
EmptyControl & WithUpdateFreqHz(units::frequency::hertz_t)
Definition ControlRequest.hpp:119
EmptyControl()
Constructs an empty control request.
Definition ControlRequest.hpp:96
std::string ToString() const override
Definition ControlRequest.hpp:112
Parent class for all devices.
Definition ParentDevice.hpp:28
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition MotionMagicExpoTorqueCurrentFOC.hpp:18
Definition span.hpp:401