TwoArmVisualServoTowardsObjects.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2014-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotSkillTemplates::VisualServoGroup
19  * @author Markus Grotz ( markus dot grotz at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
26 
27 
28 
29 // MemoryX
35 
36 // Simox
37 #include <VirtualRobot/Grasping/Grasp.h>
38 #include <VirtualRobot/Grasping/GraspSet.h>
39 #include <VirtualRobot/XML/ObjectIO.h>
40 
41 using namespace armarx;
42 using namespace VisualServoGroup;
43 
44 // DO NOT EDIT NEXT LINE
45 TwoArmVisualServoTowardsObjects::SubClassRegistry TwoArmVisualServoTowardsObjects::Registry(TwoArmVisualServoTowardsObjects::GetName(), &TwoArmVisualServoTowardsObjects::CreateInstance);
46 
47 
48 
50  XMLStateTemplate<TwoArmVisualServoTowardsObjects>(stateData), TwoArmVisualServoTowardsObjectsGeneratedBase<TwoArmVisualServoTowardsObjects>(stateData)
51 {
52 }
53 
54 
55 VirtualRobot::ManipulationObjectPtr TwoArmVisualServoTowardsObjects::getObjectPtr(std::string objectName, VisualServoGroupStatechartContext* context)
56 {
57 
58  memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx = context->getPriorKnowledge()->getObjectClassesSegment();
59  memoryx::CommonStorageInterfacePrx databasePrx = context->getPriorKnowledge()->getCommonStorage();
60  memoryx::GridFileManagerPtr fileManager(new memoryx::GridFileManager(databasePrx));
61  memoryx::EntityBasePtr entity = classesSegmentPrx->getEntityByName(objectName);
62  memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(entity);
63  memoryx::EntityWrappers::SimoxObjectWrapperPtr simoxWrapper = objectClass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
64 
65  return simoxWrapper->getManipulationObject();
66 }
67 
68 
69 
70 PosePtr TwoArmVisualServoTowardsObjects::getDesiredTcpOffsetToObject(std::string graspSetName, std::string graspName, VirtualRobot::ManipulationObjectPtr mo)
71 {
72 
73  Eigen::Matrix4f transformationFromObjectToTCPPose = Eigen::Matrix4f::Identity();
74 
75  if (mo->getGraspSet(graspSetName))
76  {
77  VirtualRobot::GraspPtr grasp = mo->getGraspSet(graspSetName)->getGrasp(graspName);
78 
79  if (!grasp)
80  {
81  ARMARX_WARNING << "No grasp with name " << graspName << " found! ";
82  }
83  else
84  {
85  transformationFromObjectToTCPPose = grasp->getTransformation().inverse();
86  ARMARX_IMPORTANT << "Successfully loaded " << graspName << "";
87  ARMARX_VERBOSE << "Grasp " << graspName << " has value:\n" << grasp->getTransformation();
88  }
89  }
90  else
91  {
92  ARMARX_WARNING << "No grasp set with name " << graspSetName << " found! ";
93  }
94 
95  Eigen::Matrix4f desiredTcpOffsetToObjectEigen = transformationFromObjectToTCPPose;
96 
97 
98  return new Pose(desiredTcpOffsetToObjectEigen);
99 }
100 
101 
103 {
104  // get grasp definition
105  VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
106 
107  VirtualRobot::ManipulationObjectPtr leftObjectPtr = getObjectPtr(in.getLeftObjectName(), context);
108  VirtualRobot::ManipulationObjectPtr rightObjectPtr = getObjectPtr(in.getRightObjectName(), context);
109 
110  PosePtr leftDesiredTcpOffsetToObject = getDesiredTcpOffsetToObject(in.getLeftGraspSetName(), in.getLeftGraspDefinitionName(), leftObjectPtr);
111  PosePtr rightDesiredTcpOffsetToObject = getDesiredTcpOffsetToObject(in.getRightGraspSetName(), in.getRightGraspDefinitionName(), rightObjectPtr);
112 
113  local.setLeftDesiredTcpOffsetToObject(leftDesiredTcpOffsetToObject);
114  local.setRightDesiredTcpOffsetToObject(rightDesiredTcpOffsetToObject);
115 
116  // request IK units
117  //ARMARX_VERBOSE << "Requesting HeadIK unit";
118  //context->getHeadIKUnit()->request();
119  ARMARX_VERBOSE << "Requesting TCP control unit";
120  context->getTCPControlUnit()->request();
121  ARMARX_VERBOSE << "Requested TCP control unit";
122 }
123 
124 
126 {
127 
128  VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
129  ARMARX_VERBOSE << "Releasing TCP control unit";
130  context->getTCPControlUnit()->release();
131  ARMARX_VERBOSE << "Released TCP control unit";
132  //ARMARX_VERBOSE << "Releasing HeadIK unit";
133  //context->getHeadIKUnit()->release();
134  //ARMARX_VERBOSE << "Released HeadIK unit";
135 
136 }
137 
138 
139 // DO NOT EDIT NEXT FUNCTION
141 {
143 }
144 
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
TwoArmVisualServoTowardsObjects.h
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::TwoArmVisualServoTowardsObjects
TwoArmVisualServoTowardsObjects(XMLStateConstructorParams stateData)
Definition: TwoArmVisualServoTowardsObjects.cpp:49
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
GridFileManager.h
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::onEnter
void onEnter() override
Definition: TwoArmVisualServoTowardsObjects.cpp:102
ObjectClass.h
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::Registry
static SubClassRegistry Registry
Definition: TwoArmVisualServoTowardsObjects.h:48
IceInternal::Handle< ObjectClass >
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects
Definition: TwoArmVisualServoTowardsObjects.h:36
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
MemoryXCoreObjectFactories.h
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
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::onExit
void onExit() override
Definition: TwoArmVisualServoTowardsObjects.cpp:125
SimoxObjectWrapper.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:42
MemoryXTypesObjectFactories.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: TwoArmVisualServoTowardsObjects.cpp:140