ObjectIsReachable.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::GraspObjectGroup
17 * @author Markus Grotz ( markus dot grotz at kit dot edu )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "ObjectIsReachable.h"
24
25using namespace armarx;
26using namespace GraspObjectGroup;
27
28// DO NOT EDIT NEXT LINE
29ObjectIsReachable::SubClassRegistry ObjectIsReachable::Registry(ObjectIsReachable::GetName(),
31
32
33#include <VirtualRobot/Grasping/Grasp.h>
34#include <VirtualRobot/Grasping/GraspSet.h>
35#include <VirtualRobot/ManipulationObject.h>
36#include <VirtualRobot/XML/ObjectIO.h>
37
43
44void
46
47{
48
49
50 if (in.isDesiredTcpOffsetToObjectInputSet())
51 {
52 local.setDesiredTcpOffsetToObject(in.getDesiredTcpOffsetToObjectInput());
53
54 return;
55 }
56 else if (in.isObjectNameSet() && in.isGraspNameSet() && in.isGraspSetNameSet())
57 {
58 std::string objectName = in.getObjectName();
59 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx =
60 getPriorKnowledge()->getObjectClassesSegment();
61 memoryx::CommonStorageInterfacePrx databasePrx = getPriorKnowledge()->getCommonStorage();
62 memoryx::GridFileManagerPtr fileManager(new memoryx::GridFileManager(databasePrx));
63 memoryx::EntityBasePtr entity = classesSegmentPrx->getEntityByName(objectName);
64
65 memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(entity);
67 objectClass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
68 VirtualRobot::ManipulationObjectPtr mo = simoxWrapper->getManipulationObject();
69
70
71 Eigen::Matrix4f transformationFromObjectToTCPPose = Eigen::Matrix4f::Identity();
72
73 std::string graspSetName = in.getGraspSetName();
74
75 if (mo->getGraspSet(graspSetName))
76 {
77 std::string graspName = in.getGraspName();
78 VirtualRobot::GraspPtr grasp = mo->getGraspSet(graspSetName)->getGrasp(graspName);
79
80 if (!grasp)
81 {
82 ARMARX_ERROR << "No grasp with name " << graspName << " found! ";
83 emitFailure();
84 }
85 else
86 {
87 transformationFromObjectToTCPPose = grasp->getTransformation().inverse();
88 }
89 }
90 else
91 {
92 ARMARX_ERROR << "No grasp set with name " << graspSetName << " found! ";
93 emitFailure();
94 }
95
96 Eigen::Matrix4f desiredTcpOffsetToObjectEigen = transformationFromObjectToTCPPose;
97 PosePtr desiredTcpOffsetToObject = new Pose(desiredTcpOffsetToObjectEigen);
98 local.setDesiredTcpOffsetToObject(desiredTcpOffsetToObject);
99 }
100 else
101 {
102 emitFailure();
103 }
104}
105
106//void ObjectIsReachable::run()
107//{
108// // put your user code for the execution-phase here
109// // runs in seperate thread, thus can do complex operations
110// // should check constantly whether isRunningTaskStopped() returns true
111//
112//// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
113// while (!isRunningTaskStopped()) // stop run function if returning true
114// {
115// // do your calculations
116// }
117//}
118
119//void ObjectIsReachable::onBreak()
120//{
121// // put your user code for the breaking point here
122// // execution time should be short (<100ms)
123//}
124
125void
127{
128 // put your user code for the exit point here
129 // execution time should be short (<100ms)
130}
131
132// DO NOT EDIT NEXT FUNCTION
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
ObjectIsReachable(const 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_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
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