CalculateTcpTarget.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 
25 #include "CalculateTcpTarget.h"
26 
27 #include "VisualServoGroupStatechartContext.generated.h"
28 
29 #include <VirtualRobot/RobotNodeSet.h>
30 
31 
32 using namespace armarx;
33 using namespace VisualServoGroup;
34 
35 
36 // DO NOT EDIT NEXT LINE
38 
39 
40 
42  XMLStateTemplate < CalculateTcpTarget > (stateData), CalculateTcpTargetGeneratedBase < CalculateTcpTarget > (stateData)
43 {
44 }
45 
46 
47 
49 {
50  VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
51  FramedPosePtr objectPose = in.getObjectPose();
52  PosePtr desiredTcpOffsetToObject = in.getDesiredTcpOffsetToObject();
53 
54  Eigen::Matrix4f tcpTargetPoseEigen = objectPose->toEigen() * desiredTcpOffsetToObject->toEigen();
55  FramedPose tcpTargetPose(tcpTargetPoseEigen, objectPose->frame, objectPose->agent);
56  auto nodeset = context->getRobotStateComponent()->getSynchronizedRobot()->getRobotNodeSet(in.getKinematicChainName());
57  auto tcpTargetPoseChainRoot = FramedPose(tcpTargetPose.toEigen(), tcpTargetPose.frame, tcpTargetPose.agent);
58  tcpTargetPoseChainRoot.changeFrame(context->getRobot(), nodeset->names.at(0));
59  float distance = tcpTargetPoseChainRoot.toEigen().block<3, 1>(0, 3).norm();
60 
61  ARMARX_VERBOSE << "TcpTargetPose: " << tcpTargetPose;
62  ARMARX_VERBOSE << "Extension of TCP to target pose: " << distance;
63  out.setTcpTargetPose(tcpTargetPose);
64 
65  if (in.getUseReachabilityMaps() && context->getRobotIK()->hasReachabilitySpace(in.getKinematicChainName()))
66  {
67  if (!context->getRobotIK()->hasReachabilitySpace(in.getKinematicChainName()))
68  {
69  ARMARX_ERROR << "No loaded reachability space available for kinematic chain '" << in.getKinematicChainName() << "'. Falling back to distance-based reachability check";
70  }
71 
72  // Use reachability maps provided by RobotIK component
73  FramedPoseBasePtr p(new FramedPose(tcpTargetPose));
74 
75  if (context->getRobotIK()->isFramedPoseReachable(in.getKinematicChainName(), p))
76  {
77  ARMARX_INFO << "Reachability check for target pose: Succeeded";
78  emitTcpTargetCalculated();
79  }
80  else
81  {
82  ARMARX_WARNING << "Reachability check for target pose: Failed";
83  emitOutOfReach();
84  }
85  }
86  else
87  {
88  // Fall back to simple distance calculation
89  if (distance > in.getMaxTCPExtension())
90  {
91  ARMARX_WARNING << "Object is too far away (distance: " << distance << ", max: " << in.getMaxTCPExtension();
92  emitOutOfReach();
93  }
94  else
95  {
96  emitTcpTargetCalculated();
97  }
98  }
99 }
100 
101 
102 
103 
104 
105 
107 {
108  // put your user code for the breaking point here
109  // execution time should be short (<100ms)
110 }
111 
112 
113 
115 {
116  // put your user code for the exit point here
117  // execution time should be short (<100ms)
118 
119 }
120 
121 
122 
123 // DO NOT EDIT NEXT FUNCTION
125 {
126  return "CalculateTcpTarget";
127 }
128 
129 
130 
131 // DO NOT EDIT NEXT FUNCTION
133 {
134  return XMLStateFactoryBasePtr(new CalculateTcpTarget(stateData));
135 }
136 
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:258
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::VisualServoGroup::CalculateTcpTarget::GetName
static std::string GetName()
Definition: CalculateTcpTarget.cpp:124
IceInternal::Handle< FramedPose >
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::Pose::toEigen
virtual Eigen::Matrix4f toEigen() const
Definition: Pose.cpp:334
armarx::VisualServoGroup::CalculateTcpTarget::CalculateTcpTarget
CalculateTcpTarget(XMLStateConstructorParams stateData)
Definition: CalculateTcpTarget.cpp:41
armarx::VisualServoGroup::CalculateTcpTarget::Registry
static SubClassRegistry Registry
Definition: CalculateTcpTarget.h:48
armarx::VisualServoGroup::CalculateTcpTarget
Definition: CalculateTcpTarget.h:34
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
CalculateTcpTarget.h
armarx::VisualServoGroup::CalculateTcpTarget::onBreak
void onBreak() override
Definition: CalculateTcpTarget.cpp:106
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::VisualServoGroup::CalculateTcpTarget::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CalculateTcpTarget.cpp:132
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::VisualServoGroup::CalculateTcpTarget::onExit
void onExit() override
Definition: CalculateTcpTarget.cpp:114
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:88
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::VisualServoGroup::CalculateTcpTarget::onEnter
void onEnter() override
Definition: CalculateTcpTarget.cpp:48
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
norm
double norm(const Point &a)
Definition: point.hpp:94