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 // MemoryX
34 
35 // Simox
36 #include <VirtualRobot/Grasping/Grasp.h>
37 #include <VirtualRobot/Grasping/GraspSet.h>
38 #include <VirtualRobot/XML/ObjectIO.h>
39 
40 using namespace armarx;
41 using namespace VisualServoGroup;
42 
43 // DO NOT EDIT NEXT LINE
44 TwoArmVisualServoTowardsObjects::SubClassRegistry
45  TwoArmVisualServoTowardsObjects::Registry(TwoArmVisualServoTowardsObjects::GetName(),
47 
49  XMLStateConstructorParams stateData) :
51  TwoArmVisualServoTowardsObjectsGeneratedBase<TwoArmVisualServoTowardsObjects>(stateData)
52 {
53 }
54 
55 VirtualRobot::ManipulationObjectPtr
56 TwoArmVisualServoTowardsObjects::getObjectPtr(std::string objectName,
57  VisualServoGroupStatechartContext* context)
58 {
59 
60  memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx =
61  context->getPriorKnowledge()->getObjectClassesSegment();
62  memoryx::CommonStorageInterfacePrx databasePrx =
63  context->getPriorKnowledge()->getCommonStorage();
64  memoryx::GridFileManagerPtr fileManager(new memoryx::GridFileManager(databasePrx));
65  memoryx::EntityBasePtr entity = classesSegmentPrx->getEntityByName(objectName);
66  memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(entity);
68  objectClass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
69 
70  return simoxWrapper->getManipulationObject();
71 }
72 
73 PosePtr
74 TwoArmVisualServoTowardsObjects::getDesiredTcpOffsetToObject(std::string graspSetName,
75  std::string graspName,
76  VirtualRobot::ManipulationObjectPtr mo)
77 {
78 
79  Eigen::Matrix4f transformationFromObjectToTCPPose = Eigen::Matrix4f::Identity();
80 
81  if (mo->getGraspSet(graspSetName))
82  {
83  VirtualRobot::GraspPtr grasp = mo->getGraspSet(graspSetName)->getGrasp(graspName);
84 
85  if (!grasp)
86  {
87  ARMARX_WARNING << "No grasp with name " << graspName << " found! ";
88  }
89  else
90  {
91  transformationFromObjectToTCPPose = grasp->getTransformation().inverse();
92  ARMARX_IMPORTANT << "Successfully loaded " << graspName << "";
93  ARMARX_VERBOSE << "Grasp " << graspName << " has value:\n"
94  << grasp->getTransformation();
95  }
96  }
97  else
98  {
99  ARMARX_WARNING << "No grasp set with name " << graspSetName << " found! ";
100  }
101 
102  Eigen::Matrix4f desiredTcpOffsetToObjectEigen = transformationFromObjectToTCPPose;
103 
104 
105  return new Pose(desiredTcpOffsetToObjectEigen);
106 }
107 
108 void
110 {
111  // get grasp definition
112  VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
113 
114  VirtualRobot::ManipulationObjectPtr leftObjectPtr =
115  getObjectPtr(in.getLeftObjectName(), context);
116  VirtualRobot::ManipulationObjectPtr rightObjectPtr =
117  getObjectPtr(in.getRightObjectName(), context);
118 
119  PosePtr leftDesiredTcpOffsetToObject = getDesiredTcpOffsetToObject(
120  in.getLeftGraspSetName(), in.getLeftGraspDefinitionName(), leftObjectPtr);
121  PosePtr rightDesiredTcpOffsetToObject = getDesiredTcpOffsetToObject(
122  in.getRightGraspSetName(), in.getRightGraspDefinitionName(), rightObjectPtr);
123 
124  local.setLeftDesiredTcpOffsetToObject(leftDesiredTcpOffsetToObject);
125  local.setRightDesiredTcpOffsetToObject(rightDesiredTcpOffsetToObject);
126 
127  // request IK units
128  //ARMARX_VERBOSE << "Requesting HeadIK unit";
129  //context->getHeadIKUnit()->request();
130  ARMARX_VERBOSE << "Requesting TCP control unit";
131  context->getTCPControlUnit()->request();
132  ARMARX_VERBOSE << "Requested TCP control unit";
133 }
134 
135 void
137 {
138 
139  VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
140  ARMARX_VERBOSE << "Releasing TCP control unit";
141  context->getTCPControlUnit()->release();
142  ARMARX_VERBOSE << "Released TCP control unit";
143  //ARMARX_VERBOSE << "Releasing HeadIK unit";
144  //context->getHeadIKUnit()->release();
145  //ARMARX_VERBOSE << "Released HeadIK unit";
146 }
147 
148 // DO NOT EDIT NEXT FUNCTION
151 {
153 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
TwoArmVisualServoTowardsObjects.h
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::TwoArmVisualServoTowardsObjects
TwoArmVisualServoTowardsObjects(XMLStateConstructorParams stateData)
Definition: TwoArmVisualServoTowardsObjects.cpp:48
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
GridFileManager.h
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::onEnter
void onEnter() override
Definition: TwoArmVisualServoTowardsObjects.cpp:109
ObjectClass.h
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::Registry
static SubClassRegistry Registry
Definition: TwoArmVisualServoTowardsObjects.h:46
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< ObjectClass >
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects
Definition: TwoArmVisualServoTowardsObjects.h:34
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
MemoryXCoreObjectFactories.h
memoryx::EntityWrappers::SimoxObjectWrapper
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
Definition: SimoxObjectWrapper.h:46
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::onExit
void onExit() override
Definition: TwoArmVisualServoTowardsObjects.cpp:136
SimoxObjectWrapper.h
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:41
MemoryXTypesObjectFactories.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::VisualServoGroup::TwoArmVisualServoTowardsObjects::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: TwoArmVisualServoTowardsObjects.cpp:150