ControllerWrapper.cpp
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 2024
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #include "ControllerWrapper.h"
23 
26 
28 #include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
29 #include <armarx/control/memory/config/Writer.h>
31 
33 {
34 
35 
37  const std::string& controllerName,
38  const std::string& controllerTypeName,
39  const memory::config::Writer& configWriter) :
40  controller_(controller),
41  controllerName_(controllerName),
42  controllerTypeName_(controllerTypeName),
43  configWriter_(configWriter)
44  {
45  }
46 
48  {
49  // deactivate the controller
50  if (not daemonized_)
51  {
52  ARMARX_INFO << "Deactivating and deleting controller `" << controllerName_ << "`";
53  controller_->deactivateAndDeleteController();
54  }
55  }
56 
57  void
59  {
60  ARMARX_CHECK_EXPRESSION(controller_);
61  ARMARX_INFO << "Activating controller `" << controllerName_ << "`";
62  controller_->activateController();
63  }
64 
65  bool
67  {
68  ARMARX_CHECK_EXPRESSION(controller_);
69  return controller_->isControllerActive();
70  }
71 
72  void
74  {
75  ARMARX_CHECK_EXPRESSION(controller_);
76  ARMARX_INFO << "Deactivating controller `" << controllerName_ << "`";
77  controller_->deactivateController();
78  }
79 
80  void
81  ControllerWrapperBase::daemonize(const bool daemonize)
82  {
83  ARMARX_INFO << "Daemonizing controller `" << controllerName_ << "`";
84  daemonized_ = daemonize;
85  }
86 
89  {
90  ARMARX_CHECK_EXPRESSION(controller_);
91  return controller_;
92  }
93 
94  void
97  {
98  ARMARX_VERBOSE << "Updating config for controller `" << controllerName_ << "`";
99 
100  ARMARX_CHECK_NOT_NULL(controller_);
101  controller_->updateConfig(config.toAronDTO());
102 
103  // store the config also in the memory (logging only)
104  configWriter_.storeConfig(controllerTypeName_, controllerName_, config.toAron());
105  }
106 } // namespace armarx::control::client::detail
armarx::control::client::detail::ControllerWrapperBase::ControllerWrapperBase
ControllerWrapperBase()=delete
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
AronGeneratedObject.h
armarx::control::client::detail::ControllerWrapperBase::activate
void activate()
Requests the activation of the controller in the RobotUnit.
Definition: ControllerWrapper.cpp:58
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::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::detail::ControllerWrapperBase::~ControllerWrapperBase
~ControllerWrapperBase()
Destructor for the ControllerWrapperBase class.
Definition: ControllerWrapper.cpp:47
controller
Definition: AddOperation.h:39
armarx::control::client::detail
This file is part of ArmarX.
Definition: ControllerDescription.h:30
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::detail::ControllerWrapperBase::deactivate
void deactivate()
Requests the deactivation of the controller in the RobotUnit.
Definition: ControllerWrapper.cpp:73
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
constants.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::control::client::detail::ControllerWrapperBase::daemonize
void daemonize(bool daemonize=true)
Sets whether the controller should be daemonized.
Definition: ControllerWrapper.cpp:81
armarx::aron::cpp::AronGeneratedObjectBase::toAronDTO
virtual armarx::aron::data::dto::DictPtr toAronDTO() const =0
Convert the current bo to the ice representation of an aron variant data dict.
armarx::control::client::detail::ControllerWrapperBase::ControllerPrx
armarx::control::ConfigurableNJointControllerInterfacePrx ControllerPrx
Definition: ControllerWrapper.h:46
armarx::aron::cpp::AronGeneratedObjectBase::toAron
virtual armarx::aron::data::DictPtr toAron() const =0
Convert the current bo to an aron variant data dict.
AronGeneratedClass.h
ControllerWrapper.h