ControllerWrapper.h
Go to the documentation of this file.
1/**
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2022
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24// #include <optional>
25// #include <type_traits>
28
30#include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
31#include <armarx/control/memory/config/Writer.h>
32
33// #include <armarx/control/common/type.h>
34// #include <armarx/control/memory/constants.h>
35
37{
38
39 namespace detail
40 {
41 /**
42 * @brief The base class for the ControllerWrapper which allows the private implementation to be in the .cpp file.
43 */
45 {
46 public:
47 using ControllerPrx = armarx::control::ConfigurableNJointControllerInterfacePrx;
48
50
51 /**
52 * @brief Constructor for the ControllerWrapperBase class.
53 * @param controller The controller object.
54 * @param controllerName The name of the controller.
55 * @param controllerTypeName The type name of the controller.
56 * @param configWriter The configuration writer object.
57 */
59 const std::string& controllerName,
60 const std::string& controllerTypeName,
61 const memory::config::Writer& configWriter);
62
63 /**
64 * @brief Destructor for the ControllerWrapperBase class. When invoked, the controller is deactivated and deleted unless being daemonized.
65 */
67
68 /**
69 * @brief Requests the activation of the controller in the RobotUnit.
70 */
71 void activate();
72
73 /**
74 * @brief Check the status of the controller.
75 */
76 bool isActive();
77
78 /**
79 * @brief Requests the deactivation of the controller in the RobotUnit.
80 */
81 void deactivate();
82
83 /**
84 * @brief Sets whether the controller should be daemonized.
85 * @param daemonize Flag indicating whether to daemonize the controller.
86 */
87 void daemonize(bool daemonize = true);
88
89 /**
90 * @brief Returns the "raw" controller object.
91 * @return The controller object.
92 */
94
95 protected:
96 /**
97 * @brief Updates the configuration of the controller.
98 *
99 * This update is two-fold:
100 * 1. The configuration is sent to the controller in the RobotUnit.
101 * 2. The configuration is written to the memory (via the the configuration writer).
102 *
103 * @param config The configuration object.
104 */
105 void
107
108
109 private:
110 ControllerPrx controller_; ///< The controller object.
111 const std::string controllerName_; ///< The name of the controller.
112 const std::string controllerTypeName_; ///< The type name of the controller.
113 memory::config::Writer configWriter_; ///< The configuration writer object.
114 bool daemonized_ = false; ///< Flag indicating whether the controller is daemonized.
115 };
116
117 } // namespace detail
118
119 /**
120 * @brief Wrapper class for an NJointController proxy.
121 *
122 * This class provides a wrapper for a controller, allowing easy access and life-cicle management.
123 * It holds the controller configuration which can be modified and updated accordingly.
124 *
125 * @tparam T The type of the controller description.
126 */
127 template <auto T>
129 {
130 public:
132 using AronConfigT = typename ControllerDescriptionType::AronDTO;
133
134 static_assert(not std::is_void<typename ControllerDescriptionType::AronDTO>::value,
135 "You must provide a ControllerDescription!");
136
138
139 // The class must be instantiated properly.
141
144
145 /**
146 * @brief Constructor for ControllerWrapper.
147 *
148 * @param controller The NJointController controller proxy.
149 * @param controllerName The name of the controller.
150 * @param configWriter The configuration writer used to store the controller configs in the memory.
151 * @param config The initial configuration for the controller.
152 */
154 const std::string& controllerName,
155 const memory::config::Writer& configWriter,
158 controllerName,
159 std::string(ControllerDescriptionType::name),
160 configWriter),
162 {
163 }
164
166 static_assert(::armarx::aron::cpp::isAronGeneratedClass<AronConfigT>,
167 "The AronConfigT must be an AronGeneratedClass!");
168
169 /**
170 * @brief Updates the configuration of the controller.
171 */
172 void
177
180 {
182 auto cfg = ctrl()->getConfig();
183 return AronConfigT::FromAron(cfg);
184 }
185 };
186
187} // namespace armarx::control::client
typename ControllerDescriptionType::AronDTO AronConfigT
ControllerWrapper(const ControllerWrapper &)=delete
void updateConfig()
Updates the configuration of the controller.
ControllerWrapper & operator=(ControllerWrapper const &)=delete
ControllerDescription< T > ControllerDescriptionType
ControllerWrapper(const ControllerPrx &controller, const std::string &controllerName, const memory::config::Writer &configWriter, AronConfigT config)
Constructor for ControllerWrapper.
The base class for the ControllerWrapper which allows the private implementation to be in the ....
void updateConfig(const armarx::aron::codegenerator::cpp::AronGeneratedObjectBase &config)
Updates the configuration of the controller.
void activate()
Requests the activation of the controller in the RobotUnit.
void deactivate()
Requests the deactivation of the controller in the RobotUnit.
ControllerPrx & ctrl()
Returns the "raw" controller object.
bool isActive()
Check the status of the controller.
armarx::control::ConfigurableNJointControllerInterfacePrx ControllerPrx
void daemonize(bool daemonize=true)
Sets whether the controller should be daemonized.
~ControllerWrapperBase()
Destructor for the ControllerWrapperBase class.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
aron::cpp::AronGeneratedObjectBase AronGeneratedObjectBase
This file is part of ArmarX.
This file is part of ArmarX.