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 
42 namespace armarx
43 {
44  DEFINEEVENT(EvAbort)
45 
47  std::string prefix) :
49  {
50  }
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
82  {
83  }
84 
85  void
87  {
88  }
89 
92  {
95  }
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
armarx::StatechartExecutorExample::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: StatechartExecutorExample.cpp:91
armarx::RemoteGui::makeVBoxLayout
detail::VBoxLayoutBuilder makeVBoxLayout(std::string const &name="")
Definition: LayoutWidgets.h:286
SingleTypeVariantList.h
armarx::RemoteGui::makeHBoxLayout
detail::HBoxLayoutBuilder makeHBoxLayout(std::string const &name="")
Definition: LayoutWidgets.h:268
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:52
armarx::PosePtr
IceInternal::Handle< Pose > PosePtr
Definition: Pose.h:306
armarx::RemoteGui::makeLabel
detail::LabelBuilder makeLabel(std::string const &name)
Definition: StaticWidgets.h:18
Pose.h
WidgetBuilder.h
armarx::RemoteGui::makeLineEdit
detail::LineEditBuilder makeLineEdit(std::string const &name)
Definition: StringWidgets.h:55
Storage.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
StateUtilFunctions.h
StateParameter.h
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:36
armarx::RemoteGui::makeSimpleGridLayout
detail::SimpleGridLayoutBuilder makeSimpleGridLayout(std::string const &name="")
Definition: LayoutWidgets.h:274
armarx::StatechartExecutorExample::onConnectComponent
virtual void onConnectComponent() override
Definition: StatechartExecutorExample.cpp:66
Statechart.h
armarx::SingleVariantPtr
IceInternal::Handle< SingleVariant > SingleVariantPtr
Definition: VariantContainer.h:50
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
StringValueMap.h
armarx::StatechartExecutorExample::onExitComponent
virtual void onExitComponent() override
Definition: StatechartExecutorExample.cpp:86
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:84
armarx::RemoteGui::detail::LabelMixin::label
Derived & label(std::string const &label)
Definition: Basic.h:216
armarx::SingleTypeVariantList::FromStdVector
static SingleTypeVariantListPtr FromStdVector(const std::vector< T1 > &vec)
Definition: SingleTypeVariantList.h:132
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:67
CycleUtil.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
StateBase.h
armarx::StatechartExecutorExamplePropertyDefinitions
Definition: StatechartExecutorExample.h:39
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:69
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
std
Definition: Application.h:66
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:198
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RemoteGui::detail::SimpleGridLayoutBuilder::cols
SimpleGridLayoutBuilder & cols(int n)
Definition: LayoutWidgets.h:123
armarx::StatechartExecutorExample::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: StatechartExecutorExample.cpp:81
armarx::StatechartExecutorExample::onInitComponent
virtual void onInitComponent() override
Definition: StatechartExecutorExample.cpp:59
armarx::StateParameter::create
static StateParameterPtr create()
Definition: StateParameter.cpp:59
StateUtil.h
armarx::StateParameterPtr
IceInternal::Handle< StateParameter > StateParameterPtr
Definition: StateParameter.h:32
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::StatechartExecutorExample::getDefaultName
virtual std::string getDefaultName() const override
Definition: StatechartExecutorExample.cpp:53
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:407
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:154
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27