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(), &ObjectIsReachable::CreateInstance);
30 
31 
37 
38 #include <VirtualRobot/ManipulationObject.h>
39 #include <VirtualRobot/Grasping/Grasp.h>
40 #include <VirtualRobot/Grasping/GraspSet.h>
41 #include <VirtualRobot/XML/ObjectIO.h>
42 
43 
44 
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 = getPriorKnowledge()->getObjectClassesSegment();
60  memoryx::CommonStorageInterfacePrx databasePrx = getPriorKnowledge()->getCommonStorage();
61  memoryx::GridFileManagerPtr fileManager(new memoryx::GridFileManager(databasePrx));
62  memoryx::EntityBasePtr entity = classesSegmentPrx->getEntityByName(objectName);
63 
64  memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(entity);
65  memoryx::EntityWrappers::SimoxObjectWrapperPtr simoxWrapper = objectClass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
66  VirtualRobot::ManipulationObjectPtr mo = simoxWrapper->getManipulationObject();
67 
68 
69  Eigen::Matrix4f transformationFromObjectToTCPPose = Eigen::Matrix4f::Identity();
70 
71  std::string graspSetName = in.getGraspSetName();
72 
73  if (mo->getGraspSet(graspSetName))
74  {
75  std::string graspName = in.getGraspName();
76  VirtualRobot::GraspPtr grasp = mo->getGraspSet(graspSetName)->getGrasp(graspName);
77 
78  if (!grasp)
79  {
80  ARMARX_ERROR << "No grasp with name " << graspName << " found! ";
81  emitFailure();
82  }
83  else
84  {
85  transformationFromObjectToTCPPose = grasp->getTransformation().inverse();
86  }
87  }
88  else
89  {
90  ARMARX_ERROR << "No grasp set with name " << graspSetName << " found! ";
91  emitFailure();
92  }
93 
94  Eigen::Matrix4f desiredTcpOffsetToObjectEigen = transformationFromObjectToTCPPose;
95  PosePtr desiredTcpOffsetToObject = new Pose(desiredTcpOffsetToObjectEigen);
96  local.setDesiredTcpOffsetToObject(desiredTcpOffsetToObject);
97  }
98  else
99  {
100  emitFailure();
101  }
102 }
103 
104 //void ObjectIsReachable::run()
105 //{
106 // // put your user code for the execution-phase here
107 // // runs in seperate thread, thus can do complex operations
108 // // should check constantly whether isRunningTaskStopped() returns true
109 //
110 //// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
111 // while (!isRunningTaskStopped()) // stop run function if returning true
112 // {
113 // // do your calculations
114 // }
115 //}
116 
117 //void ObjectIsReachable::onBreak()
118 //{
119 // // put your user code for the breaking point here
120 // // execution time should be short (<100ms)
121 //}
122 
124 {
125  // put your user code for the exit point here
126  // execution time should be short (<100ms)
127 }
128 
129 
130 // DO NOT EDIT NEXT FUNCTION
132 {
133  return XMLStateFactoryBasePtr(new ObjectIsReachable(stateData));
134 }
135 
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::GraspObjectGroup::ObjectIsReachable::Registry
static SubClassRegistry Registry
Definition: ObjectIsReachable.h:46
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
GridFileManager.h
ObjectClass.h
armarx::GraspObjectGroup::ObjectIsReachable::ObjectIsReachable
ObjectIsReachable(const XMLStateConstructorParams &stateData)
Definition: ObjectIsReachable.h:33
IceInternal::Handle< ObjectClass >
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::GraspObjectGroup::ObjectIsReachable::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: ObjectIsReachable.cpp:131
armarx::GraspObjectGroup::ObjectIsReachable::onEnter
void onEnter() override
Definition: ObjectIsReachable.cpp:45
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
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
armarx::GraspObjectGroup::ObjectIsReachable::onExit
void onExit() override
Definition: ObjectIsReachable.cpp:123
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:42
MemoryXTypesObjectFactories.h
ObjectIsReachable.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28