VisualServoTowardsTargetPose.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 <IceUtil/UUID.h>
28#include <VirtualRobot/RobotNodeSet.h>
29
30#include "VisualServoGroupStatechartContextBase.generated.h"
31
32using namespace armarx;
33using namespace VisualServoGroup;
34
35
36// DO NOT EDIT NEXT LINE
37VisualServoTowardsTargetPose::SubClassRegistry
40
42 const XMLStateConstructorParams& stateData) :
44 VisualServoTowardsTargetPoseGeneratedBase<VisualServoTowardsTargetPose>(stateData)
45{
46}
47
48void
50{
51 if (!in.isTcpTargetPoseSet() && !in.isTcpTargetPositionSet())
52 {
53 ARMARX_ERROR << "Either TcpTargetPose or TcpTargetPosition has to be set for VisualServo, "
54 "but none is set.";
55 cancelSubstates();
56 emitFailure();
57 return;
58 }
59
60
61 VisualServoGroupStatechartContextBase* context =
62 getContext<VisualServoGroupStatechartContextBase>();
63
64 std::string kinematicChainName = in.getKinematicChainName();
65 if (!in.isTCPNameInRobotModelSet())
66 {
67 std::string tcpName =
68 context->getLocalRobot()->getRobotNodeSet(kinematicChainName)->getTCP()->getName();
69 local.setTcpNameInRobotModel(tcpName);
70 }
71 else
72 {
73 local.setTcpNameInRobotModel(in.getTCPNameInRobotModel());
74 }
75
76 local.setSpeedModificationFactorHandNotLocalized(0.3f);
77 local.setSpeedModificationFactorHandPoseUncertain(0.5f);
78
79 if (in.isStartTimeRefSet())
80 {
81 ARMARX_INFO << "Using existing StartTime for Visual Servo.";
82 local.setTimerCreated(false);
83 }
84 else
85 {
86 ARMARX_INFO << "Creating new StartTime for Visual Servo.";
87 in.setStartTimeRef(
88 getSystemObserver()->startTimer("VisualServoTimer_" + IceUtil::generateUUID()));
89 local.setTimerCreated(true);
90 }
91
92 if (context->getTCPControlUnit()->isRequested())
93 {
94 ARMARX_INFO << "TCPControlUnit is already requested.";
95 local.setTCPControlUnitRequested(false);
96 }
97 else
98 {
99 ARMARX_INFO << "Requesting TCPControlUnit.";
100 context->getTCPControlUnit()->request();
101 local.setTCPControlUnitRequested(true);
102 }
103
104 // TCP visu
105 std::string chainName = in.getKinematicChainName();
106 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx =
107 context->getPriorKnowledge()->getObjectClassesSegment();
108 auto tcpObjectClass = classesSegmentPrx->getObjectClassByName(
109 in.getHandMemoryChannel()->getDataField("className")->getString());
110 if (tcpObjectClass)
111 {
112 context->getEntityDrawerTopic()->setObjectVisu(
113 "VisualServoHandVisu", "tcpTarget_" + chainName, tcpObjectClass, new Pose());
114 context->getEntityDrawerTopic()->updateObjectTransparency(
115 "VisualServoHandVisu", "tcpTarget_" + chainName, 0.3);
116 }
117}
118
119void
121{
122 if (local.getTimerCreated())
123 {
124 ARMARX_INFO << "Removing timer.";
125 getSystemObserver()->removeTimer(in.getStartTimeRef());
126 }
127 if (local.getTCPControlUnitRequested())
128 {
129 ARMARX_INFO << "Releasing TCPControlUnit.";
130 getTcpControlUnit()->release();
131 }
132
133 VisualServoGroupStatechartContextBase* context =
134 getContext<VisualServoGroupStatechartContextBase>();
135 context->getDebugDrawerTopic()->removeLayer("VisualServo");
136 context->getEntityDrawerTopic()->removeLayer("VisualServoHandVisu");
137}
138
139// DO NOT EDIT NEXT FUNCTION
140std::string
142{
143 return "VisualServoTowardsTargetPose";
144}
145
146// DO NOT EDIT NEXT FUNCTION
The Pose class.
Definition Pose.h:243
VisualServoTowardsTargetPose(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64