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::retrieve_hand_skill_provider
17  * @author Jianfeng Gao ( jianfeng dot gao 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 
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 
35 
36 
38 {
39 
40  const std::string
41  Component::defaultName = "retrieve_hand_skill_provider";
42 
43 
46  {
47  ::armarx::PropertyDefinitionsPtr def = new ::armarx::ComponentPropertyDefinitions(getConfigIdentifier());
48 
49  def->component(remote.robotUnit, "Armar7Unit");
50  def->optional(properties.retrieveHandSkillProviderName, "retrieveHandSkillProvider");
51  // Publish to a topic (passing the TopicListenerPrx).
52  // def->topic(myTopicListener);
53 
54  // Subscribe to a topic (passing the topic name).
55  // def->topic<PlatformUnitListener>("MyTopic");
56 
57  // Use (and depend on) another component (passing the ComponentInterfacePrx).
58  // def->component(myComponentProxy)
59 
60 
61  // Add a required property. (The component won't start without a value being set.)
62  // def->required(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
63 
64  // Add an optional property.
65  // def->optional(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
66  // def->optional(properties.numBoxes, "p.box.Number", "Number of boxes to draw in ArViz.");
67 
68  return def;
69  }
70 
71 
72  void
74  {
75  // Topics and properties defined above are automagically registered.
76 
77  // Keep debug observer data until calling `sendDebugObserverBatch()`.
78  // (Requires the armarx::DebugObserverComponentPluginUser.)
79  // setDebugObserverBatchModeEnabled(true);
80  }
81 
82 
83  void
85  {
86  // Do things after connecting to topics and components.
87 
88  namespace rh = ::armarx::control::retrieve_hand::skills;
89 
90 
91  rh::RetrieveHand::Remote r;
92 
93  // r.arviz = this->arviz;
94  r.robotUnit = remote.robotUnit;
95  r.memoryNameSystem = memoryNameSystem();
96 
97  // rh::skills::RetrieveHand::Properties p;
98  // p.robotName =
99  // = properties.retrieveHandSkillProviderName;
100  // p.viewSelectionSkillProviderName = properties.viewSelectionSkillProviderName;
101 
102  // addSkillFactory<ho::skills::HandOverObjectToHuman>(r, p);
103 
104  // Option 1: Simply add a new instance of the skill.
105  addSkillFactory<rh::RetrieveHand>(r);
106  /* Option 2: Initialize skill after creation, e.g. set parameters, pass remote proxies.
107  {
108  skills::RetrieveHand* skill = addSkill<skills::RetrieveHand>();
109  skill->connectTo(...);
110  }
111  */
112 
113  /* (Requires the armarx::DebugObserverComponentPluginUser.)
114  // Use the debug observer to log data over time.
115  // The data can be viewed in the ObserverView and the LivePlotter.
116  // (Before starting any threads, we don't need to lock mutexes.)
117  {
118  setDebugObserverDatafield("numBoxes", properties.numBoxes);
119  setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
120  sendDebugObserverBatch();
121  }
122  */
123 
124  /* (Requires the armarx::ArVizComponentPluginUser.)
125  // Draw boxes in ArViz.
126  // (Before starting any threads, we don't need to lock mutexes.)
127  drawBoxes(properties, arviz);
128  */
129 
130  /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
131  // Setup the remote GUI.
132  {
133  createRemoteGuiTab();
134  RemoteGui_startRunningTask();
135  }
136  */
137  }
138 
139 
140  void
142  {
143  }
144 
145 
146  void
148  {
149  }
150 
151 
152  std::string
154  {
155  return Component::defaultName;
156  }
157 
158 
159  std::string
161  {
162  return Component::defaultName;
163  }
164 
165 
166  /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
167  void
168  Component::createRemoteGuiTab()
169  {
170  using namespace armarx::RemoteGui::Client;
171 
172  // Setup the widgets.
173 
174  tab.boxLayerName.setValue(properties.boxLayerName);
175 
176  tab.numBoxes.setValue(properties.numBoxes);
177  tab.numBoxes.setRange(0, 100);
178 
179  tab.drawBoxes.setLabel("Draw Boxes");
180 
181  // Setup the layout.
182 
183  GridLayout grid;
184  int row = 0;
185  {
186  grid.add(Label("Box Layer"), {row, 0}).add(tab.boxLayerName, {row, 1});
187  ++row;
188 
189  grid.add(Label("Num Boxes"), {row, 0}).add(tab.numBoxes, {row, 1});
190  ++row;
191 
192  grid.add(tab.drawBoxes, {row, 0}, {2, 1});
193  ++row;
194  }
195 
196  VBoxLayout root = {grid, VSpacer()};
197  RemoteGui_createTab(getName(), root, &tab);
198  }
199 
200 
201  void
202  Component::RemoteGui_update()
203  {
204  if (tab.boxLayerName.hasValueChanged() || tab.numBoxes.hasValueChanged())
205  {
206  std::scoped_lock lock(propertiesMutex);
207  properties.boxLayerName = tab.boxLayerName.getValue();
208  properties.numBoxes = tab.numBoxes.getValue();
209 
210  {
211  setDebugObserverDatafield("numBoxes", properties.numBoxes);
212  setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
213  sendDebugObserverBatch();
214  }
215  }
216  if (tab.drawBoxes.wasClicked())
217  {
218  // Lock shared variables in methods running in separate threads
219  // and pass them to functions. This way, the called functions do
220  // not need to think about locking.
221  std::scoped_lock lock(propertiesMutex);
222  drawBoxes(properties, arviz);
223  }
224  }
225  */
226 
227 
228  /* (Requires the armarx::ArVizComponentPluginUser.)
229  void
230  Component::drawBoxes(const Component::Properties& p, viz::Client& arviz)
231  {
232  // Draw something in ArViz (requires the armarx::ArVizComponentPluginUser.
233  // See the ArVizExample in RobotAPI for more examples.
234 
235  viz::Layer layer = arviz.layer(p.boxLayerName);
236  for (int i = 0; i < p.numBoxes; ++i)
237  {
238  layer.add(viz::Box("box_" + std::to_string(i))
239  .position(Eigen::Vector3f(i * 100, 0, 0))
240  .size(20).color(simox::Color::blue()));
241  }
242  arviz.commit(layer);
243  }
244  */
245 
246 
248 
249 } // namespace armarx::control::components::retrieve_hand_skill_provider
RetrieveHand.h
armarx::control::components::retrieve_hand_skill_provider::ARMARX_REGISTER_COMPONENT_EXECUTABLE
ARMARX_REGISTER_COMPONENT_EXECUTABLE(Component, Component::GetDefaultName())
armarx::control::components::retrieve_hand_skill_provider::Component::onExitComponent
void onExitComponent() override
Definition: Component.cpp:147
armarx::armem::client::plugins::PluginUser::memoryNameSystem
MemoryNameSystem & memoryNameSystem()
Definition: PluginUser.cpp:22
armarx::control::components::retrieve_hand_skill_provider::Component::onDisconnectComponent
void onDisconnectComponent() override
Definition: Component.cpp:141
armarx::control::components::retrieve_hand_skill_provider::Component::GetDefaultName
static std::string GetDefaultName()
Get the component's default name.
Definition: Component.cpp:160
Component.h
armarx::control::components::retrieve_hand_skill_provider
Definition: Component.cpp:37
armarx::control::components::retrieve_hand_skill_provider::Component::getDefaultName
std::string getDefaultName() const override
Definition: Component.cpp:153
armarx::control::components::retrieve_hand_skill_provider::Component
Definition: Component.h:46
armarx::control::components::retrieve_hand_skill_provider::Component::createPropertyDefinitions
::armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: Component.cpp:45
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
Decoupled.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::control::components::retrieve_hand_skill_provider::Component::onConnectComponent
void onConnectComponent() override
Definition: Component.cpp:84
armarx::control::components::retrieve_hand_skill_provider::Component::onInitComponent
void onInitComponent() override
Definition: Component.cpp:73