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