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
35namespace armarx
36{
37
38 struct XMLStateOffererFactoryBase;
40
42 {
43 public:
45 {
46 defineRequiredProperty<std::string>("XMLStatechartGroupDefinitionFile",
47 "Path to statechart group definition file "
48 "(*.scgxml) - relative to projects' source dir");
50 "XMLStatechartProfile",
51 "",
52 "Profile to use for state execution. Should be the same for all Statechart Groups "
53 "in one scenario. This profile name is also added as a prefix to the Ice "
54 "identifier of the RemoteStateOfferer of this statechart group.");
56 "XMLRemoteStateOffererName",
57 "",
58 "Name of the RemoteStateOfferer to start. The default name is "
59 "[StatechartGroupName]RemoteStateOfferer.");
61 "StatesToEnter",
62 "",
63 "List of states that are directly entered and executed. Seperated by comma. These "
64 "must not need any input parameters!");
66 "StateReportingTopic",
67 "StateReportingTopic",
68 "Topic on which state changes are published. Leave empty to disable reporting.");
69 //defineOptionalProperty<std::string>("XMLStatechartProfileDefinitionFile", "", "Path to StatechartProfiles-<ProjectName>.xml file.");
70 }
71 };
72
73 /**
74 * @defgroup Component-XMLStateComponent XMLStateComponent
75 * @ingroup ArmarXCore-Components StatechartGrp
76 * This component is the managing component for XML statechart groups offered with XMLRemoteStateOfferer.
77 * This component is used in the application *XMLRemoteStateOfferer*.
78 * It loads a statechart group from a XML file (defined in property XMLStatechartGroupDefinitionFile) and
79 * offers all contained public states via the XMLRemoteStateOfferer.
80 * The XMLRemoteStateOfferer is the remote interface to all public states of a statechart group.
81 *
82 * **Configuration:**
83 *
84 * Two properties of the XMLStateComponent are essential: *XMLStatechartGroupDefinitionFile* and *XMLStatechartProfile*.<br/>
85 * *XMLStatechartGroupDefinitionFile* is a required property and defines which statechart
86 * group (*.scgxml) is to be loaded. All public states
87 * will be available after start up for remote access.
88 * *XMLStatechartProfile* is an optional property which defines which \ref statechartprofiles "configuration profile"
89 * a statechart group should be used.
90 * This is usually a robot specific profile like *Armar3Simulation*.
91 * This profile contains two types of information:<br/>
92 * - information about the default parameters of each state
93 * - default configuration for the XMLRemoteStateOfferer, which consists mostly of
94 * proxy names like the KinematicUnit. This configuration can be overwritten
95 * with config files attached to the XMLStateComponent app.
96 * The profile name is also the prefix for the XMLRemoteStateOfferer network identifier,
97 * e.g. *Armar3SimulationGraspingGroupRemoteStateOfferer*. This way there can ba a RemoteStateOffer for each profile.
98 *
99 * Both types of information are stored in the statechart xml files and specified in the \ref ArmarXGui-GuiPlugins-StatechartEditorController "Statechart Editor".
100 *
101 * **Auto entering of states**:
102 *
103 * The property *StatesToEnter* specifies which *public* states are entered automatically on start up of the XMLComponent.
104 * These **must not** require any input parameters.
105 * It is also possible to specify multiple states by a comma-seperated list, which then will be run in parallel.
106 * (Though, event processing is not parallel.)
107 *
108 * **Configuration of a multi robot statechart setup:**
109 *
110 * It is easily possible to configure a statechart setup for multiple robots. You can just start multiple XMLStateComponent apps,
111 * choose a different profile for each app and a unique name for each of the XMLStateComponents (property *ArmarX.XMLStateComponent.objectName*).
112 *
113 * An example could look like this:
114 * \verbatim
115 config1.cfg:
116 ArmarX.XMLStateComponent.XMLStatechartGroupDefinitionFile = RobotSkillTemplates/statecharts/BringObjectGroup/BringObjectGroup.scgxml
117 ArmarX.XMLStateComponent.ObjectName = "XMLStateComponentBringObjectGroupArmar3a"
118 ArmarX.XMLStateComponent.XMLStatechartProfile=Armar3a
119
120 config2.cfg:
121 ArmarX.XMLStateComponent.XMLStatechartGroupDefinitionFile = RobotSkillTemplates/statecharts/BringObjectGroup/BringObjectGroup.scgxml
122 ArmarX.XMLStateComponent.ObjectName = "XMLStateComponentBringObjectGroupArmar3b"
123 ArmarX.XMLStateComponent.XMLStatechartProfile=Armar3b
124 \endverbatim
125 * \note This does not work for usage of two robot with the same profile. Then the properties for
126 * the XMLRemoteStateOfferer need to be specified in the .cfg file as well.
127 *
128 * @class XMLStateComponent
129 * @ingroup Component-XMLStateComponent
130 */
132 {
133 public:
135
136 // PropertyUser interface
138
139
140 // ManagedIceObject interface
141 bool loadLib(std::string libPath);
142
143 protected:
144 void onInitComponent() override;
145 void onConnectComponent() override;
146 std::string getDefaultName() const override;
147 void createAndEnterInstance(const std::string& stateClassName,
148 bool useExisitingPrx = false);
149
150 std::map<std::string, DynamicLibraryPtr> libraries;
151 std::string uuid;
152 std::string offererName;
153 std::string iceObjName;
157
158 private:
159 int stateIDStartedUsingExisitingPrx = -1;
160
161 // ManagedIceObject interface
162 protected:
163 void onDisconnectComponent() override;
164 };
165
166} // namespace armarx
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
PropertyDefinition< PropertyType > & defineRequiredProperty(const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
XMLStateComponentProperties(std::string prefix)
void onInitComponent() override
Pure virtual hook for the subclass.
StatechartProfilePtr selectedProfile
void createAndEnterInstance(const std::string &stateClassName, bool useExisitingPrx=false)
void onDisconnectComponent() override
Hook for subclass.
XMLStateOffererFactoryBasePtr offerer
std::map< std::string, DynamicLibraryPtr > libraries
void onConnectComponent() override
Pure virtual hook for the subclass.
PropertyDefinitionsPtr createPropertyDefinitions() override
StatechartProfilesPtr profiles
bool loadLib(std::string libPath)
std::string getDefaultName() const override
Retrieve default name of component.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< StatechartProfiles > StatechartProfilesPtr
IceInternal::Handle< XMLStateOffererFactoryBase > XMLStateOffererFactoryBasePtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::shared_ptr< class StatechartProfile > StatechartProfilePtr