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/interface/ConfigurableNJointControllerInterface.h>
46 #include <armarx/control/memory/config/Reader.h>
47 #include <armarx/control/memory/config/Writer.h>
49 
50 namespace armarx::armem::client
51 {
52  class MemoryNameSystem;
53 }
54 
56 {
57  class Plugin;
58 }
59 
60 namespace armarx::plugins
61 {
62  class RobotUnitComponentPlugin;
63 }
64 
66 {
67 
69  {
70  public:
71  ComponentPlugin(ManagedIceObject& parent, const std::string& prefix);
72  ~ComponentPlugin() override;
73 
75 
76  void preOnInitComponent() override;
77  void preOnConnectComponent() override;
78 
79  template <auto T, typename... Args>
80  auto
82  {
83  // Probe if a proper builder is returned ...
84  using BuilderT = decltype(concreteControllerBuilder<T>(args...));
85 
86  // ... otherwise, print a meaningful message.
87  static_assert(not std::is_void<BuilderT>::value,
88  "This controller type is not supported at the moment!");
89 
90  return concreteControllerBuilder<T>(args...);
91  }
92 
93  template <auto T>
94  auto
96  {
97  return createControllerBuilder<T>(robotUnitPlugin->getRobotUnit(),
98  configReader.value(),
99  configWriter.value(),
100  parent().getName());
101  }
102 
105  {
106  return *robotUnitPlugin;
107  }
108 
111  {
112  return *armemPlugin;
113  }
114 
115  memory::config::Reader&
117  {
118  ARMARX_CHECK(configReader.has_value());
119  return configReader.value();
120  }
121 
122  memory::config::Writer&
124  {
125  ARMARX_CHECK(configWriter.has_value());
126  return configWriter.value();
127  }
128 
129  private:
130  template <auto T, typename... Args>
131  constexpr auto
132  concreteControllerBuilder(Args... args)
133  {
134  return ControllerBuilder<T>(args...);
135  }
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  class ComponentPluginUser : virtual public ManagedIceObject
147  {
148 
149  public:
151 
152 
153  // Non-API
154  ~ComponentPluginUser() override;
155 
156  template <auto T>
157  auto
159  {
160  ARMARX_CHECK_NOT_NULL(plugin);
161  return plugin->createControllerBuilder<T>();
162  }
163 
165 
166  private:
167  ComponentPlugin* plugin = nullptr;
168  };
169 
170 
171 } // namespace armarx::control::client
armarx::control::client::ComponentPluginUser::~ComponentPluginUser
~ComponentPluginUser() override
armarx::ManagedIceObjectPlugin::prefix
const std::string & prefix() const
Definition: ManagedIceObjectPlugin.cpp:66
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:72
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:123
armarx::control::client::ComponentPluginUser::controllerBuilder
auto controllerBuilder()
Definition: ComponentPlugin.h:158
armarx::control::client::ComponentPlugin::configMemoryReader
memory::config::Reader & configMemoryReader()
Definition: ComponentPlugin.h:116
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:6
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:146
armarx::control::client::ComponentPlugin
Definition: ComponentPlugin.h:68
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:855
ManagedIceObject.h
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:27
armarx::ComponentPlugin
Definition: ComponentPlugin.h:37
ControllerDescription.h
armarx::control::client::ComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(armarx::PropertyDefinitionsPtr &properties) override
Definition: ComponentPlugin.cpp:33
armarx::control::client::ComponentPlugin::getRobotUnitPlugin
armarx::plugins::RobotUnitComponentPlugin & getRobotUnitPlugin()
Definition: ComponentPlugin.h:104
armarx::control::client::ComponentPlugin::createControllerBuilder
auto createControllerBuilder(Args... args)
Definition: ComponentPlugin.h:81
armarx::control::client::ComponentPluginUser::getControlComponentPlugin
ComponentPlugin & getControlComponentPlugin()
Definition: ComponentPlugin.cpp:68
armarx::control::client::ComponentPlugin::createControllerBuilder
auto createControllerBuilder()
Definition: ComponentPlugin.h:95
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:162
constants.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::client::plugins
This file is part of ArmarX.
Definition: forward_declarations.h:23
armarx::control::client::ComponentPluginUser::ComponentPluginUser
ComponentPluginUser()
Definition: ComponentPlugin.cpp:61
armarx::control::client::ComponentPlugin::getArmemPlugin
armarx::armem::client::plugins::Plugin & getArmemPlugin()
Definition: ComponentPlugin.h:110
ComponentPlugin.h
MemoryNameSystem.h
Logging.h
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
armarx::control::client::ComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: ComponentPlugin.cpp:40
RobotUnitComponentPlugin.h
armarx::control::client::ComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: ComponentPlugin.cpp:47
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:19
armarx::plugins::RobotUnitComponentPlugin::getRobotUnit
RobotUnitInterfacePrx getRobotUnit() const
Definition: RobotUnitComponentPlugin.cpp:112
ControllerWrapper.h