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
43
44namespace armarx
45{
46 DEFINEEVENT(EvAbort)
47
53
54 std::string
56 {
57 return "StatechartExecutorExample";
58 }
59
60 void
62 {
63 usingProxy("SimpleStatechartExecutor");
64 usingProxy("RemoteGuiProvider");
65 }
66
67 void
69 {
70 getProxy(_statechartExecutor, "SimpleStatechartExecutor");
71
72 getProxy(_remoteGuiPrx, "RemoteGuiProvider");
73 _tabName = "StatechartExecutorExample";
74 setupRemoteGuiWidget();
75 _remoteGuiTab = RemoteGui::TabProxy(_remoteGuiPrx, _tabName);
76
77 _remoteGuiTask = new RunningTask<StatechartExecutorExample>(
78 this, &StatechartExecutorExample::runRemoteGui);
79 _remoteGuiTask->start();
80 }
81
82 void
86
87 void
91
98
99 using namespace RemoteGui;
100
101 void
102 StatechartExecutorExample::setupRemoteGuiWidget()
103 {
104 auto grid = makeSimpleGridLayout("Layout").cols(3);
105
106 WidgetPtr test0Button = makeButton("Test_normal");
107 grid.addChild(test0Button);
108 WidgetPtr test1Button = makeButton("Test_args");
109 grid.addChild(test1Button);
110 WidgetPtr test2Button = makeButton("Test_wrongProxy");
111 grid.addChild(test2Button);
112
113 auto hlayout = makeHBoxLayout("HLayout");
114 hlayout.addChild(grid);
115
116 WidgetPtr stopButton = makeButton("Stop").label("Stop!!");
117 hlayout.addChild(stopButton);
118
119 auto manualLayout = makeSimpleGridLayout("manualLayout").cols(2);
120 WidgetPtr label1 = makeLabel("ProxyName").value("ProxyName");
121 manualLayout.addChild(label1);
122 WidgetPtr lineedit1 = makeLineEdit("ProxyEdit");
123 manualLayout.addChild(lineedit1);
124 WidgetPtr label2 = makeLabel("StateName").value("StateName");
125 manualLayout.addChild(label2);
126 WidgetPtr lineedit2 = makeLineEdit("StateEdit");
127 manualLayout.addChild(lineedit2);
128 WidgetPtr runManual = makeButton("Run");
129 manualLayout.addChild(runManual);
130
131 auto vlayout = makeVBoxLayout("VLayout");
132 vlayout.addChildren({hlayout, manualLayout});
133
134 _remoteGuiPrx->createTab(_tabName, vlayout);
135 }
136
137 void
138 StatechartExecutorExample::runRemoteGui()
139 {
140 int cycleDurationMs = 20;
141 CycleUtil c(cycleDurationMs);
142 while (!_remoteGuiTask->isStopped())
143 {
144 _remoteGuiTab.receiveUpdates();
145
146 if (_remoteGuiTab.getButton("Stop").clicked())
147 {
148 _statechartExecutor->stopImmediatly();
149
150 auto output = _statechartExecutor->getSetOutputParameters();
151 for (const auto& p : output)
152 {
153 SingleVariantPtr var = SingleVariantPtr::dynamicCast(p.second);
154 ARMARX_INFO << p.first << ": " << var->get()->getOutputValueOnly();
155 }
156 }
157
158 if (_remoteGuiTab.getButton("Test_normal").clicked())
159 {
160 std::string proxyName = "StatechartExecutionGroupRemoteStateOfferer";
161 std::string stateName = "TestStateForStatechartExecution";
162
163
164 StateParameterMap inputMap;
165 PosePtr p = new Pose();
166 // StateParameterPtr param = StateParameter::create();
167 // param->value = new SingleVariant(p);
168 // param->set = true;
169 // inputMap["bla2"] = param;
170
172 param2->value = new SingleVariant(1);
173 param2->set = true;
174 inputMap["intTest"] = param2;
175
176 std::vector<PosePtr> v;
177 v.push_back(p);
179 param3->value = SingleTypeVariantList::FromStdVector(v);
180 param3->set = true;
181 inputMap["intListTest"] = param3;
182
183 std::map<std::string, PosePtr> m;
184 m["a"] = p;
185 m["b"] = p;
187 param4->value = StringValueMap::FromStdMap<PosePtr>(m);
188 param4->set = true;
189 inputMap["poseMapTest"] = param4;
190
191 _statechartExecutor->ensureVariantLibrariesAreLoaded(inputMap);
192 _statechartExecutor->startStatechart(proxyName, stateName, inputMap);
193
194 // StatechartExecutionResult result = _statechartExecutor->waitUntilStatechartExecutionIsFinished();
195 // ARMARX_INFO << VAROUT(result);
196 // StringVariantContainerBaseMap output = _statechartExecutor->getSetOutputParameters();
197
198
199 // int outInt = SingleVariantPtr::dynamicCast(output["OutputInt"])->get()->get<int>();
200 // ARMARX_INFO << VAROUT(outInt);
201
202 // PosePtr pose = SingleVariantPtr::dynamicCast(output["OutputPose"])->get()->get<Pose>();
203 // ARMARX_INFO << VAROUT(pose);
204 }
205
206 if (_remoteGuiTab.getButton("Test_args").clicked())
207 {
208 }
209
210 if (_remoteGuiTab.getButton("Test_wrongProxy").clicked())
211 {
212 StringVariantContainerBaseMap output =
213 _statechartExecutor->getSetOutputParameters();
214 if (!output.empty())
215 {
216 int outInt =
217 SingleVariantPtr::dynamicCast(output["OutputInt"])->get()->get<int>();
218 ARMARX_INFO << VAROUT(outInt);
219 }
220 }
221
222 if (_remoteGuiTab.getButtonClicked("Run"))
223 {
224 }
225
226 _remoteGuiTab.sendUpdates();
227 c.waitForCycleDuration();
228 }
229 }
230
232} // namespace armarx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
#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()
Brief description of class StatechartExecutorExample.
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