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 navigation::ArmarXObjects::navigation_skill_provider
17  * @author Fabian Reister ( fabian dot reister at kit dot edu )
18  * @date 2023
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 #include "Component.h"
25 
27 
36 
38 {
40  {
41  addPlugin(virtualRobotReaderPlugin);
42  addPlugin(costmapReaderPlugin);
43  addPlugin(graphReaderPlugin);
44  addPlugin(roomsReaderPlugin);
45  }
46 
47  const std::string Component::defaultName = skills::constants::NavigationSkillProviderName;
48 
51  {
54 
55  def->component(navigatorPrx, "navigator");
56 
57  def->required(properties.robotName, "RobotName", "Default robot name.");
58 
59  auto optionalSubSkillID =
60  [&def](armarx::skills::SkillID& skillID, const std::string& nameBase)
61  {
62  ARMARX_CHECK(skillID.providerId.has_value());
63  def->optional(skillID.providerId->providerName, nameBase + ".providerName");
64  def->optional(skillID.skillName, nameBase + ".skillName");
65  };
66 
67  optionalSubSkillID(properties.navigateToNamedLocation.subSkillIDs.navigateToLocation,
68  "p.navigateToNamedLocation.subSkillIDs.navigateToLocation");
69  optionalSubSkillID(properties.navigateToChargingStation.subSkillIDs.navigateToNamedLocation,
70  "p.navigateToChargingStation.subSkillIDs.navigateToNamedLocation");
71 
72  return def;
73  }
74 
75  void
77  {
78  // Topics and properties defined above are automagically registered.
79 
80  // Keep debug observer data until calling `sendDebugObserverBatch()`.
81  // (Requies the armarx::DebugObserverComponentPluginUser.)
82  // setDebugObserverBatchModeEnabled(true);
83  }
84 
85  void
87  {
88  // Do things after connecting to topics and components.
89 
90  iceNavigator.setNavigatorComponent(navigatorPrx);
91 
92  {
94  .iceNavigator = iceNavigator,
95  .memoryNameSystem = memoryNameSystem(),
96  };
97  addSkillFactory<skills::NavigateTo>(srv);
98  }
99 
100  {
102  .iceNavigator = iceNavigator,
103  .memoryNameSystem = memoryNameSystem(),
104  };
105  addSkillFactory<skills::NavigateToLocation>(srv);
106  }
107 
108  {
110  .locationReader = graphReaderPlugin->get(),
111  };
112  addSkillFactory<skills::NavigateToNamedLocation>(properties.navigateToNamedLocation,
113  services);
114  }
115 
116  {
117  addSkillFactory<skills::NavigateToChargingStation>(
118  properties.navigateToChargingStation);
119  }
120 
121  {
122  skills::MoveXMeters::Services srv{
123  .iceNavigator = iceNavigator,
124  .memoryNameSystem = memoryNameSystem(),
125  };
126  addSkillFactory<skills::MoveXMeters>(srv);
127  }
128 
129  {
130 
131  skills::RotateXDegrees::Services srv{
132  .iceNavigator = iceNavigator,
133  .memoryNameSystem = memoryNameSystem(),
134  };
135  addSkillFactory<skills::RotateXDegrees>(srv);
136  }
137 
138  {
140  .robotName = this->properties.robotName,
141  };
143  .iceNavigator = iceNavigator,
144  .memoryNameSystem = memoryNameSystem(),
145  .robotReader = virtualRobotReaderPlugin->get(),
146  };
147  addSkillFactory<skills::MoveRelativePlanar>(properties, srv);
148  }
149 
150  {
151  ARMARX_CHECK_NOT_NULL(virtualRobotReaderPlugin);
152  ARMARX_CHECK_NOT_NULL(virtualRobotReaderPlugin);
153  ARMARX_CHECK_NOT_NULL(roomsReaderPlugin);
154 
156  .memoryNameSystem = memoryNameSystem(),
157  .virtualRobotReader =
158  virtualRobotReaderPlugin->get(),
159  .costmapReader = costmapReaderPlugin->get(),
160  .roomsReader = roomsReaderPlugin->get(),
161  .arviz = arviz};
162 
163  addSkillFactory<skills::GuideHumanToRoom>(srv);
164  }
165 
166 
167  /* (Requies the armarx::DebugObserverComponentPluginUser.)
168  // Use the debug observer to log data over time.
169  // The data can be viewed in the ObserverView and the LivePlotter.
170  // (Before starting any threads, we don't need to lock mutexes.)
171  {
172  setDebugObserverDatafield("numBoxes", properties.numBoxes);
173  setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
174  sendDebugObserverBatch();
175  }
176  */
177 
178  /* (Requires the armarx::ArVizComponentPluginUser.)
179  // Draw boxes in ArViz.
180  // (Before starting any threads, we don't need to lock mutexes.)
181  drawBoxes(properties, arviz);
182  */
183 
184  /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
185  // Setup the remote GUI.
186  {
187  createRemoteGuiTab();
188  RemoteGui_startRunningTask();
189  }
190  */
191  }
192 
193  void
195  {
196  }
197 
198  void
200  {
201  }
202 
203  std::string
205  {
206  return Component::defaultName;
207  }
208 
209  std::string
211  {
212  return Component::defaultName;
213  }
214 
215  /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
216  void
217  Component::createRemoteGuiTab()
218  {
219  using namespace armarx::RemoteGui::Client;
220 
221  // Setup the widgets.
222 
223  tab.boxLayerName.setValue(properties.boxLayerName);
224 
225  tab.numBoxes.setValue(properties.numBoxes);
226  tab.numBoxes.setRange(0, 100);
227 
228  tab.drawBoxes.setLabel("Draw Boxes");
229 
230  // Setup the layout.
231 
232  GridLayout grid;
233  int row = 0;
234  {
235  grid.add(Label("Box Layer"), {row, 0}).add(tab.boxLayerName, {row, 1});
236  ++row;
237 
238  grid.add(Label("Num Boxes"), {row, 0}).add(tab.numBoxes, {row, 1});
239  ++row;
240 
241  grid.add(tab.drawBoxes, {row, 0}, {2, 1});
242  ++row;
243  }
244 
245  VBoxLayout root = {grid, VSpacer()};
246  RemoteGui_createTab(getName(), root, &tab);
247  }
248 
249 
250  void
251  Component::RemoteGui_update()
252  {
253  if (tab.boxLayerName.hasValueChanged() || tab.numBoxes.hasValueChanged())
254  {
255  std::scoped_lock lock(propertiesMutex);
256  properties.boxLayerName = tab.boxLayerName.getValue();
257  properties.numBoxes = tab.numBoxes.getValue();
258 
259  {
260  setDebugObserverDatafield("numBoxes", properties.numBoxes);
261  setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
262  sendDebugObserverBatch();
263  }
264  }
265  if (tab.drawBoxes.wasClicked())
266  {
267  // Lock shared variables in methods running in seperate threads
268  // and pass them to functions. This way, the called functions do
269  // not need to think about locking.
270  std::scoped_lock lock(propertiesMutex, arvizMutex);
271  drawBoxes(properties, arviz);
272  }
273  }
274  */
275 
276 
277  /* (Requires the armarx::ArVizComponentPluginUser.)
278  void
279  Component::drawBoxes(const Component::Properties& p, viz::Client& arviz)
280  {
281  // Draw something in ArViz (requires the armarx::ArVizComponentPluginUser.
282  // See the ArVizExample in RobotAPI for more examples.
283 
284  viz::Layer layer = arviz.layer(p.boxLayerName);
285  for (int i = 0; i < p.numBoxes; ++i)
286  {
287  layer.add(viz::Box("box_" + std::to_string(i))
288  .position(Eigen::Vector3f(i * 100, 0, 0))
289  .size(20).color(simox::Color::blue()));
290  }
291  arviz.commit(layer);
292  }
293  */
294 
295 
297 
298 } // namespace armarx::navigation::components::navigation_skill_provider
constants.h
armarx::navigation::client::IceNavigator::setNavigatorComponent
void setNavigatorComponent(const NavigatorInterfacePrx &navigator)
Definition: IceNavigator.cpp:39
armarx::navigation::skills::NavigateToNamedLocation::Services::locationReader
armarx::navigation::memory::client::graph::Reader locationReader
Definition: NavigateToNamedLocation.h:53
armarx::navigation::skills::MoveRelativePlanar::Services::iceNavigator
client::IceNavigator & iceNavigator
Definition: MoveRelativePlanar.h:19
armarx::navigation::skills::constants::NavigationSkillProviderName
const std::string NavigationSkillProviderName
Definition: constants.h:28
armarx::skills::SkillID::skillName
std::string skillName
Definition: SkillID.h:60
armarx::armem::client::plugins::PluginUser::memoryNameSystem
MemoryNameSystem & memoryNameSystem()
Definition: PluginUser.cpp:22
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
RotateXDegrees.h
armarx::skills::SkillID::providerId
std::optional< ProviderID > providerId
Definition: SkillID.h:59
armarx::navigation::components::navigation_skill_provider::Component::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: Component.cpp:50
armarx::ManagedIceObject::addPlugin
PluginT * addPlugin(const std::string prefix="", ParamsT &&...params)
Definition: ManagedIceObject.h:182
armarx::navigation::skills::NavigateToNamedLocation::Services
Definition: NavigateToNamedLocation.h:51
armarx::navigation::components::navigation_skill_provider::Component::Component
Component()
Definition: Component.cpp:39
Component.h
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::navigation::components::navigation_skill_provider::Component::onExitComponent
void onExitComponent() override
Definition: Component.cpp:199
armarx::navigation::skills::NavigateTo::Services
Definition: NavigateTo.h:44
GuideHumanToRoom.h
NavigateToLocation.h
armarx::navigation::components::navigation_skill_provider
Definition: Component.cpp:37
armarx::navigation::components::navigation_skill_provider::Component::getDefaultName
std::string getDefaultName() const override
Definition: Component.cpp:204
armarx::navigation::skills::NavigateToLocation::Services::iceNavigator
client::IceNavigator & iceNavigator
Definition: NavigateToLocation.h:41
armarx::navigation::skills::MoveRelativePlanar::Properties
Definition: MoveRelativePlanar.h:24
armarx::navigation::components::navigation_skill_provider::ARMARX_REGISTER_COMPONENT_EXECUTABLE
ARMARX_REGISTER_COMPONENT_EXECUTABLE(Component, Component::GetDefaultName())
armarx::navigation::components::navigation_skill_provider::Component::onDisconnectComponent
void onDisconnectComponent() override
Definition: Component.cpp:194
NavigateTo.h
armarx::navigation::components::navigation_skill_provider::Component
Definition: Component.h:48
armarx::navigation::skills::GuideHumanToRoom::Services::iceNavigator
client::IceNavigator & iceNavigator
Definition: GuideHumanToRoom.h:50
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
Decoupled.h
armarx::navigation::components::navigation_skill_provider::Component::GetDefaultName
static std::string GetDefaultName()
Get the component's default name.
Definition: Component.cpp:210
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::ArVizComponentPluginUser::arviz
armarx::viz::Client arviz
Definition: ArVizComponentPlugin.h:43
armarx::navigation::skills::NavigateToLocation::Services
Definition: NavigateToLocation.h:39
MoveRelativePlanar.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::navigation::components::navigation_skill_provider::Component::onConnectComponent
void onConnectComponent() override
Definition: Component.cpp:86
NavigateToChargingStation.h
armarx::navigation::skills::MoveRelativePlanar::Services
Definition: MoveRelativePlanar.h:17
MoveXMeters.h
armarx::skills::SkillID
Definition: SkillID.h:17
armarx::navigation::skills::NavigateTo::Services::iceNavigator
client::IceNavigator & iceNavigator
Definition: NavigateTo.h:46
armarx::navigation::skills::GuideHumanToRoom::Services
Definition: GuideHumanToRoom.h:48
armarx::navigation::components::navigation_skill_provider::Component::onInitComponent
void onInitComponent() override
Definition: Component.cpp:76