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 
49  ControllerWrapperBase() = delete;
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 
135  "You must provide a ControllerDescription!");
136 
138 
139  // The class must be instantiated properly.
140  ControllerWrapper() = delete;
141 
142  ControllerWrapper(const ControllerWrapper&) = delete;
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),
161  config(config)
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
174  {
176  }
177 
180  {
182  auto cfg = ctrl()->getConfig();
183  return AronConfigT::FromAron(cfg);
184  }
185  };
186 
187 } // 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:173
armarx::control::client::ControllerWrapper::AronConfigT
typename ControllerDescriptionType::AronDTO AronConfigT
Definition: ControllerWrapper.h:132
armarx::control::client::ControllerWrapper::config
AronConfigT config
Definition: ControllerWrapper.h:165
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:44
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:128
armarx::control::client::detail::ControllerWrapperBase::ctrl
ControllerPrx & ctrl()
Returns the "raw" controller object.
Definition: ControllerWrapper.cpp:88
armarx::aron::cpp::AronGeneratedObjectBase
Definition: AronGeneratedObject.h:31
armarx::control::client::ControllerDescription
Definition: ControllerDescription.h:103
armarx::control::client::ControllerWrapper
Wrapper class for an NJointController proxy.
Definition: ControllerWrapper.h:128
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:855
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:179
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:153
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:47
AronGeneratedClass.h