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