GetGraspOffset.cpp
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::ObjectLocalization
17  * @author Markus Grotz ( markus dot grotz at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "GetGraspOffset.h"
24 
25 #include <VirtualRobot/Grasping/Grasp.h>
26 #include <VirtualRobot/Grasping/GraspSet.h>
27 #include <VirtualRobot/ManipulationObject.h>
28 
34 
35 using namespace armarx;
36 using namespace ObjectLocalization;
37 
38 // DO NOT EDIT NEXT LINE
39 GetGraspOffset::SubClassRegistry GetGraspOffset::Registry(GetGraspOffset::GetName(),
41 
42 void
44 {
45  memoryx::PersistentObjectClassSegmentBasePrx objectClassesSegment =
46  getPriorKnowledge()->getObjectClassesSegment();
47  memoryx::CommonStorageInterfacePrx commonStorage = getPriorKnowledge()->getCommonStorage();
48  memoryx::GridFileManagerPtr fileManager(new memoryx::GridFileManager(commonStorage));
49 
50  std::string objectName;
51  if (in.isObjectInstanceChannelSet())
52  {
53  ARMARX_DEBUG << "using object instance channel";
54  objectName = in.getObjectInstanceChannel()->getDataField("className")->getString();
55  }
56  else if (in.isObjectNameSet())
57  {
58  ARMARX_DEBUG << "using object name";
59  objectName = in.isObjectNameSet();
60  }
61  else
62  {
63  ARMARX_WARNING << "object instance channel not set";
64  emitFailure();
65  }
66 
67  ARMARX_INFO << "retrieving grasp " << in.getGraspName() << " from grasp set "
68  << in.getGraspSetName() << " for object " << objectName;
69 
70  memoryx::EntityBasePtr entity = objectClassesSegment->getEntityByName(objectName);
71  memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(entity);
72 
74  objectClass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
75  VirtualRobot::ManipulationObjectPtr manipulationObject = simoxWrapper->getManipulationObject();
76 
77  VirtualRobot::GraspSetPtr graspSet = manipulationObject->getGraspSet(in.getGraspSetName());
78  if (graspSet)
79  {
80  VirtualRobot::GraspPtr grasp = graspSet->getGrasp(in.getGraspName());
81 
82  if (!grasp)
83  {
84  ARMARX_ERROR << "No grasp with name " << in.getGraspName() << " found! ";
85  emitFailure();
86  }
87  else
88  {
89  Eigen::Matrix4f graspPose = grasp->getTransformation().inverse();
90  out.setGraspOffset(new Pose(graspPose));
91  emitSuccess();
92  }
93  }
94  else
95  {
96  ARMARX_ERROR << "No grasp set with name " << in.getGraspSetName() << " found! ";
97  emitFailure();
98  }
99 }
100 
101 //void GetGraspOffset::run()
102 //{
103 // // put your user code for the execution-phase here
104 // // runs in seperate thread, thus can do complex operations
105 // // should check constantly whether isRunningTaskStopped() returns true
106 //
107 //// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
108 // while (!isRunningTaskStopped()) // stop run function if returning true
109 // {
110 // // do your calculations
111 // }
112 //}
113 
114 //void GetGraspOffset::onBreak()
115 //{
116 // // put your user code for the breaking point here
117 // // execution time should be short (<100ms)
118 //}
119 
120 void
122 {
123  // put your user code for the exit point here
124  // execution time should be short (<100ms)
125 }
126 
127 // DO NOT EDIT NEXT FUNCTION
130 {
131  return XMLStateFactoryBasePtr(new GetGraspOffset(stateData));
132 }
armarx::ObjectLocalization::GetGraspOffset::Registry
static SubClassRegistry Registry
Definition: GetGraspOffset.h:46
armarx::ObjectLocalization::GetGraspOffset::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: GetGraspOffset.cpp:129
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
GridFileManager.h
armarx::ObjectLocalization::GetGraspOffset::GetGraspOffset
GetGraspOffset(const XMLStateConstructorParams &stateData)
Definition: GetGraspOffset.h:32
ObjectClass.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< ObjectClass >
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
MemoryXCoreObjectFactories.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
memoryx::EntityWrappers::SimoxObjectWrapper
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
Definition: SimoxObjectWrapper.h:46
SimoxObjectWrapper.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
armarx::ObjectLocalization::GetGraspOffset::onEnter
void onEnter() override
Definition: GetGraspOffset.cpp:43
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:41
MemoryXTypesObjectFactories.h
GetGraspOffset.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::ObjectLocalization::GetGraspOffset::onExit
void onExit() override
Definition: GetGraspOffset.cpp:121
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27