StatechartExecutorExample.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 ArmarXGui::ArmarXObjects::StatechartExecutorExample
17 * @author Stefan Reither ( stefan dot reither at kit dot edu )
18 * @date 2019
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26#include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h>
36
39
41
42namespace armarx
43{
44 DEFINEEVENT(EvAbort)
45
51
52 std::string
54 {
55 return "StatechartExecutorExample";
56 }
57
58 void
60 {
61 usingProxy("SimpleStatechartExecutor");
62 usingProxy("RemoteGuiProvider");
63 }
64
65 void
67 {
68 getProxy(_statechartExecutor, "SimpleStatechartExecutor");
69
70 getProxy(_remoteGuiPrx, "RemoteGuiProvider");
71 _tabName = "StatechartExecutorExample";
72 setupRemoteGuiWidget();
73 _remoteGuiTab = RemoteGui::TabProxy(_remoteGuiPrx, _tabName);
74
75 _remoteGuiTask = new RunningTask<StatechartExecutorExample>(
76 this, &StatechartExecutorExample::runRemoteGui);
77 _remoteGuiTask->start();
78 }
79
80 void
84
85 void
89
96
97 using namespace RemoteGui;
98
99 void
100 StatechartExecutorExample::setupRemoteGuiWidget()
101 {
102 auto grid = makeSimpleGridLayout("Layout").cols(3);
103
104 WidgetPtr test0Button = makeButton("Test_normal");
105 grid.addChild(test0Button);
106 WidgetPtr test1Button = makeButton("Test_args");
107 grid.addChild(test1Button);
108 WidgetPtr test2Button = makeButton("Test_wrongProxy");
109 grid.addChild(test2Button);
110
111 auto hlayout = makeHBoxLayout("HLayout");
112 hlayout.addChild(grid);
113
114 WidgetPtr stopButton = makeButton("Stop").label("Stop!!");
115 hlayout.addChild(stopButton);
116
117 auto manualLayout = makeSimpleGridLayout("manualLayout").cols(2);
118 WidgetPtr label1 = makeLabel("ProxyName").value("ProxyName");
119 manualLayout.addChild(label1);
120 WidgetPtr lineedit1 = makeLineEdit("ProxyEdit");
121 manualLayout.addChild(lineedit1);
122 WidgetPtr label2 = makeLabel("StateName").value("StateName");
123 manualLayout.addChild(label2);
124 WidgetPtr lineedit2 = makeLineEdit("StateEdit");
125 manualLayout.addChild(lineedit2);
126 WidgetPtr runManual = makeButton("Run");
127 manualLayout.addChild(runManual);
128
129 auto vlayout = makeVBoxLayout("VLayout");
130 vlayout.addChildren({hlayout, manualLayout});
131
132 _remoteGuiPrx->createTab(_tabName, vlayout);
133 }
134
135 void
136 StatechartExecutorExample::runRemoteGui()
137 {
138 int cycleDurationMs = 20;
139 CycleUtil c(cycleDurationMs);
140 while (!_remoteGuiTask->isStopped())
141 {
142 _remoteGuiTab.receiveUpdates();
143
144 if (_remoteGuiTab.getButton("Stop").clicked())
145 {
146 _statechartExecutor->stopImmediatly();
147
148 auto output = _statechartExecutor->getSetOutputParameters();
149 for (const auto& p : output)
150 {
151 SingleVariantPtr var = SingleVariantPtr::dynamicCast(p.second);
152 ARMARX_INFO << p.first << ": " << var->get()->getOutputValueOnly();
153 }
154 }
155
156 if (_remoteGuiTab.getButton("Test_normal").clicked())
157 {
158 std::string proxyName = "StatechartExecutionGroupRemoteStateOfferer";
159 std::string stateName = "TestStateForStatechartExecution";
160
161
162 StateParameterMap inputMap;
163 PosePtr p = new Pose();
164 // StateParameterPtr param = StateParameter::create();
165 // param->value = new SingleVariant(p);
166 // param->set = true;
167 // inputMap["bla2"] = param;
168
170 param2->value = new SingleVariant(1);
171 param2->set = true;
172 inputMap["intTest"] = param2;
173
174 std::vector<PosePtr> v;
175 v.push_back(p);
177 param3->value = SingleTypeVariantList::FromStdVector(v);
178 param3->set = true;
179 inputMap["intListTest"] = param3;
180
181 std::map<std::string, PosePtr> m;
182 m["a"] = p;
183 m["b"] = p;
185 param4->value = StringValueMap::FromStdMap<PosePtr>(m);
186 param4->set = true;
187 inputMap["poseMapTest"] = param4;
188
189 _statechartExecutor->ensureVariantLibrariesAreLoaded(inputMap);
190 _statechartExecutor->startStatechart(proxyName, stateName, inputMap);
191
192 // StatechartExecutionResult result = _statechartExecutor->waitUntilStatechartExecutionIsFinished();
193 // ARMARX_INFO << VAROUT(result);
194 // StringVariantContainerBaseMap output = _statechartExecutor->getSetOutputParameters();
195
196
197 // int outInt = SingleVariantPtr::dynamicCast(output["OutputInt"])->get()->get<int>();
198 // ARMARX_INFO << VAROUT(outInt);
199
200 // PosePtr pose = SingleVariantPtr::dynamicCast(output["OutputPose"])->get()->get<Pose>();
201 // ARMARX_INFO << VAROUT(pose);
202 }
203
204 if (_remoteGuiTab.getButton("Test_args").clicked())
205 {
206 }
207
208 if (_remoteGuiTab.getButton("Test_wrongProxy").clicked())
209 {
210 StringVariantContainerBaseMap output =
211 _statechartExecutor->getSetOutputParameters();
212 if (!output.empty())
213 {
214 int outInt =
215 SingleVariantPtr::dynamicCast(output["OutputInt"])->get()->get<int>();
216 ARMARX_INFO << VAROUT(outInt);
217 }
218 }
219
220 if (_remoteGuiTab.getButtonClicked("Run"))
221 {
222 }
223
224 _remoteGuiTab.sendUpdates();
225 c.waitForCycleDuration();
226 }
227 }
228} // namespace armarx
#define DEFINEEVENT(NEWEVENT)
this macro declares a new event-class derived vom Event, to have a compiletime check for typos in eve...
#define VAROUT(x)
constexpr T c
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
static SingleTypeVariantListPtr FromStdVector(const std::vector< T1 > &vec)
static StateParameterPtr create()
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
virtual std::string getDefaultName() const override
static StringValueMapPtr FromStdMap(const std::map< std::string, Type > &map)
FromStdMap creates a StringValueMap from a std::map<std::string, Type>.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
detail::VBoxLayoutBuilder makeVBoxLayout(std::string const &name="")
detail::HBoxLayoutBuilder makeHBoxLayout(std::string const &name="")
detail::SimpleGridLayoutBuilder makeSimpleGridLayout(std::string const &name="")
detail::ButtonBuilder makeButton(std::string const &name)
detail::LabelBuilder makeLabel(std::string const &name)
detail::LineEditBuilder makeLineEdit(std::string const &name)
double v(double t, double v0, double a0, double j)
Definition CtrlUtil.h:39
Eigen::Isometry3f Pose
Definition basic_types.h:31
QMap< QString, StateParameterPtr > StateParameterMap
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< StateParameter > StateParameterPtr
IceInternal::Handle< SingleVariant > SingleVariantPtr
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Derived & label(std::string const &label)
Definition Basic.h:216
Derived & value(ValueT const &value)
Definition Basic.h:84