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 
26 
31 
33 
34 
36 
37 #include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h>
42 
44 
45 namespace armarx
46 {
47  DEFINEEVENT(EvAbort)
48 
51  {
52 
53  }
54 
55 
57  {
58  return "StatechartExecutorExample";
59  }
60 
61 
63  {
64  usingProxy("SimpleStatechartExecutor");
65  usingProxy("RemoteGuiProvider");
66  }
67 
68 
70  {
71  getProxy(_statechartExecutor, "SimpleStatechartExecutor");
72 
73  getProxy(_remoteGuiPrx, "RemoteGuiProvider");
74  _tabName = "StatechartExecutorExample";
75  setupRemoteGuiWidget();
76  _remoteGuiTab = RemoteGui::TabProxy(_remoteGuiPrx, _tabName);
77 
78  _remoteGuiTask = new RunningTask<StatechartExecutorExample>(this, &StatechartExecutorExample::runRemoteGui);
79  _remoteGuiTask->start();
80  }
81 
82 
84  {
85 
86  }
87 
88 
90  {
91 
92  }
93 
94 
96  {
99  }
100 
101  using namespace RemoteGui;
102  void 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 StatechartExecutorExample::runRemoteGui()
138  {
139  int cycleDurationMs = 20;
140  CycleUtil c(cycleDurationMs);
141  while (!_remoteGuiTask->isStopped())
142  {
143  _remoteGuiTab.receiveUpdates();
144 
145  if (_remoteGuiTab.getButton("Stop").clicked())
146  {
147  _statechartExecutor->stopImmediatly();
148 
149  auto output = _statechartExecutor->getSetOutputParameters();
150  for (const auto& p : output)
151  {
152  SingleVariantPtr var = SingleVariantPtr::dynamicCast(p.second);
153  ARMARX_INFO << p.first << ": " << var->get()->getOutputValueOnly();
154  }
155  }
156 
157  if (_remoteGuiTab.getButton("Test_normal").clicked())
158  {
159  std::string proxyName = "StatechartExecutionGroupRemoteStateOfferer";
160  std::string stateName = "TestStateForStatechartExecution";
161 
162 
163  StateParameterMap inputMap;
164  PosePtr p = new Pose();
165  // StateParameterPtr param = StateParameter::create();
166  // param->value = new SingleVariant(p);
167  // param->set = true;
168  // inputMap["bla2"] = param;
169 
171  param2->value = new SingleVariant(1);
172  param2->set = true;
173  inputMap["intTest"] = param2;
174 
175  std::vector<PosePtr> v;
176  v.push_back(p);
178  param3->value = SingleTypeVariantList::FromStdVector(v);
179  param3->set = true;
180  inputMap["intListTest"] = param3;
181 
182  std::map<std::string, PosePtr> m;
183  m["a"] = p;
184  m["b"] = p;
186  param4->value = StringValueMap::FromStdMap<PosePtr>(m);
187  param4->set = true;
188  inputMap["poseMapTest"] = param4;
189 
190  _statechartExecutor->ensureVariantLibrariesAreLoaded(inputMap);
191  _statechartExecutor->startStatechart(proxyName, stateName, inputMap);
192 
193  // StatechartExecutionResult result = _statechartExecutor->waitUntilStatechartExecutionIsFinished();
194  // ARMARX_INFO << VAROUT(result);
195  // StringVariantContainerBaseMap output = _statechartExecutor->getSetOutputParameters();
196 
197 
198  // int outInt = SingleVariantPtr::dynamicCast(output["OutputInt"])->get()->get<int>();
199  // ARMARX_INFO << VAROUT(outInt);
200 
201  // PosePtr pose = SingleVariantPtr::dynamicCast(output["OutputPose"])->get()->get<Pose>();
202  // ARMARX_INFO << VAROUT(pose);
203  }
204 
205  if (_remoteGuiTab.getButton("Test_args").clicked())
206  {
207 
208  }
209 
210  if (_remoteGuiTab.getButton("Test_wrongProxy").clicked())
211  {
212  StringVariantContainerBaseMap output = _statechartExecutor->getSetOutputParameters();
213  if (!output.empty())
214  {
215  int outInt = SingleVariantPtr::dynamicCast(output["OutputInt"])->get()->get<int>();
216  ARMARX_INFO << VAROUT(outInt);
217  }
218 
219  }
220 
221  if (_remoteGuiTab.getButtonClicked("Run"))
222  {
223 
224  }
225 
226  _remoteGuiTab.sendUpdates();
227  c.waitForCycleDuration();
228  }
229  }
230 }
armarx::StatechartExecutorExample::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: StatechartExecutorExample.cpp:95
armarx::RemoteGui::makeVBoxLayout
detail::VBoxLayoutBuilder makeVBoxLayout(std::string const &name="")
Definition: LayoutWidgets.h:245
SingleTypeVariantList.h
armarx::RemoteGui::makeHBoxLayout
detail::HBoxLayoutBuilder makeHBoxLayout(std::string const &name="")
Definition: LayoutWidgets.h:230
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::RemoteGui::makeButton
detail::ButtonBuilder makeButton(std::string const &name)
Definition: IntegerWidgets.h:48
armarx::PosePtr
IceInternal::Handle< Pose > PosePtr
Definition: Pose.h:306
armarx::RemoteGui::makeLabel
detail::LabelBuilder makeLabel(std::string const &name)
Definition: StaticWidgets.h:17
Pose.h
WidgetBuilder.h
armarx::RemoteGui::makeLineEdit
detail::LineEditBuilder makeLineEdit(std::string const &name)
Definition: StringWidgets.h:53
Storage.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
StateUtilFunctions.h
StateParameter.h
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::RemoteGui::makeSimpleGridLayout
detail::SimpleGridLayoutBuilder makeSimpleGridLayout(std::string const &name="")
Definition: LayoutWidgets.h:235
armarx::StatechartExecutorExample::onConnectComponent
virtual void onConnectComponent() override
Definition: StatechartExecutorExample.cpp:69
Statechart.h
armarx::SingleVariantPtr
IceInternal::Handle< SingleVariant > SingleVariantPtr
Definition: VariantContainer.h:51
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
StringValueMap.h
armarx::StatechartExecutorExample::onExitComponent
virtual void onExitComponent() override
Definition: StatechartExecutorExample.cpp:89
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
State.h
StatechartExecutorExample.h
armarx::RemoteGui::detail::ValueMixin::value
Derived & value(ValueT const &value)
Definition: Basic.h:77
armarx::RemoteGui::detail::LabelMixin::label
Derived & label(std::string const &label)
Definition: Basic.h:191
armarx::SingleTypeVariantList::FromStdVector
static SingleTypeVariantListPtr FromStdVector(const std::vector< T1 > &vec)
Definition: SingleTypeVariantList.h:125
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
CycleUtil.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
StateBase.h
armarx::StatechartExecutorExamplePropertyDefinitions
Definition: StatechartExecutorExample.h:41
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
std
Definition: Application.h:66
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteGui::detail::SimpleGridLayoutBuilder::cols
SimpleGridLayoutBuilder & cols(int n)
Definition: LayoutWidgets.h:108
armarx::StatechartExecutorExample::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: StatechartExecutorExample.cpp:83
armarx::StatechartExecutorExample::onInitComponent
virtual void onInitComponent() override
Definition: StatechartExecutorExample.cpp:62
armarx::StateParameter::create
static StateParameterPtr create()
Definition: StateParameter.cpp:58
StateUtil.h
armarx::StateParameterPtr
IceInternal::Handle< StateParameter > StateParameterPtr
Definition: StateParameter.h:31
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::StatechartExecutorExample::getDefaultName
virtual std::string getDefaultName() const override
Definition: StatechartExecutorExample.cpp:56
armarx::ManagedIceObject::getProxy
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Definition: ManagedIceObject.cpp:393
armarx::DEFINEEVENT
DEFINEEVENT(EvInit) struct StateRun
Variant.h
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28