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