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
38namespace viz = armarx::viz;
39
41{
42
43 const std::string ik_demo::defaultName = "IkDemo";
44
46 {
47 }
48
51 {
54
55 // Publish to a topic (passing the TopicListenerPrx).
56 // def->topic(myTopicListener);
57
58 // Subscribe to a topic (passing the topic name).
59 // def->topic<PlatformUnitListener>("MyTopic");
60
61 // Use (and depend on) another component (passing the ComponentInterfacePrx).
62 // def->component(myComponentProxy)
63
64 impl->defineProperties(*def);
65
66
67 // Add a required property. (The component won't start without a value being set.)
68 // def->required(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
69
70 // Add an optionalproperty.
71 // def->optional(properties.numBoxes, "p.box.Number", "Number of boxes to draw in ArViz.");
72
73 return def;
74 }
75
76 void
78 {
79 // Topics and properties defined above are automagically registered.
80
81 // Keep debug observer data until calling `sendDebugObserverBatch()`.
82 // (Requies the armarx::DebugObserverComponentPluginUser.)
83 // setDebugObserverBatchModeEnabled(true);
84 }
85
86 void
88 {
89 impl->remote.arviz = arviz;
90
91 task = new armarx::SimpleRunningTask<>([this]() { this->run(); });
92 task->start();
93
94 /* (Requies the armarx::DebugObserverComponentPluginUser.)
95 // Use the debug observer to log data over time.
96 // The data can be viewed in the ObserverView and the LivePlotter.
97 // (Before starting any threads, we don't need to lock mutexes.)
98 {
99 setDebugObserverDatafield("numBoxes", properties.numBoxes);
100 setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
101 sendDebugObserverBatch();
102 }
103 */
104
105 /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
106 // Setup the remote GUI.
107 {
108 createRemoteGuiTab();
109 RemoteGui_startRunningTask();
110 }
111 */
112 }
113
114 void
116 {
117 const bool join = true;
118 task->stop(join);
119 task = nullptr;
120 }
121
122 void
126
127 void
128 ik_demo::run()
129 {
130 impl->start();
131
132 armarx::CycleUtil cycle(10.0f);
133 while (!task->isStopped())
134 {
135 impl->update();
136
137 cycle.waitForCycleDuration();
138 }
139 }
140
141 std::string
143 {
144 return ik_demo::defaultName;
145 }
146
147 std::string
149 {
150 return ik_demo::defaultName;
151 }
152
153 /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
154 void
155 Component::createRemoteGuiTab()
156 {
157 using namespace armarx::RemoteGui::Client;
158
159 // Setup the widgets.
160
161 tab.boxLayerName.setValue(properties.boxLayerName);
162
163 tab.numBoxes.setValue(properties.numBoxes);
164 tab.numBoxes.setRange(0, 100);
165
166 tab.drawBoxes.setLabel("Draw Boxes");
167
168 // Setup the layout.
169
170 GridLayout grid;
171 int row = 0;
172 {
173 grid.add(Label("Box Layer"), {row, 0}).add(tab.boxLayerName, {row, 1});
174 ++row;
175
176 grid.add(Label("Num Boxes"), {row, 0}).add(tab.numBoxes, {row, 1});
177 ++row;
178
179 grid.add(tab.drawBoxes, {row, 0}, {2, 1});
180 ++row;
181 }
182
183 VBoxLayout root = {grid, VSpacer()};
184 RemoteGui_createTab(getName(), root, &tab);
185 }
186
187
188 void
189 Component::RemoteGui_update()
190 {
191 if (tab.boxLayerName.hasValueChanged() || tab.numBoxes.hasValueChanged())
192 {
193 std::scoped_lock lock(propertiesMutex);
194 properties.boxLayerName = tab.boxLayerName.getValue();
195 properties.numBoxes = tab.numBoxes.getValue();
196
197 {
198 setDebugObserverDatafield("numBoxes", properties.numBoxes);
199 setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
200 sendDebugObserverBatch();
201 }
202 }
203 if (tab.drawBoxes.wasClicked())
204 {
205 // Lock shared variables in methods running in seperate threads
206 // and pass them to functions. This way, the called functions do
207 // not need to think about locking.
208 std::scoped_lock lock(propertiesMutex, arvizMutex);
209 drawBoxes(properties, arviz);
210 }
211 }
212 */
213
214
215 // ARMARX_REGISTER_COMPONENT_EXECUTABLE(ik_demo, ik_demo::GetDefaultName());
216
217} // namespace armar6::skills::components::armar6_ik_demo
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition ik_demo.cpp:50
static std::string GetDefaultName()
Get the component's default name.
Definition ik_demo.cpp:148
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
This util class helps with keeping a cycle time during a control cycle.
Definition CycleUtil.h:41
bool isStopped()
Retrieve whether stop() has been called.
This file is part of ArmarX.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
SimpleRunningTask(Ts...) -> SimpleRunningTask< std::function< void(void)> >