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 
25 using namespace armarx;
26 using namespace GraspObjectGroup;
27 
28 // DO NOT EDIT NEXT LINE
29 ObjectIsReachable::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 
44 void
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 
125 void
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
135 {
136  return XMLStateFactoryBasePtr(new ObjectIsReachable(stateData));
137 }
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::GraspObjectGroup::ObjectIsReachable::Registry
static SubClassRegistry Registry
Definition: ObjectIsReachable.h:46
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
GridFileManager.h
ObjectClass.h
armarx::GraspObjectGroup::ObjectIsReachable::ObjectIsReachable
ObjectIsReachable(const XMLStateConstructorParams &stateData)
Definition: ObjectIsReachable.h:32
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< ObjectClass >
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::GraspObjectGroup::ObjectIsReachable::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: ObjectIsReachable.cpp:134
armarx::GraspObjectGroup::ObjectIsReachable::onEnter
void onEnter() override
Definition: ObjectIsReachable.cpp:45
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
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
armarx::GraspObjectGroup::ObjectIsReachable::onExit
void onExit() override
Definition: ObjectIsReachable.cpp:126
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:41
MemoryXTypesObjectFactories.h
ObjectIsReachable.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27