StatechartEditorController.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <QFileSystemWatcher>
27
31
35
37#include "StateTreeController.h"
38
39namespace armarx
40{
42
43 /**
44 \page ArmarXGui-GuiPlugins-StatechartEditorController StatechartEditor
45 \tableofcontents
46
47 The Statechart Editor is a powerful and convenient tool to design complex behavior.
48 It is deeply integrated into ArmarX and tailored onto it.
49 It allows the user to design hierarchical, distributed statecharts inspired by Harel, 84 [1] in
50 a graphical way and generate and connect it directly with C++ code.
51 For a step-by-step tutorial refer to: \ref ArmarXCore-Tutorials-sce
52
53 A detailed explanation of ArmarX Statecharts can be found in the publication:<br/>
54 M. Wächter, S. Ottenhaus, M. Kröhnert, N. Vahrenkamp and T. Asfour (2016), *The ArmarX Statechart Concept: Graphical Programming of Robot Behaviour*, Front. Robot. AI 3:33.
55 <a href="http://journal.frontiersin.org/article/10.3389/frobt.2016.00033/full">[DOI]</a>
56
57 [1]: David Harel: *Statecharts: A Visual Approach to Complex Systems*, CS84-05, Department of Applied Mathematics, The Weizmann Institute of Science, 1984
58
59 \image html StatechartEditor.png
60
61 \see \ref Statechart
62 \see \ref ArmarXGui-GuiPlugins-StatechartViewer
63 \see \ref RobotSkillTemplates
64 \see \ref StatechartEditorController
65 \see \ref ArmarXGui-GuiPlugins-EventSender
66 \see \ref ArmarXCore-Tutorials-sce
67
68 \section SCE-Group-Execution Statechart Execution from the Statechart Editor
69 Statecharts are always executed as part of their statechart group.
70 There are two different ways to execute a statechart group:
71 \li <b>From the Statechart Editor directly:</b> In the context menu of the statechart group it is possible
72 to execute a statechart group directly. This option is meant for quick testing of statecharts. All statechart group dependencies
73 are automatically also executed (they need to be loaded in the current session of the Statechart Editor for this).
74 Before execution a public state that should immediately be entered can be selected. Note
75 that this state must not need any input paramters.
76 \li <b>Starting a statechart group with a scenario:</b> The usual way to start a statechart group is as part of
77 a scenario. For this option, it is possible to drag'n'drop a statechart group from the Statechart Editor to the \ref ArmarXGui-GuiPlugins-ScenarioManagerGuiPlugin "/ScenarioManager.conf".
78 The statechart group needs to be dropped on an open scenario. It is then fully parameterized and ready to be started.
79 Note that for this option all statechart group dependencies need to be added to the scenario manually as well.
80 In the properties of the statechart group it is possible to define a set of state that should be entered automatically. These states will run in parallel.
81
82 \section SCE-Intro Statechart Editor Intro: Making Armar wave in 4 minutes
83 In this video, the Statechart Editor used to program a simple
84 statechart that makes Armar3 wave. This demonstrates the basic features of the Statechart Editor.
85 There was nothing prepared except starting the simulation and getting the needed joint values for the arm joints.
86 \htmlonly
87 <video width="700" controls>
88 <source src="images/SCE-intro-2016-03-25_17.38.00.mp4" type="video/mp4">
89 Your browser does not support HTML5 video.
90 </video>
91 \endhtmlonly
92
93 \section SCE-Configurations Editing the runtime configuration of a statechart group
94 Statecharts groups need like component often parameters to work with one specific robot.
95 For statechart groups this can be done with the Statechart Editor. In this video, it is shown
96 how to setup the configuration for one group. This configuration is then always applied when starting
97 the statechart group.
98 \htmlonly
99 <video width="700" controls>
100 <source src="images/SCE-configurations-2016-03-24_03.13.42.mp4" type="video/mp4">
101 Your browser does not support HTML5 video.
102 </video>
103 \endhtmlonly
104
105 \section SCE-GroupCloning Cloning a statechart group to another package
106 \htmlonly
107 <video width="700" controls>
108 <source src="images/SCE-cloning-2016-03-24_03.50.53.mp4" type="video/mp4">
109 Your browser does not support HTML5 video.
110 </video>
111 \endhtmlonly
112
113
114 \section SCE-DirectMapping Direct mapping of parameters during transitions
115 \htmlonly
116 <video width="700" controls>
117 <source src="images/SCE-directvaluemapping-2016-03-30_23.44.26.mp4" type="video/mp4">
118 Your browser does not support HTML5 video.
119 </video>
120 \endhtmlonly
121
122
123 */
124
125
126 /**
127 \class StatechartEditorController
128 \brief The StatechartEditorController class is the controller of the main widget of the Statechart Editor.
129 */
131 public ArmarXComponentWidgetControllerTemplate<StatechartEditorController>
132 {
133 Q_OBJECT
134
135 public:
138
139 QStringList findAllStatechartGroupDefinitions(const QString& basePath);
140
141 public slots:
142 void treeviewGroupsDoubleClicked(QModelIndex index);
143 void requestSave();
144 void onStateTabChanged(int index);
147 void searchAndOpenPaths(QStringList paths);
148
149 void connectToView(int tabIndex);
151 void showCodeFileContent(const QString& path);
152 void showOnEnterFunction();
153 void showRunFunction();
154 void showOnBreakFunction();
155 void showOnExitFunction();
156 void openSelectedState();
157 void closeAllTabs();
158 void executeOpenedState(bool);
159
160 public:
161 // inherited from Component
162 void onInitComponent() override;
163 void onConnectComponent() override;
164 void onDisconnectComponent() override;
165 void onExitComponent() override;
166
167 // inherited of ArmarXWidget
168 static QString
170 {
171 return "Statecharts.StatechartEditor";
172 }
173
174 static QIcon
176 {
177 return QIcon(":/statechart-editor/states.svg");
178 }
179
180 static QIcon
182 {
183 return QIcon(":/statechart-editor/states.svg");
184 }
185
186 void loadSettings(QSettings* settings) override;
187 void saveSettings(QSettings* settings) override;
188
189 // ArmarXWidgetController interface
190 QPointer<QWidget> getWidget() override;
191 void openStatechartGroups(QStringList groups);
192 private slots:
193 void initWidget();
194
195 private:
196 void updateExecutionButtonStatus();
197 void watchState(const std::string& objName);
198 QPointer<StatechartEditorMainWindow> editor;
199 StateEditorControllerPtr stateEditorController;
200 StateTreeControllerPtr treeController;
202 QFileSystemWatcher* watcher;
203 StateWatcherPtr stateWatcher;
204 bool alreadyWatchingState = false;
205 VariantInfoPtr variantInfo;
206 StatechartProfilesPtr profiles;
207 QPointer<StatechartEditorConfigDialog> dialog;
208 StatechartGroupPtr executedOpenedGroup;
210 // ArmarXWidgetController interface
211 public:
212 QPointer<QDialog> getConfigDialog(QWidget* parent) override;
213
222
223 // ArmarXWidgetController interface
224 bool onClose() override;
225 void configured() override;
227 };
228
229} // namespace armarx
uint8_t index
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
void onInitComponent() override
Pure virtual hook for the subclass.
bool onClose() override
If you overwrite this method, make sure to call this implementation at the end of your implementation...
void onDisconnectComponent() override
Hook for subclass.
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
void showStateCode(statechartmodel::StateInstancePtr stateInstance)
QStringList findAllStatechartGroupDefinitions(const QString &basePath)
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
void onConnectComponent() override
Pure virtual hook for the subclass.
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
void onExitComponent() override
Hook for subclass.
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
struct armarx::StatechartEditorController::Config config
std::shared_ptr< StateInstance > StateInstancePtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< StatechartProfiles > StatechartProfilesPtr
std::shared_ptr< StatechartGroup > StatechartGroupPtr
std::shared_ptr< StateEditorController > StateEditorControllerPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition VariantInfo.h:39
std::shared_ptr< class StatechartProfile > StatechartProfilePtr
IceInternal::Handle< StateWatcher > StateWatcherPtr
std::shared_ptr< StateTreeController > StateTreeControllerPtr
std::shared_ptr< ArmarXPackageToolInterface > ArmarXPackageToolInterfacePtr