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