VisualServoTowardsObject.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::GraspObjectGroup
19 * @author David ( david dot schiebener at kit dot edu )
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include "VisualServoGroupStatechartContext.generated.h"
28
29
30// MemoryX
36
37// Simox
38#include <VirtualRobot/Grasping/Grasp.h>
39#include <VirtualRobot/Grasping/GraspSet.h>
40#include <VirtualRobot/ManipulationObject.h>
41#include <VirtualRobot/XML/ObjectIO.h>
42
43
44using namespace armarx;
45using namespace VisualServoGroup;
46
47
48// DO NOT EDIT NEXT LINE
49VisualServoTowardsObject::SubClassRegistry
52
55 VisualServoTowardsObjectGeneratedBase<VisualServoTowardsObject>(stateData)
56{
57}
58
59void
61{
62 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
63 local.setStartTimeRef(ChannelRefPtr::dynamicCast(
64 context->systemObserverPrx->startTimer("VisualServoTowardsObjectStartTime")));
65
66 // get grasp definition
67 std::string objectName;
68 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx =
69 context->getPriorKnowledge()->getObjectClassesSegment();
70 memoryx::CommonStorageInterfacePrx databasePrx =
71 context->getPriorKnowledge()->getCommonStorage();
72 memoryx::GridFileManagerPtr fileManager(new memoryx::GridFileManager(databasePrx));
73 memoryx::EntityBasePtr entity;
74 if (in.isPreselectedObjectInstanceChannelSet())
75 {
76 ARMARX_INFO << "Using preselected instance "
77 << in.getPreselectedObjectInstanceChannel()->output();
78 objectName =
79 in.getPreselectedObjectInstanceChannel()->getDataField("className")->getString();
80 }
81 else
82 {
83 objectName = in.getObjectMemoryChannel()->getDataField("className")->getString();
84 }
85 entity = classesSegmentPrx->getEntityByName(objectName);
86 auto chainName = in.getKinematicChainName();
87
88 memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(entity);
90 objectClass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
91 VirtualRobot::ManipulationObjectPtr mo = simoxWrapper->getManipulationObject();
92
93 auto tcpObjectClass = classesSegmentPrx->getObjectClassByName(in.getHandNameInMemory());
94 if (tcpObjectClass)
95 {
96 context->getEntityDrawerTopic()->setObjectVisu(
97 "VisualServoHandVisu", "tcpTarget_" + chainName, tcpObjectClass, new Pose());
98 context->getEntityDrawerTopic()->updateObjectTransparency(
99 "VisualServoHandVisu", "tcpTarget_" + chainName, 0.3);
100 }
101 else
102 {
103 ARMARX_IMPORTANT << "Could not get objectclass for tcp " << in.getHandNameInMemory()
104 << " for visu purposes";
105 }
106 Eigen::Matrix4f transformationFromObjectToTCPPose = Eigen::Matrix4f::Identity();
107
108 std::string graspSetName = getInput<std::string>("GraspSetName");
109
110 if (mo->getGraspSet(graspSetName))
111 {
112 std::string graspName = getInput<std::string>("GraspDefinitionName");
113 VirtualRobot::GraspPtr grasp = mo->getGraspSet(graspSetName)->getGrasp(graspName);
114
115 if (!grasp)
116 {
117 ARMARX_ERROR << "No grasp with name " << graspName << " found! ";
118 return;
119 }
120 else
121 {
122 transformationFromObjectToTCPPose = grasp->getTransformation().inverse();
123 ARMARX_IMPORTANT << "Successfully loaded " << graspName << "";
124 ARMARX_VERBOSE << "Grasp " << graspName << " has value:\n"
125 << grasp->getTransformation();
126 }
127 }
128 else
129 {
130 ARMARX_ERROR << "No grasp set with name " << graspSetName << " found! ";
131 return;
132 }
133
134 Eigen::Matrix4f desiredTcpOffsetToObjectEigen = transformationFromObjectToTCPPose;
135 PosePtr desiredTcpOffsetToObject = new Pose(desiredTcpOffsetToObjectEigen);
136 setLocal("DesiredTcpOffsetToObject", *desiredTcpOffsetToObject);
137
138 // request IK units
139 ARMARX_VERBOSE << "Requesting TCP control unit";
140 context->getTCPControlUnit()->request();
141 ARMARX_VERBOSE << "Requested TCP control unit";
142}
143
144void
146{
147 // put your user code for the exit point here
148 // execution time should be short (<100ms)
149
150 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
151 ARMARX_VERBOSE << "Releasing TCP control unit";
152 context->getTCPControlUnit()->release();
153 ARMARX_VERBOSE << "Released TCP control unit";
154
155 // this pose was set in GetObjectPose
156 context->getDebugDrawerTopic()->removePoseDebugLayerVisu("objectPose");
157 context->systemObserverPrx->removeTimer(local.getStartTimeRef());
158 context->getEntityDrawerTopic()->removeLayer("VisualServoHandVisu");
159}
160
161// DO NOT EDIT NEXT FUNCTION
162std::string
164{
165 return "VisualServoTowardsObject";
166}
167
168// DO NOT EDIT NEXT FUNCTION
The Pose class.
Definition Pose.h:243
VisualServoTowardsObject(XMLStateConstructorParams stateData)
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_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
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