ComponentPlugin.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 
25 #include <filesystem>
26 #include <optional>
27 #include <string>
28 #include <type_traits>
29 
34 
35 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
39 
44 #include <armarx/control/core/Controller.h>
45 #include <armarx/control/memory/config/Reader.h>
46 #include <armarx/control/memory/config/Writer.h>
48 #include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
49 
50 
51 namespace armarx::armem::client
52 {
53  class MemoryNameSystem;
54 }
55 
57 {
58  class Plugin;
59 }
60 
61 namespace armarx::plugins
62 {
63  class RobotUnitComponentPlugin;
64 }
65 
67 {
68 
70  {
71  public:
72  ComponentPlugin(ManagedIceObject& parent, const std::string& prefix);
73  ~ComponentPlugin() override;
74 
76 
77  void preOnInitComponent() override;
78  void preOnConnectComponent() override;
79 
80 
81  template <auto T, typename... Args>
82  auto
84  {
85  // Probe if a proper builder is returned ...
86  using BuilderT = decltype(concreteControllerBuilder<T>(args...));
87 
88  // ... otherwise, print a meaningful message.
89  static_assert(not std::is_void<BuilderT>::value,
90  "This controller type is not supported at the moment!");
91 
92  return concreteControllerBuilder<T>(args...);
93  }
94 
95  template <auto T>
96  auto
98  {
99  return createControllerBuilder<T>(robotUnitPlugin->getRobotUnit(),
100  configReader.value(),
101  configWriter.value(),
102  parent().getName());
103  }
104 
107  {
108  return *robotUnitPlugin;
109  }
112  {
113  return *armemPlugin;
114  }
115 
116  memory::config::Reader&
118  {
119  ARMARX_CHECK(configReader.has_value());
120  return configReader.value();
121  }
122 
123  memory::config::Writer&
125  {
126  ARMARX_CHECK(configWriter.has_value());
127  return configWriter.value();
128  }
129 
130  private:
131  template <auto T, typename... Args>
132  constexpr auto
133  concreteControllerBuilder(Args... args)
134  {
135  return ControllerBuilder<T>(args...);
136  }
137  // static constexpr const char* PROPERTY_NAME = "nav.NavigatorName";
138 
139  std::optional<memory::config::Reader> configReader;
140  std::optional<memory::config::Writer> configWriter;
141 
142  armarx::armem::client::plugins::Plugin* armemPlugin = nullptr;
143  armarx::plugins::RobotUnitComponentPlugin* robotUnitPlugin = nullptr;
144  };
145 
146 
147  class ComponentPluginUser : virtual public ManagedIceObject
148  {
149 
150  public:
152 
153 
154  // Non-API
155  ~ComponentPluginUser() override;
156 
157  template <auto T>
158  auto
160  {
161  ARMARX_CHECK_NOT_NULL(plugin);
162  return plugin->createControllerBuilder<T>();
163  }
164 
166 
167  private:
168  ComponentPlugin* plugin = nullptr;
169  };
170 
171 
172 } // namespace armarx::control::client
armarx::control::client::ComponentPluginUser::~ComponentPluginUser
~ComponentPluginUser() override
armarx::ManagedIceObjectPlugin::prefix
const std::string & prefix() const
Definition: ManagedIceObjectPlugin.cpp:63
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:69
MemoryID.h
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::ComponentPlugin::configMemoryWriter
memory::config::Writer & configMemoryWriter()
Definition: ComponentPlugin.h:124
armarx::control::client::ComponentPluginUser::controllerBuilder
auto controllerBuilder()
Definition: ComponentPlugin.h:159
armarx::control::client::ComponentPlugin::configMemoryReader
memory::config::Reader & configMemoryReader()
Definition: ComponentPlugin.h:117
armarx::control::client
This file is part of ArmarX.
Definition: ComponentPlugin.cpp:20
armarx::armem::client
This file is part of ArmarX.
Definition: forward_declarations.h:7
armarx::control::client::ControllerBuilder
Definition: ControllerBuilder.h:52
type.h
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::control::client::ComponentPluginUser
Definition: ComponentPlugin.h:147
armarx::control::client::ComponentPlugin
Definition: ComponentPlugin.h:69
armarx::control::client::ComponentPlugin::ComponentPlugin
ComponentPlugin(ManagedIceObject &parent, const std::string &prefix)
Definition: ComponentPlugin.cpp:23
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
ManagedIceObject.h
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:28
armarx::ComponentPlugin
Definition: ComponentPlugin.h:38
ControllerDescription.h
armarx::control::client::ComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(armarx::PropertyDefinitionsPtr &properties) override
Definition: ComponentPlugin.cpp:34
armarx::control::client::ComponentPlugin::getRobotUnitPlugin
armarx::plugins::RobotUnitComponentPlugin & getRobotUnitPlugin()
Definition: ComponentPlugin.h:106
armarx::control::client::ComponentPlugin::createControllerBuilder
auto createControllerBuilder(Args... args)
Definition: ComponentPlugin.h:83
armarx::control::client::ComponentPluginUser::getControlComponentPlugin
ComponentPlugin & getControlComponentPlugin()
Definition: ComponentPlugin.cpp:70
armarx::control::client::ComponentPlugin::createControllerBuilder
auto createControllerBuilder()
Definition: ComponentPlugin.h:97
ControllerBuilder.h
armarx::plugins::RobotUnitComponentPlugin
Definition: RobotUnitComponentPlugin.h:11
armarx::control::client::ComponentPlugin::~ComponentPlugin
~ComponentPlugin() override
ExpressionException.h
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
constants.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::client::plugins
This file is part of ArmarX.
Definition: forward_declarations.h:24
armarx::control::client::ComponentPluginUser::ComponentPluginUser
ComponentPluginUser()
Definition: ComponentPlugin.cpp:63
armarx::control::client::ComponentPlugin::getArmemPlugin
armarx::armem::client::plugins::Plugin & getArmemPlugin()
Definition: ComponentPlugin.h:111
ComponentPlugin.h
MemoryNameSystem.h
Logging.h
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::control::client::ComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: ComponentPlugin.cpp:41
RobotUnitComponentPlugin.h
armarx::control::client::ComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: ComponentPlugin.cpp:48
armarx::armem::client::plugins::Plugin
A component plugin offering client-side access to to the working memory system by providing a Memory ...
Definition: Plugin.h:20
armarx::plugins::RobotUnitComponentPlugin::getRobotUnit
RobotUnitInterfacePrx getRobotUnit() const
Definition: RobotUnitComponentPlugin.cpp:112
ControllerWrapper.h