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
32using namespace armarx;
33using namespace VisualServoGroup;
34
35
36// DO NOT EDIT NEXT LINE
37CalculateTcpTarget::SubClassRegistry
40
43 CalculateTcpTargetGeneratedBase<CalculateTcpTarget>(stateData)
44{
45}
46
47void
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
108void
110{
111 // put your user code for the breaking point here
112 // execution time should be short (<100ms)
113}
114
115void
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
123std::string
125{
126 return "CalculateTcpTarget";
127}
128
129// DO NOT EDIT NEXT FUNCTION
The FramedPose class.
Definition FramedPose.h:281
virtual Eigen::Matrix4f toEigen() const
Definition Pose.cpp:334
CalculateTcpTarget(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
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272
double norm(const Point &a)
Definition point.hpp:102
double distance(const Point &a, const Point &b)
Definition point.hpp:95