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 // #include <armarx/control/common/type.h>
33 // #include <armarx/control/memory/constants.h>
34 
36 {
37 
38  namespace detail
39  {
40  /**
41  * @brief The base class for the ControllerWrapper which allows the private implementation to be in the .cpp file.
42  */
44  {
45  public:
46  using ControllerPrx = armarx::control::ConfigurableNJointControllerInterfacePrx;
47 
48  ControllerWrapperBase() = delete;
49 
50  /**
51  * @brief Constructor for the ControllerWrapperBase class.
52  * @param controller The controller object.
53  * @param controllerName The name of the controller.
54  * @param controllerTypeName The type name of the controller.
55  * @param configWriter The configuration writer object.
56  */
58  const std::string& controllerName,
59  const std::string& controllerTypeName,
60  const memory::config::Writer& configWriter);
61 
62  /**
63  * @brief Destructor for the ControllerWrapperBase class. When invoked, the controller is deactivated and deleted unless being daemonized.
64  */
66 
67  /**
68  * @brief Requests the activation of the controller in the RobotUnit.
69  */
70  void activate();
71 
72  /**
73  * @brief Check the status of the controller.
74  */
75  bool isActive();
76 
77  /**
78  * @brief Requests the deactivation of the controller in the RobotUnit.
79  */
80  void deactivate();
81 
82  /**
83  * @brief Sets whether the controller should be daemonized.
84  * @param daemonize Flag indicating whether to daemonize the controller.
85  */
86  void daemonize(bool daemonize = true);
87 
88  /**
89  * @brief Returns the "raw" controller object.
90  * @return The controller object.
91  */
93 
94  protected:
95  /**
96  * @brief Updates the configuration of the controller.
97  *
98  * This update is two-fold:
99  * 1. The configuration is sent to the controller in the RobotUnit.
100  * 2. The configuration is written to the memory (via the the configuration writer).
101  *
102  * @param config The configuration object.
103  */
104  void
106 
107 
108  private:
109  ControllerPrx controller_; ///< The controller object.
110  const std::string controllerName_; ///< The name of the controller.
111  const std::string controllerTypeName_; ///< The type name of the controller.
112  memory::config::Writer configWriter_; ///< The configuration writer object.
113  bool daemonized_ = false; ///< Flag indicating whether the controller is daemonized.
114  };
115 
116  } // namespace detail
117 
118  /**
119  * @brief Wrapper class for an NJointController proxy.
120  *
121  * This class provides a wrapper for a controller, allowing easy access and life-cicle management.
122  * It holds the controller configuration which can be modified and updated accordingly.
123  *
124  * @tparam T The type of the controller description.
125  */
126  template <auto T>
128  {
129  public:
131  using AronConfigT = typename ControllerDescriptionType::AronDTO;
132 
134  "You must provide a ControllerDescription!");
135 
137 
138  // The class must be instantiated properly.
139  ControllerWrapper() = delete;
140 
141  ControllerWrapper(const ControllerWrapper&) = delete;
143 
144  /**
145  * @brief Constructor for ControllerWrapper.
146  *
147  * @param controller The NJointController controller proxy.
148  * @param controllerName The name of the controller.
149  * @param configWriter The configuration writer used to store the controller configs in the memory.
150  * @param config The initial configuration for the controller.
151  */
153  const std::string& controllerName,
154  const memory::config::Writer& configWriter,
157  controllerName,
158  std::string(ControllerDescriptionType::name),
159  configWriter),
160  config(config)
161  {
162  }
163 
165  static_assert(::armarx::aron::cpp::isAronGeneratedClass<AronConfigT>,
166  "The AronConfigT must be an AronGeneratedClass!");
167 
168  /**
169  * @brief Updates the configuration of the controller.
170  */
172  {
174  }
175 
177  {
179  auto cfg = ctrl()->getConfig();
180  return AronConfigT::FromAron(cfg);
181  }
182  };
183 
184 } // namespace armarx::control::client
armarx::control::client::detail::ControllerWrapperBase::ControllerWrapperBase
ControllerWrapperBase()=delete
AronGeneratedObject.h
armarx::control::client::ControllerWrapper::updateConfig
void updateConfig()
Updates the configuration of the controller.
Definition: ControllerWrapper.h:171
armarx::control::client::ControllerWrapper::AronConfigT
typename ControllerDescriptionType::AronDTO AronConfigT
Definition: ControllerWrapper.h:131
armarx::control::client::ControllerWrapper::config
AronConfigT config
Definition: ControllerWrapper.h:164
armarx::control::client::detail::ControllerWrapperBase::activate
void activate()
Requests the activation of the controller in the RobotUnit.
Definition: ControllerWrapper.cpp:58
armarx::control::client::detail::ControllerWrapperBase
The base class for the ControllerWrapper which allows the private implementation to be in the ....
Definition: ControllerWrapper.h:43
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::control::client
This file is part of ArmarX.
Definition: ComponentPlugin.cpp:20
detail
Definition: OpenCVUtil.cpp:127
armarx::control::client::detail::ControllerWrapperBase::ctrl
ControllerPrx & ctrl()
Returns the "raw" controller object.
Definition: ControllerWrapper.cpp:88
armarx::aron::cpp::AronGeneratedObjectBase
Definition: AronGeneratedObject.h:32
armarx::control::client::ControllerDescription
Definition: ControllerDescription.h:103
armarx::control::client::ControllerWrapper
Wrapper class for an NJointController proxy.
Definition: ControllerWrapper.h:127
armarx::control::client::detail::ControllerWrapperBase::~ControllerWrapperBase
~ControllerWrapperBase()
Destructor for the ControllerWrapperBase class.
Definition: ControllerWrapper.cpp:47
armarx::control::client::ControllerWrapper::operator=
ControllerWrapper & operator=(ControllerWrapper const &)=delete
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
controller
Definition: AddOperation.h:39
armarx::control::client::detail::ControllerWrapperBase::isActive
bool isActive()
Check the status of the controller.
Definition: ControllerWrapper.cpp:66
ControllerDescription.h
armarx::control::client::detail::ControllerWrapperBase::updateConfig
void updateConfig(const armarx::aron::codegenerator::cpp::AronGeneratedObjectBase &config)
Updates the configuration of the controller.
Definition: ControllerWrapper.cpp:95
armarx::control::client::ControllerWrapper::ControllerWrapper
ControllerWrapper()=delete
armarx::control::client::ControllerWrapper::getConfig
AronConfigT getConfig()
Definition: ControllerWrapper.h:176
armarx::control::client::ControllerWrapper::ControllerWrapper
ControllerWrapper(const ControllerPrx &controller, const std::string &controllerName, const memory::config::Writer &configWriter, AronConfigT config)
Constructor for ControllerWrapper.
Definition: ControllerWrapper.h:152
armarx::control::client::detail::ControllerWrapperBase::deactivate
void deactivate()
Requests the deactivation of the controller in the RobotUnit.
Definition: ControllerWrapper.cpp:73
armarx::control::client::detail::ControllerWrapperBase::daemonize
void daemonize(bool daemonize=true)
Sets whether the controller should be daemonized.
Definition: ControllerWrapper.cpp:81
std
Definition: Application.h:66
armarx::control::client::detail::ControllerWrapperBase::ControllerPrx
armarx::control::ConfigurableNJointControllerInterfacePrx ControllerPrx
Definition: ControllerWrapper.h:46
AronGeneratedClass.h