FindAndGraspObjectContext.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 RobotSkillTemplates::FindAndGraspObject
17 * @author Nikolaus Vahrenkamp
18 * @date 2012 Nikolaus Vahrenkamp
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 
24 #pragma once
25 
27 //#include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
28 
29 #include <VisionX/interface/components/Calibration.h>
30 #include <VisionX/interface/components/HandLocalization.h>
31 #include <VisionX/interface/core/ImageProcessorInterface.h>
32 
33 #include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
34 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
35 
38 #include <RobotAPI/interface/units/KinematicUnitInterface.h>
39 
42 
43 namespace armarx
44 {
45 
46  // ****************************************************************
47  // Component and context
48  // ****************************************************************
49 
51  {
54  {
55  defineOptionalProperty<std::string>("KinematicUnitName", "Armar3KinematicUnit", "Name of the kinematic unit that should be used");
56  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the robot state component that should be used");
57  defineOptionalProperty<std::string>("ObjectMemoryObserverName", "ObjectMemoryObserver", "Name of the ObjectMemoryObserver component that should be used");
58  defineOptionalProperty<std::string>("PriorKnowledgeName", "PriorKnowledge", "Name of the PriorKnowledge component that should be used");
59  //defineOptionalProperty<std::string>("SimulatorName", "Simulator", "Name of the simulator component that should be used");
60 
61  defineOptionalProperty<std::string>("HeadIKUnitName", "", "Name of the head unit that should be used.");
62  defineOptionalProperty<std::string>("HeadIKKinematicChainName", "", "Name of the inematic chain that should be used for head IK.");
63  }
64  };
65 
66 
68  virtual public RobotStatechartContext
69  {
70  public:
71  // inherited from Component
72  virtual std::string getDefaultName()
73  {
74  return "FindAndGraspObjectContext";
75  }
76 
77  virtual void onInitStatechartContext()
78  {
79  ARMARX_LOG << eINFO << "Init FindAndGraspObjectContext" << flush;
80 
82 
83  usingProxy(getProperty<std::string>("KinematicUnitObserverName").getValue());
84  usingProxy(getProperty<std::string>("KinematicUnitName").getValue());
85  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
86  usingProxy(getProperty<std::string>("ObjectMemoryObserverName").getValue());
87  usingProxy(getProperty<std::string>("PriorKnowledgeName").getValue());
88 
89  //For Visualization of (debug) coordinate systems
90  std::string simPrxName = getProperty<std::string>("SimulatorName").getValue();
91 
92  if (!simPrxName.empty())
93  {
94  usingProxy(simPrxName);
95  }
96 
97  // headIKUnit
98  headIKUnitName = getProperty<std::string>("HeadIKUnitName").getValue();
99  ARMARX_LOG << eINFO << "headIKUnitName:" << headIKUnitName << flush;
100  headIKKinematicChainName = getProperty<std::string>("HeadIKKinematicChainName").getValue();
101 
102  if (!headIKUnitName.empty())
103  {
104  usingProxy(headIKUnitName);
105  }
106  }
107 
109  {
111  ARMARX_LOG << eINFO << "Starting FindAndGraspObjectContext" << flush;
112  // retrieve proxies
113 
114  objectMemoryObserver = getProxy<memoryx::ObjectMemoryObserverInterfacePrx>(getProperty<std::string>("ObjectMemoryObserverName").getValue());
115  priorMemoryProxy = getProxy<memoryx::PriorKnowledgeInterfacePrx>(getProperty<std::string>("PriorKnowledgeName").getValue());
116  std::string rbStateName = getProperty<std::string>("RobotStateComponentName").getValue();
117  robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(rbStateName);
118  std::string kinUnitName = getProperty<std::string>("KinematicUnitName").getValue();
119  kinematicUnitPrx = getProxy<KinematicUnitInterfacePrx>(kinUnitName);
120 
121  // initialize remote robot
122  remoteRobot.reset(new RemoteRobot(robotStateComponent->getSynchronizedRobot()));
123 
124  //For Visualization of (debug) coordinate systems
125  /*std::string simPrxName = getProperty<std::string>("SimulatorName").getValue();
126  if (!simPrxName.empty())
127  {
128  simulatorProxy = getProxy<SimulatorInterfacePrx>(simPrxName);
129  }
130  //ARMARX_LOG << eINFO << "Fetched proxies " << kinUnitName << ":" << kinematicUnitPrx << ", " << rbStateName << ": " << robotStateComponent << flush;
131  */
132  if (!headIKUnitName.empty())
133  {
134  headIKUnitPrx = getProxy<HeadIKUnitInterfacePrx>(headIKUnitName);
135  ARMARX_LOG << eINFO << "Fetched headIK proxy " << headIKUnitName << ":" << headIKUnitPrx << ", head IK kin chain:" << headIKKinematicChainName << flush;
136  }
137 
138  localRobot = RemoteRobot::createLocalClone(robotStateComponent);
139  ARMARX_LOG << eINFO << "Created local robot" << flush;
140 
141  }
142 
144  {
145  return PropertyDefinitionsPtr(new FindAndGraspObjectContextProperties(getConfigIdentifier()));
146  }
147 
148  //From GraspingWithVisualFeedbackContext:
149  //TCPControlUnitInterfacePrx tcpControlUnitProxy; //Maybe not necessary?
150 
151  //visionx::ImageFileSequenceProviderInterfacePrx imageSequenceProviderProxy;
152  memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver;
153  memoryx::PriorKnowledgeInterfacePrx priorMemoryProxy;
154  VirtualRobot::GraspPtr graspDefinition;
155  //visionx::HandLocalizationInterfacePrx handLocalizationProxy;
156  //std::string kinematicChainName, graspedObjectName;
157 
158  //From VisualServoContext:
160  KinematicUnitInterfacePrx kinematicUnitPrx;
162 
163  //For Visualization of (debug) coordinate systems
164  //SimulatorInterfacePrx simulatorProxy;
165 
166  HeadIKUnitInterfacePrx headIKUnitPrx;
168  std::string headIKUnitName;
169 
170  // a temporary robot which has to be manually synchronized. Can be used for IK computations.
172 
173  };
174 
175 }
176 
177 
armarx::FindAndGraspObjectContext::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Definition: FindAndGraspObjectContext.h:159
RemoteRobot.h
armarx::RobotStatechartContext::onConnectStatechartContext
void onConnectStatechartContext() override
onConnectStatechartContext can be implemented by subclasses
Definition: RobotStatechartContext.cpp:72
armarx::FindAndGraspObjectContextProperties::FindAndGraspObjectContextProperties
FindAndGraspObjectContextProperties(std::string prefix)
Definition: FindAndGraspObjectContext.h:52
armarx::FindAndGraspObjectContext::priorMemoryProxy
memoryx::PriorKnowledgeInterfacePrx priorMemoryProxy
Definition: FindAndGraspObjectContext.h:153
armarx::RobotStatechartContext::onInitStatechartContext
void onInitStatechartContext() override
onInitStatechartonInitStatechartContext can be implemented by subclasses
Definition: RobotStatechartContext.cpp:38
armarx::FindAndGraspObjectContext::headIKKinematicChainName
std::string headIKKinematicChainName
Definition: FindAndGraspObjectContext.h:167
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::FindAndGraspObjectContext::remoteRobot
VirtualRobot::RobotPtr remoteRobot
Definition: FindAndGraspObjectContext.h:161
armarx::FindAndGraspObjectContext::onConnectStatechartContext
virtual void onConnectStatechartContext()
onConnectStatechartContext can be implemented by subclasses
Definition: FindAndGraspObjectContext.h:108
RobotAPIObjectFactories.h
armarx::FindAndGraspObjectContext::getDefaultName
virtual std::string getDefaultName()
Definition: FindAndGraspObjectContext.h:72
armarx::FindAndGraspObjectContext::objectMemoryObserver
memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver
Definition: FindAndGraspObjectContext.h:152
StatechartContext.h
armarx::FindAndGraspObjectContext
Definition: FindAndGraspObjectContext.h:67
armarx::RobotStatechartContext
Definition: RobotStatechartContext.h:66
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::FindAndGraspObjectContext::headIKUnitName
std::string headIKUnitName
Definition: FindAndGraspObjectContext.h:168
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:163
armarx::FindAndGraspObjectContext::localRobot
VirtualRobot::RobotPtr localRobot
Definition: FindAndGraspObjectContext.h:171
armarx::RemoteRobot
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
Definition: RemoteRobot.h:139
armarx::RemoteRobot::createLocalClone
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
Definition: RemoteRobot.cpp:328
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::FindAndGraspObjectContext::onInitStatechartContext
virtual void onInitStatechartContext()
onInitStatechartonInitStatechartContext can be implemented by subclasses
Definition: FindAndGraspObjectContext.h:77
armarx::RobotStatechartContextProperties
Definition: RobotStatechartContext.h:46
armarx::FindAndGraspObjectContext::createPropertyDefinitions
virtual PropertyDefinitionsPtr createPropertyDefinitions()
Definition: FindAndGraspObjectContext.h:143
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::FindAndGraspObjectContextProperties
Definition: FindAndGraspObjectContext.h:50
armarx::FindAndGraspObjectContext::graspDefinition
VirtualRobot::GraspPtr graspDefinition
Definition: FindAndGraspObjectContext.h:154
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::FindAndGraspObjectContext::headIKUnitPrx
HeadIKUnitInterfacePrx headIKUnitPrx
Definition: FindAndGraspObjectContext.h:166
armarx::FindAndGraspObjectContext::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: FindAndGraspObjectContext.h:160
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
RobotStatechartContext.h
ImportExportComponent.h