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 
27 
30 
32 
33 #include <VirtualRobot/ManipulationObject.h>
34 #include <VirtualRobot/Grasping/Grasp.h>
35 #include <VirtualRobot/Grasping/GraspSet.h>
36 
37 using namespace armarx;
38 using namespace ObjectLocalization;
39 
40 // DO NOT EDIT NEXT LINE
41 GetGraspOffset::SubClassRegistry GetGraspOffset::Registry(GetGraspOffset::GetName(), &GetGraspOffset::CreateInstance);
42 
43 
45 {
46  memoryx::PersistentObjectClassSegmentBasePrx objectClassesSegment = 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 " << in.getGraspSetName() << " for object " << objectName;
68 
69  memoryx::EntityBasePtr entity = objectClassesSegment->getEntityByName(objectName);
70  memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(entity);
71 
72  memoryx::EntityWrappers::SimoxObjectWrapperPtr simoxWrapper = objectClass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
73  VirtualRobot::ManipulationObjectPtr manipulationObject = simoxWrapper->getManipulationObject();
74 
75  VirtualRobot::GraspSetPtr graspSet = manipulationObject->getGraspSet(in.getGraspSetName());
76  if (graspSet)
77  {
78  VirtualRobot::GraspPtr grasp = graspSet->getGrasp(in.getGraspName());
79 
80  if (!grasp)
81  {
82  ARMARX_ERROR << "No grasp with name " << in.getGraspName() << " found! ";
83  emitFailure();
84  }
85  else
86  {
87  Eigen::Matrix4f graspPose = grasp->getTransformation().inverse();
88  out.setGraspOffset(new Pose(graspPose));
89  emitSuccess();
90  }
91  }
92  else
93  {
94  ARMARX_ERROR << "No grasp set with name " << in.getGraspSetName() << " found! ";
95  emitFailure();
96  }
97 }
98 
99 //void GetGraspOffset::run()
100 //{
101 // // put your user code for the execution-phase here
102 // // runs in seperate thread, thus can do complex operations
103 // // should check constantly whether isRunningTaskStopped() returns true
104 //
105 //// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
106 // while (!isRunningTaskStopped()) // stop run function if returning true
107 // {
108 // // do your calculations
109 // }
110 //}
111 
112 //void GetGraspOffset::onBreak()
113 //{
114 // // put your user code for the breaking point here
115 // // execution time should be short (<100ms)
116 //}
117 
119 {
120  // put your user code for the exit point here
121  // execution time should be short (<100ms)
122 }
123 
124 
125 // DO NOT EDIT NEXT FUNCTION
127 {
128  return XMLStateFactoryBasePtr(new GetGraspOffset(stateData));
129 }
130 
armarx::ObjectLocalization::GetGraspOffset::Registry
static SubClassRegistry Registry
Definition: GetGraspOffset.h:46
armarx::ObjectLocalization::GetGraspOffset::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: GetGraspOffset.cpp:126
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
GridFileManager.h
armarx::ObjectLocalization::GetGraspOffset::GetGraspOffset
GetGraspOffset(const XMLStateConstructorParams &stateData)
Definition: GetGraspOffset.h:33
ObjectClass.h
IceInternal::Handle< ObjectClass >
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
MemoryXCoreObjectFactories.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
memoryx::EntityWrappers::SimoxObjectWrapper
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
Definition: SimoxObjectWrapper.h:46
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
SimoxObjectWrapper.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
armarx::ObjectLocalization::GetGraspOffset::onEnter
void onEnter() override
Definition: GetGraspOffset.cpp:44
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:42
MemoryXTypesObjectFactories.h
GetGraspOffset.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::ObjectLocalization::GetGraspOffset::onExit
void onExit() override
Definition: GetGraspOffset.cpp:118
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28