ik_demo.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 skills::ArmarXObjects::armar6_ik_demo
17  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18  * @date 2022
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 #include "ik_demo.h"
25 
26 #include <Eigen/Core>
27 
28 #include <SimoxUtility/color/Color.h>
29 
30 // #include <ArmarXCore/libraries/DecoupledSingleComponent/Decoupled.h>
32 
34 
35 #include "IkDemo.h"
36 
37 
38 namespace viz = armarx::viz;
39 
40 
42 {
43 
44  const std::string
45  ik_demo::defaultName = "IkDemo";
46 
47 
48  ik_demo::ik_demo() : impl(new IkDemo)
49  {
50  }
51 
52 
55  {
57 
58  // Publish to a topic (passing the TopicListenerPrx).
59  // def->topic(myTopicListener);
60 
61  // Subscribe to a topic (passing the topic name).
62  // def->topic<PlatformUnitListener>("MyTopic");
63 
64  // Use (and depend on) another component (passing the ComponentInterfacePrx).
65  // def->component(myComponentProxy)
66 
67  impl->defineProperties(*def);
68 
69 
70  // Add a required property. (The component won't start without a value being set.)
71  // def->required(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
72 
73  // Add an optionalproperty.
74  // def->optional(properties.numBoxes, "p.box.Number", "Number of boxes to draw in ArViz.");
75 
76  return def;
77  }
78 
79 
80  void
82  {
83  // Topics and properties defined above are automagically registered.
84 
85  // Keep debug observer data until calling `sendDebugObserverBatch()`.
86  // (Requies the armarx::DebugObserverComponentPluginUser.)
87  // setDebugObserverBatchModeEnabled(true);
88  }
89 
90 
91  void
93  {
94  impl->remote.arviz = arviz;
95 
96  task = new armarx::SimpleRunningTask<>([this]() { this->run(); });
97  task->start();
98 
99  /* (Requies the armarx::DebugObserverComponentPluginUser.)
100  // Use the debug observer to log data over time.
101  // The data can be viewed in the ObserverView and the LivePlotter.
102  // (Before starting any threads, we don't need to lock mutexes.)
103  {
104  setDebugObserverDatafield("numBoxes", properties.numBoxes);
105  setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
106  sendDebugObserverBatch();
107  }
108  */
109 
110  /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
111  // Setup the remote GUI.
112  {
113  createRemoteGuiTab();
114  RemoteGui_startRunningTask();
115  }
116  */
117  }
118 
119 
120  void
122  {
123  const bool join = true;
124  task->stop(join);
125  task = nullptr;
126  }
127 
128 
129  void
131  {
132  }
133 
134 
135  void ik_demo::run()
136  {
137  impl->start();
138 
139  armarx::CycleUtil cycle(10.0f);
140  while (!task->isStopped())
141  {
142  impl->update();
143 
144  cycle.waitForCycleDuration();
145  }
146  }
147 
148 
149  std::string
151  {
152  return ik_demo::defaultName;
153  }
154 
155 
156  std::string
158  {
159  return ik_demo::defaultName;
160  }
161 
162 
163  /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
164  void
165  Component::createRemoteGuiTab()
166  {
167  using namespace armarx::RemoteGui::Client;
168 
169  // Setup the widgets.
170 
171  tab.boxLayerName.setValue(properties.boxLayerName);
172 
173  tab.numBoxes.setValue(properties.numBoxes);
174  tab.numBoxes.setRange(0, 100);
175 
176  tab.drawBoxes.setLabel("Draw Boxes");
177 
178  // Setup the layout.
179 
180  GridLayout grid;
181  int row = 0;
182  {
183  grid.add(Label("Box Layer"), {row, 0}).add(tab.boxLayerName, {row, 1});
184  ++row;
185 
186  grid.add(Label("Num Boxes"), {row, 0}).add(tab.numBoxes, {row, 1});
187  ++row;
188 
189  grid.add(tab.drawBoxes, {row, 0}, {2, 1});
190  ++row;
191  }
192 
193  VBoxLayout root = {grid, VSpacer()};
194  RemoteGui_createTab(getName(), root, &tab);
195  }
196 
197 
198  void
199  Component::RemoteGui_update()
200  {
201  if (tab.boxLayerName.hasValueChanged() || tab.numBoxes.hasValueChanged())
202  {
203  std::scoped_lock lock(propertiesMutex);
204  properties.boxLayerName = tab.boxLayerName.getValue();
205  properties.numBoxes = tab.numBoxes.getValue();
206 
207  {
208  setDebugObserverDatafield("numBoxes", properties.numBoxes);
209  setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
210  sendDebugObserverBatch();
211  }
212  }
213  if (tab.drawBoxes.wasClicked())
214  {
215  // Lock shared variables in methods running in seperate threads
216  // and pass them to functions. This way, the called functions do
217  // not need to think about locking.
218  std::scoped_lock lock(propertiesMutex, arvizMutex);
219  drawBoxes(properties, arviz);
220  }
221  }
222  */
223 
224 
225  // ARMARX_REGISTER_COMPONENT_EXECUTABLE(ik_demo, ik_demo::GetDefaultName());
226 
227 } // namespace armar6::skills::components::armar6_ik_demo
Client.h
armarx::SimpleRunningTask
Usage:
Definition: TaskUtil.h:70
armar6::skills::components::armar6_ik_demo::ik_demo::onConnectComponent
void onConnectComponent() override
Definition: ik_demo.cpp:92
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armar6::skills::components::armar6_ik_demo::ik_demo::onDisconnectComponent
void onDisconnectComponent() override
Definition: ik_demo.cpp:121
armar6::skills::components::armar6_ik_demo::ik_demo::onInitComponent
void onInitComponent() override
Definition: ik_demo.cpp:81
armar6::skills::components::armar6_ik_demo::IkDemo
Definition: IkDemo.h:16
CycleUtil.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
IkDemo.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::ArVizComponentPluginUser::arviz
armarx::viz::Client arviz
Definition: ArVizComponentPlugin.h:43
armar6::skills::components::armar6_ik_demo::ik_demo::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ik_demo.cpp:54
IceUtil::Handle< class PropertyDefinitionContainer >
armar6::skills::components::armar6_ik_demo::ik_demo::onExitComponent
void onExitComponent() override
Definition: ik_demo.cpp:130
armar6::skills::components::armar6_ik_demo::ik_demo::ik_demo
ik_demo()
Definition: ik_demo.cpp:48
armar6::skills::components::armar6_ik_demo::ik_demo::GetDefaultName
static std::string GetDefaultName()
Get the component's default name.
Definition: ik_demo.cpp:157
armar6::skills::components::armar6_ik_demo::ik_demo::getDefaultName
std::string getDefaultName() const override
Definition: ik_demo.cpp:150
armar6::skills::components::armar6_ik_demo
Definition: ComponentInterface.ice:27
armarx::viz
This file is part of ArmarX.
Definition: ArVizStorage.cpp:416
ik_demo.h