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
40using namespace armarx;
41using namespace VisualServoGroup;
42
43// DO NOT EDIT NEXT LINE
44TwoArmVisualServoTowardsObjects::SubClassRegistry
45 TwoArmVisualServoTowardsObjects::Registry(TwoArmVisualServoTowardsObjects::GetName(),
47
54
55VirtualRobot::ManipulationObjectPtr
56TwoArmVisualServoTowardsObjects::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
74TwoArmVisualServoTowardsObjects::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
108void
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
135void
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
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
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_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
Eigen::Isometry3f Pose
Definition basic_types.h:31
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