SceneModifier.h
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 ArmarXSimulation::SceneModifier
17 * @author Nikolaus Vahrenkamp
18 * @date 2015
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 #include <Eigen/Core>
28 #include <ArmarXCore/interface/observers/ConditionHandlerInterface.h>
29 
30 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
31 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
32 #include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
33 
34 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
35 
36 namespace armarx
37 {
38 
41  {
42  public:
45  {
46  defineRequiredProperty<std::string>("SceneModificationType", "Possible modes are 'addObject', 'removeObject', and 'moveObject'. No object manipulation with 'none'.");
47  defineRequiredProperty<std::string>("ObjectClassName", "Name of object class in PriorKnowledge");
48  defineRequiredProperty<std::string>("ObjectInstanceName", "Name of object instance in working memory");
49  defineOptionalProperty<float>("PositionX", 0.0f, "Position of object (x)");
50  defineOptionalProperty<float>("PositionY", 0.0f, "Position of object (y)");
51  defineOptionalProperty<float>("PositionZ", 0.0f, "Position of object (z)");
52  defineOptionalProperty<float>("OrientationRoll", 0.0f, "Orientation of object (roll)");
53  defineOptionalProperty<float>("OrientationPitch", 0.0f, "Orientation of object (pitch)");
54  defineOptionalProperty<float>("OrientationYaw", 0.0f, "Orientation of object (yaw)");
55  defineOptionalProperty<bool>("StaticObject", false, "Specify if the object is static (fixed in the world) or dynamic (can move in the world)");
56  defineOptionalProperty<std::string>("WorkingMemoryName", "WorkingMemory", "Name of the WorkingMemory component that should be used");
57  defineOptionalProperty<std::string>("PriorKnowledgeName", "PriorKnowledge", "Name of the PriorKnowledge component that should be used");
58  defineOptionalProperty<std::string>("SimulatorName", "Simulator", "Name of the Simulator component that should be used");
59 
60  // define optional properties:
61  for (int i = 0; i < 10; i++)
62  {
63  std::stringstream ss1;
64  ss1 << "SceneModificationType_" << i;
65  defineOptionalProperty<std::string>(ss1.str(), "none", "Optional additional object. Possible modes are 'addObject', 'removeObject', and 'moveObject'. No object manipulation with 'none'.");
66 
67  std::stringstream ss2;
68  ss2 << "ObjectClassName_" << i;
69  defineOptionalProperty<std::string>(ss2.str(), "", "Optional additional object. Name of object class in PriorKnowledge");
70 
71  std::stringstream ss3;
72  ss3 << "ObjectInstanceName_" << i;
73  defineOptionalProperty<std::string>(ss3.str(), "", "Optional additional object. Name of object instance in working memory");
74 
75  std::stringstream ss4;
76  ss4 << "PositionX_" << i;
77  defineOptionalProperty<float>(ss4.str(), 0.0f, "Optional additional object. Position of object (x)");
78 
79  std::stringstream ss5;
80  ss5 << "PositionY_" << i;
81  defineOptionalProperty<float>(ss5.str(), 0.0f, "Optional additional object. Position of object (y)");
82 
83  std::stringstream ss6;
84  ss6 << "PositionZ_" << i;
85  defineOptionalProperty<float>(ss6.str(), 0.0f, "Optional additional object. Position of object (z)");
86 
87  std::stringstream ss7;
88  ss7 << "OrientationRoll_" << i;
89  defineOptionalProperty<float>(ss7.str(), 0.0f, "Optional additional object. Orientation of object (roll)");
90 
91  std::stringstream ss8;
92  ss8 << "OrientationPitch_" << i;
93  defineOptionalProperty<float>(ss8.str(), 0.0f, "Optional additional object. Orientation of object (pitch)");
94 
95  std::stringstream ss9;
96  ss9 << "OrientationYaw_" << i;
97  defineOptionalProperty<float>(ss9.str(), 0.0f, "Optional additional object. Orientation of object (yaw)");
98 
99  std::stringstream ss10;
100  ss10 << "StaticObject_" << i;
101  defineOptionalProperty<bool>(ss10.str(), false, "Optional additional object. Specify if the object is static (fixed in the world) or dynamic (can move in the world)");
102 
103  }
104 
105  defineOptionalProperty<bool>("LocalizeObject", false, "Start localization of object. This will make the object visible in the WM gui.");
106  defineOptionalProperty<int>("LocalizeObject_seconds", 10, "How long should the object be localized");
107 
108  defineOptionalProperty<std::string>("AttachObjectToRobot.ObjectName", "", "Attach object to robot: object instance name");
109  defineOptionalProperty<std::string>("AttachObjectToRobot.RobotName", "", "Attach object to robot: name of robot");
110  defineOptionalProperty<std::string>("AttachObjectToRobot.RobotNodeName", "", "Attach object to robot: name of RobotNode (i.e. tcp)");
111  }
112  };
113 
114  /**
115  * @defgroup Component-SceneModifier SceneModifier
116  * @ingroup ArmarXSimulation-Components
117 
118  * @brief The SceneModifier class is capable of modifying a simulated scene.
119  * Possible modifications are adding, moving or removing objects or attaching them to a robot node.
120  *
121  * This application allows to adjust a default scene in order to add or move objects for a custom scenario setup.
122  *
123  * @see @ref ArmarXSimulation-HowTos-Customize-Scene
124  *
125  * @class SceneModifier
126  * @ingroup Component-SceneModifier
127  *
128  */
130  virtual public armarx::Component
131  {
132  public:
133  /**
134  * @see PropertyUser::createPropertyDefinitions()
135  */
137  {
140  getConfigIdentifier()));
141  }
142 
143  // inherited from Component
144  std::string getDefaultName() const override
145  {
146  return "SceneModifier";
147  }
148  void onInitComponent() override;
149  void onExitComponent() override;
150  void onConnectComponent() override;
151 
152  void onDisconnectComponent() override;
153  protected:
154  Eigen::Matrix4f getGlobalPose(const std::string& suffix);
155 
156  void addObject(const std::string& suffix);
157  void removeObject(const std::string& suffix);
158  void moveObject(const std::string& suffix);
159 
160  memoryx::WorkingMemoryInterfacePrx workingMemoryProxy;
161  memoryx::PriorKnowledgeInterfacePrx priorKnowledgeProxy;
162  SimulatorInterfacePrx simulatorPrx;
163  memoryx::ObjectMemoryObserverInterfacePrx memoryObserver;
164  armarx::ConditionHandlerInterfacePrx conditionHandler;
165  armarx::ChannelRefBasePtr classChannel1;
166  void localizeSingleObject(const std::string& objClass, int sleepS);
167  void attachObject(const std::string& objName, const std::string& robotName, const std::string& robotNodeName);
168  bool checkForConfigs(const std::string& suffix);
169  bool getStatic(const std::string& suffix);
170  };
171 }
armarx::SceneModifier::simulatorPrx
SimulatorInterfacePrx simulatorPrx
Definition: SceneModifier.h:162
armarx::SceneModifier::memoryObserver
memoryx::ObjectMemoryObserverInterfacePrx memoryObserver
Definition: SceneModifier.h:163
armarx::SceneModifier::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: SceneModifier.h:144
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::SceneModifier
Definition: SceneModifier.h:129
armarx::SceneModifier::classChannel1
armarx::ChannelRefBasePtr classChannel1
Definition: SceneModifier.h:165
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::SceneModifierPropertyDefinitions::SceneModifierPropertyDefinitions
SceneModifierPropertyDefinitions(std::string prefix)
Definition: SceneModifier.h:43
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::SceneModifier::workingMemoryProxy
memoryx::WorkingMemoryInterfacePrx workingMemoryProxy
Definition: SceneModifier.h:160
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::SceneModifier::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SceneModifier.h:136
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::SceneModifier::conditionHandler
armarx::ConditionHandlerInterfacePrx conditionHandler
Definition: SceneModifier.h:164
armarx::SceneModifier::priorKnowledgeProxy
memoryx::PriorKnowledgeInterfacePrx priorKnowledgeProxy
Definition: SceneModifier.h:161
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::SceneModifierPropertyDefinitions
Definition: SceneModifier.h:39
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ImportExportComponent.h