XMLStateComponent.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 ArmarX::
19 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 
30 //#include <ArmarXCore/statechart/StatechartContext.h>
31 //#include "XMLRemoteStateOfferer.h"
32 
33 #define STATEOFFERERSUFFIX "RemoteStateOfferer"
34 
35 namespace armarx
36 {
37 
38  struct XMLStateOffererFactoryBase;
40 
43  {
44  public:
47  {
48  defineRequiredProperty<std::string>("XMLStatechartGroupDefinitionFile", "Path to statechart group definition file (*.scgxml) - relative to projects' source dir");
49  defineOptionalProperty<std::string>("XMLStatechartProfile", "", "Profile to use for state execution. Should be the same for all Statechart Groups in one scenario. This profile name is also added as a prefix to the Ice identifier of the RemoteStateOfferer of this statechart group.");
50  defineOptionalProperty<std::string>("XMLRemoteStateOffererName", "", "Name of the RemoteStateOfferer to start. The default name is [StatechartGroupName]RemoteStateOfferer.");
51  defineOptionalProperty<std::string>("StatesToEnter", "", "List of states that are directly entered and executed. Seperated by comma. These must not need any input parameters!");
52  defineOptionalProperty<std::string>("StateReportingTopic", "StateReportingTopic", "Topic on which state changes are published. Leave empty to disable reporting.");
53  //defineOptionalProperty<std::string>("XMLStatechartProfileDefinitionFile", "", "Path to StatechartProfiles-<ProjectName>.xml file.");
54  }
55  };
56 
57  /**
58  * @defgroup Component-XMLStateComponent XMLStateComponent
59  * @ingroup ArmarXCore-Components StatechartGrp
60  * This component is the managing component for XML statechart groups offered with XMLRemoteStateOfferer.
61  * This component is used in the application *XMLRemoteStateOfferer*.
62  * It loads a statechart group from a XML file (defined in property XMLStatechartGroupDefinitionFile) and
63  * offers all contained public states via the XMLRemoteStateOfferer.
64  * The XMLRemoteStateOfferer is the remote interface to all public states of a statechart group.
65  *
66  * **Configuration:**
67  *
68  * Two properties of the XMLStateComponent are essential: *XMLStatechartGroupDefinitionFile* and *XMLStatechartProfile*.<br/>
69  * *XMLStatechartGroupDefinitionFile* is a required property and defines which statechart
70  * group (*.scgxml) is to be loaded. All public states
71  * will be available after start up for remote access.
72  * *XMLStatechartProfile* is an optional property which defines which \ref statechartprofiles "configuration profile"
73  * a statechart group should be used.
74  * This is usually a robot specific profile like *Armar3Simulation*.
75  * This profile contains two types of information:<br/>
76  * - information about the default parameters of each state
77  * - default configuration for the XMLRemoteStateOfferer, which consists mostly of
78  * proxy names like the KinematicUnit. This configuration can be overwritten
79  * with config files attached to the XMLStateComponent app.
80  * The profile name is also the prefix for the XMLRemoteStateOfferer network identifier,
81  * e.g. *Armar3SimulationGraspingGroupRemoteStateOfferer*. This way there can ba a RemoteStateOffer for each profile.
82  *
83  * Both types of information are stored in the statechart xml files and specified in the \ref ArmarXGui-GuiPlugins-StatechartEditorController "Statechart Editor".
84  *
85  * **Auto entering of states**:
86  *
87  * The property *StatesToEnter* specifies which *public* states are entered automatically on start up of the XMLComponent.
88  * These **must not** require any input parameters.
89  * It is also possible to specify multiple states by a comma-seperated list, which then will be run in parallel.
90  * (Though, event processing is not parallel.)
91  *
92  * **Configuration of a multi robot statechart setup:**
93  *
94  * It is easily possible to configure a statechart setup for multiple robots. You can just start multiple XMLStateComponent apps,
95  * choose a different profile for each app and a unique name for each of the XMLStateComponents (property *ArmarX.XMLStateComponent.objectName*).
96  *
97  * An example could look like this:
98  * \verbatim
99  config1.cfg:
100  ArmarX.XMLStateComponent.XMLStatechartGroupDefinitionFile = RobotSkillTemplates/statecharts/BringObjectGroup/BringObjectGroup.scgxml
101  ArmarX.XMLStateComponent.ObjectName = "XMLStateComponentBringObjectGroupArmar3a"
102  ArmarX.XMLStateComponent.XMLStatechartProfile=Armar3a
103 
104  config2.cfg:
105  ArmarX.XMLStateComponent.XMLStatechartGroupDefinitionFile = RobotSkillTemplates/statecharts/BringObjectGroup/BringObjectGroup.scgxml
106  ArmarX.XMLStateComponent.ObjectName = "XMLStateComponentBringObjectGroupArmar3b"
107  ArmarX.XMLStateComponent.XMLStatechartProfile=Armar3b
108  \endverbatim
109  * \note This does not work for usage of two robot with the same profile. Then the properties for
110  * the XMLRemoteStateOfferer need to be specified in the .cfg file as well.
111  *
112  * @class XMLStateComponent
113  * @ingroup Component-XMLStateComponent
114  */
116  public Component
117  {
118  public:
120 
121  // PropertyUser interface
123 
124 
125  // ManagedIceObject interface
126  bool loadLib(std::string libPath);
127  protected:
128  void onInitComponent() override;
129  void onConnectComponent() override;
130  std::string getDefaultName() const override;
131  void createAndEnterInstance(const std::string& stateClassName, bool useExisitingPrx = false);
132 
133  std::map<std::string, DynamicLibraryPtr> libraries;
134  std::string uuid;
135  std::string offererName;
136  std::string iceObjName;
140  private:
141  int stateIDStartedUsingExisitingPrx = -1;
142 
143  // ManagedIceObject interface
144  protected:
145  void onDisconnectComponent() override;
146  };
147 
148 }
149 
armarx::XMLStateComponent::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: XMLStateComponent.cpp:149
armarx::XMLStateComponent
Definition: XMLStateComponent.h:115
armarx::XMLStateComponent::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: XMLStateComponent.cpp:50
DynamicLibrary.h
armarx::XMLStateOffererFactoryBasePtr
IceInternal::Handle< XMLStateOffererFactoryBase > XMLStateOffererFactoryBasePtr
Definition: XMLRemoteStateOfferer.h:42
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::XMLStateComponent::offererName
std::string offererName
Definition: XMLStateComponent.h:135
armarx::StatechartProfilePtr
std::shared_ptr< class StatechartProfile > StatechartProfilePtr
Definition: StatechartContext.h:52
armarx::XMLStateComponent::libraries
std::map< std::string, DynamicLibraryPtr > libraries
Definition: XMLStateComponent.h:133
IceInternal::Handle< XMLStateOffererFactoryBase >
armarx::XMLStateComponent::offerer
XMLStateOffererFactoryBasePtr offerer
Definition: XMLStateComponent.h:137
armarx::StatechartProfilesPtr
std::shared_ptr< StatechartProfiles > StatechartProfilesPtr
Definition: StatechartProfiles.h:35
armarx::XMLStateComponentProperties
Definition: XMLStateComponent.h:41
armarx::XMLStateComponent::createAndEnterInstance
void createAndEnterInstance(const std::string &stateClassName, bool useExisitingPrx=false)
Definition: XMLStateComponent.cpp:223
armarx::XMLStateComponent::XMLStateComponent
XMLStateComponent()
Definition: XMLStateComponent.cpp:45
armarx::XMLStateComponent::uuid
std::string uuid
Definition: XMLStateComponent.h:134
StatechartProfiles.h
armarx::XMLStateComponent::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: XMLStateComponent.cpp:242
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::XMLStateComponent::profiles
StatechartProfilesPtr profiles
Definition: XMLStateComponent.h:138
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::XMLStateComponentProperties::XMLStateComponentProperties
XMLStateComponentProperties(std::string prefix)
Definition: XMLStateComponent.h:45
armarx::XMLStateComponent::iceObjName
std::string iceObjName
Definition: XMLStateComponent.h:136
armarx::XMLStateComponent::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: XMLStateComponent.cpp:188
armarx::XMLStateComponent::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: XMLStateComponent.cpp:183
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::XMLStateComponent::loadLib
bool loadLib(std::string libPath)
Definition: XMLStateComponent.cpp:194
armarx::XMLStateComponent::selectedProfile
StatechartProfilePtr selectedProfile
Definition: XMLStateComponent.h:139