Component.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 * @package control::ArmarXObjects::collision_avoidance_skill_provider
17 * @author Meixner ( andre dot meixner at kit dot edu )
18 * @date 2025
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
24#include "Component.h"
25
26// Include headers you only need in function definitions in the .cpp.
27
28// #include <Eigen/Core>
29
30// #include <SimoxUtility/color/Color.h>
31
33
34// Skill libraries
36
38
39
41{
42
43 const std::string
44 Component::defaultName = "collision_avoidance_skill_provider";
45
49
52 {
53 ::armarx::PropertyDefinitionsPtr def = new ::armarx::ComponentPropertyDefinitions(getConfigIdentifier());
54
55 def->component(collisionAvoidanceComponent);
56
57 // Publish to a topic (passing the TopicListenerPrx).
58 // def->topic(myTopicListener);
59
60 // Subscribe to a topic (passing the topic name).
61 // def->topic<PlatformUnitListener>("MyTopic");
62
63 // Use (and depend on) another component (passing the ComponentInterfacePrx).
64 // def->component(myComponentProxy)
65 //def->required(properties.robotUnitName, "RobotUnitName", "Name of the robot unit.");
66
67
68 // Add a required property. (The component won't start without a value being set.)
69 // def->required(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
70
71 // Add an optional property.
72 // def->optional(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
73 // def->optional(properties.numBoxes, "p.box.Number", "Number of boxes to draw in ArViz.");
74
75 return def;
76 }
77
78
79 void
81 {
82 // Topics and properties defined above are automagically registered.
83
84 // Keep debug observer data until calling `sendDebugObserverBatch()`.
85 // (Requires the armarx::DebugObserverComponentPluginUser.)
86 // setDebugObserverBatchModeEnabled(true);
87 }
88
89
90 void
92 {
93 // Do things after connecting to topics and components.
94
96 //Add a new skillFacory for your skill with the remote and properties structs needed.
97
98 // collisionAvoidanceComponent = getProxy<armarx::control::components::collision_avoidance::ComponentInterfacePrx>("Component");
99
100 const skills::CollisionAvoidance::Remote remote {
101 .collisionAvoidanceComponent =
102 std::experimental::make_observer(&collisionAvoidanceComponent)
103 };
104
105 //skills::CollisionAvoidance::Properties properties;
106
107 //armarx::armem::robot_state::VirtualRobotReader robotStateReader;
108 //robotStateReader.connect(memoryNameSystem());
109
111
112 /* (Requires the armarx::DebugObserverComponentPluginUser.)
113 // Use the debug observer to log data over time.
114 // The data can be viewed in the ObserverView and the LivePlotter.
115 // (Before starting any threads, we don't need to lock mutexes.)
116 {
117 setDebugObserverDatafield("numBoxes", properties.numBoxes);
118 setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
119 sendDebugObserverBatch();
120 }
121 */
122
123 /* (Requires the armarx::ArVizComponentPluginUser.)
124 // Draw boxes in ArViz.
125 // (Before starting any threads, we don't need to lock mutexes.)
126 drawBoxes(properties, arviz);
127 */
128
129 /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
130 // Setup the remote GUI.
131 {
132 createRemoteGuiTab();
133 RemoteGui_startRunningTask();
134 }
135 */
136 }
137
138
139 void
143
144
145 void
149
150
151 std::string
153 {
154 return Component::defaultName;
155 }
156
157
158 std::string
160 {
161 return Component::defaultName;
162 }
163
164
165 /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
166 void
167 Component::createRemoteGuiTab()
168 {
169 using namespace armarx::RemoteGui::Client;
170
171 // Setup the widgets.
172
173 tab.boxLayerName.setValue(properties.boxLayerName);
174
175 tab.numBoxes.setValue(properties.numBoxes);
176 tab.numBoxes.setRange(0, 100);
177
178 tab.drawBoxes.setLabel("Draw Boxes");
179
180 // Setup the layout.
181
182 GridLayout grid;
183 int row = 0;
184 {
185 grid.add(Label("Box Layer"), {row, 0}).add(tab.boxLayerName, {row, 1});
186 ++row;
187
188 grid.add(Label("Num Boxes"), {row, 0}).add(tab.numBoxes, {row, 1});
189 ++row;
190
191 grid.add(tab.drawBoxes, {row, 0}, {2, 1});
192 ++row;
193 }
194
195 VBoxLayout root = {grid, VSpacer()};
196 RemoteGui_createTab(getName(), root, &tab);
197 }
198
199
200 void
201 Component::RemoteGui_update()
202 {
203 if (tab.boxLayerName.hasValueChanged() || tab.numBoxes.hasValueChanged())
204 {
205 std::scoped_lock lock(propertiesMutex);
206 properties.boxLayerName = tab.boxLayerName.getValue();
207 properties.numBoxes = tab.numBoxes.getValue();
208
209 {
210 setDebugObserverDatafield("numBoxes", properties.numBoxes);
211 setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
212 sendDebugObserverBatch();
213 }
214 }
215 if (tab.drawBoxes.wasClicked())
216 {
217 // Lock shared variables in methods running in separate threads
218 // and pass them to functions. This way, the called functions do
219 // not need to think about locking.
220 std::scoped_lock lock(propertiesMutex);
221 drawBoxes(properties, arviz);
222 }
223 }
224 */
225
226
227 /* (Requires the armarx::ArVizComponentPluginUser.)
228 void
229 Component::drawBoxes(const Component::Properties& p, viz::Client& arviz)
230 {
231 // Draw something in ArViz (requires the armarx::ArVizComponentPluginUser.
232 // See the ArVizExample in RobotAPI for more examples.
233
234 viz::Layer layer = arviz.layer(p.boxLayerName);
235 for (int i = 0; i < p.numBoxes; ++i)
236 {
237 layer.add(viz::Box("box_" + std::to_string(i))
238 .position(Eigen::Vector3f(i * 100, 0, 0))
239 .size(20).color(simox::Color::blue()));
240 }
241 arviz.commit(layer);
242 }
243 */
244
245
247
248} // namespace armarx::control::components::collision_avoidance::skill_provider
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
skills::SkillBlueprint * addSkillFactory(const skills::SkillDescription &desc, const skills::LambdaSkill::FunctionType &f)
::armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition Component.cpp:51
static std::string GetDefaultName()
Get the component's default name.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
This file is part of ArmarX.
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept