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
51{
52 class MemoryNameSystem;
53}
54
56{
57 class Plugin;
58}
59
60namespace armarx::plugins
61{
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
147 {
148
149 public:
151
152
153 // Non-API
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
const std::string & prefix() const
ManagedIceObject(ManagedIceObject const &other)
The memory name system (MNS) client.
A component plugin offering client-side access to to the working memory system by providing a Memory ...
Definition Plugin.h:20
ComponentPlugin(ManagedIceObject &parent, const std::string &prefix)
memory::config::Reader & configMemoryReader()
memory::config::Writer & configMemoryWriter()
armarx::armem::client::plugins::Plugin & getArmemPlugin()
armarx::plugins::RobotUnitComponentPlugin & getRobotUnitPlugin()
void postCreatePropertyDefinitions(armarx::PropertyDefinitionsPtr &properties) override
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#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...
This file is part of ArmarX.
This file is part of ArmarX.
This file is part of ArmarX.
This file is part of ArmarX.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.