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 
32 using namespace armarx;
33 using namespace VisualServoGroup;
34 
35 
36 // DO NOT EDIT NEXT LINE
37 VisualServoTowardsTargetPose::SubClassRegistry
40 
42  const XMLStateConstructorParams& stateData) :
44  VisualServoTowardsTargetPoseGeneratedBase<VisualServoTowardsTargetPose>(stateData)
45 {
46 }
47 
48 void
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 
119 void
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
140 std::string
142 {
143  return "VisualServoTowardsTargetPose";
144 }
145 
146 // DO NOT EDIT NEXT FUNCTION
149 {
151 }
armarx::VisualServoGroup::VisualServoTowardsTargetPose::VisualServoTowardsTargetPose
VisualServoTowardsTargetPose(const XMLStateConstructorParams &stateData)
Definition: VisualServoTowardsTargetPose.cpp:41
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::VisualServoGroup::VisualServoTowardsTargetPose::Registry
static SubClassRegistry Registry
Definition: VisualServoTowardsTargetPose.h:44
armarx::VisualServoGroup::VisualServoTowardsTargetPose::onEnter
void onEnter() override
Definition: VisualServoTowardsTargetPose.cpp:49
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::VisualServoGroup::VisualServoTowardsTargetPose::onExit
void onExit() override
Definition: VisualServoTowardsTargetPose.cpp:120
VisualServoTowardsTargetPose.h
armarx::VisualServoGroup::VisualServoTowardsTargetPose
Definition: VisualServoTowardsTargetPose.h:31
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::VisualServoGroup::VisualServoTowardsTargetPose::GetName
static std::string GetName()
Definition: VisualServoTowardsTargetPose.cpp:141
armarx::VisualServoGroup::VisualServoTowardsTargetPose::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: VisualServoTowardsTargetPose.cpp:148
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27