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
35using namespace armarx;
36using namespace ObjectLocalization;
37
38// DO NOT EDIT NEXT LINE
39GetGraspOffset::SubClassRegistry GetGraspOffset::Registry(GetGraspOffset::GetName(),
41
42void
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
120void
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
GetGraspOffset(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
The Pose class.
Definition Pose.h:243
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
IceInternal::Handle< ObjectClass > ObjectClassPtr
Definition ObjectClass.h:35
std::shared_ptr< GridFileManager > GridFileManagerPtr