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>
26 
28 
31 #include <armarx/control/memory/config/Writer.h>
33 #include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
34 
36 {
37 
38 
39  template <auto T>
41  {
42  public:
43  using ControllerPrx = armarx::control::
44  ConfigurableNJointControllerInterfacePrx; // ::armarx::control::ControllerInterfacePtr;
45 
47  using AronConfigT = typename ControllerDescriptionType::AronDTO;
48 
49 
51  "You must provide a ControllerDescription!");
52 
53  ControllerWrapper() = default;
54 
56  const std::string& controllerName,
57  const memory::config::Writer& configWriter,
59  config(config),
61  controllerName(controllerName),
62  configWriter(configWriter)
63  {
64  }
65 
67  static_assert(std::is_base_of<armarx::aron::codegenerator::cpp::AronGeneratedClass,
69  "asdf");
70 
71  void
73  {
74  ARMARX_INFO << "Updating config for controller `" << controllerName << "`";
75 
77  controller->updateConfig(config.toAronDTO());
78 
79  // store the config also in the memory (logging only)
80  configWriter.storeConfig(
81  std::string(ControllerDescriptionType::name), controllerName, config.toAron());
82  }
83 
85  {
86 
87  // deactivate the controller
88  if (not daemonized)
89  {
90  ARMARX_INFO << "Deactivating and deleting controller `" << controllerName << "`";
91  // FIXME does not work atm: controller->deactivateAndDeleteController();
92  }
93 
94  // => switch to velocity mode ??
95 
96  // delete controll
97  }
98 
99  void
101  {
102  ARMARX_INFO << "Activating controller `" << controllerName << "`";
103  controller->activateController();
104  }
105 
106  void
108  {
109  ARMARX_INFO << "Deactivating controller `" << controllerName << "`";
110  controller->deactivateController();
111  }
112 
113  /**
114  * @brief
115  *
116  */
117  void
118  daemonize(const bool daemonize = true)
119  {
120  ARMARX_INFO << "Daemonizing controller `" << controllerName << "`";
121  daemonized = daemonize;
122  }
123 
126  {
127  return controller;
128  }
129 
130  private:
132  const std::string controllerName;
133 
134  memory::config::Writer configWriter;
135 
136  // Indicates whether this controller will be deactivated and deleted from the RobotUnit
137  // upon deletion of this object.
138  bool daemonized = false;
139  };
140 
141 } // namespace armarx::control::client
armarx::control::client::ControllerWrapper::updateConfig
void updateConfig()
Definition: ControllerWrapper.h:72
armarx::control::client::ControllerWrapper::AronConfigT
typename ControllerDescriptionType::AronDTO AronConfigT
Definition: ControllerWrapper.h:47
armarx::control::client::ControllerWrapper::config
AronConfigT config
Definition: ControllerWrapper.h:66
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
armarx::control::client::ControllerWrapper::activate
void activate()
Definition: ControllerWrapper.h:100
armarx::control::client::ControllerDescription
Definition: ControllerDescription.h:28
armarx::control::client::ControllerWrapper
Definition: ControllerWrapper.h:40
type.h
armarx::control::client::ControllerWrapper::deactivate
void deactivate()
Definition: ControllerWrapper.h:107
armarx::control::client::ControllerWrapper::ControllerWrapper
ControllerWrapper()=default
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
controller
Definition: AddOperation.h:39
ControllerDescription.h
armarx::control::client::ControllerWrapper::~ControllerWrapper
~ControllerWrapper()
Definition: ControllerWrapper.h:84
armarx::aron::cpp::AronGeneratedClass
Definition: AronGeneratedClass.h:46
armarx::control::client::ControllerWrapper::ControllerWrapper
ControllerWrapper(const ControllerPrx &controller, const std::string &controllerName, const memory::config::Writer &configWriter, AronConfigT config)
Definition: ControllerWrapper.h:55
constants.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::control::client::ControllerWrapper::ctrl
ControllerPrx & ctrl()
Definition: ControllerWrapper.h:125
armarx::control::client::ControllerWrapper::daemonize
void daemonize(const bool daemonize=true)
Definition: ControllerWrapper.h:118
armarx::control::client::ControllerWrapper::ControllerPrx
armarx::control::ConfigurableNJointControllerInterfacePrx ControllerPrx
Definition: ControllerWrapper.h:44
AronGeneratedClass.h