CartesianPositionControlVerification.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::MotionControlGroup
19 * @author Peter Kaiser ( peter dot kaiser 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 <VirtualRobot/LinkedCoordinate.h>
28#include <VirtualRobot/RobotNodeSet.h>
29
33
35
36using namespace armarx;
37using namespace MotionControlGroup;
38
39// DO NOT EDIT NEXT LINE
40CartesianPositionControlVerification::SubClassRegistry
42 CartesianPositionControlVerification::GetName(),
44
52
53void
57
58void
60{
62 getContext<MotionControlGroupStatechartContext>();
63
64 std::string kinChainName = in.getKinematicChainName();
65 float positionTolerance = in.getTcpPositionTolerance();
66 float orientationTolerance = in.getTcpOrientationTolerance();
67
68 VirtualRobot::RobotPtr robot = context->getRobot()->clone();
69
70 if (!robot)
71 {
72 ARMARX_WARNING << "Could not create robot" << flush;
73 emitFailure();
74 }
75
76 if (!robot->hasRobotNodeSet(kinChainName))
77 {
78 ARMARX_WARNING << "Kinematic Chain '" << kinChainName << "' not available" << flush;
79 emitFailure();
80 }
81
82 FramedPositionPtr framedPosition;
83 FramedOrientationPtr framedOrientation;
84
85 float tcpPositionDistanceToTarget = 0;
86 float tcpOrientationDistanceToTarget = 0;
87
88 // Compute distance to position target (if set)
89 if (isInputParameterSet("TcpTargetPosition"))
90 {
91 framedPosition = in.getTcpTargetPosition();
92 tcpPositionDistanceToTarget =
93 (framedPosition->toGlobal(robot)->toEigen() -
94 robot->getRobotNodeSet(kinChainName)->getTCP()->getGlobalPose().block<3, 1>(0, 3))
95 .norm();
96 }
97
98 // Compute distance to orientation target (if set)
99 if (isInputParameterSet("TcpTargetOrientation"))
100 {
101 framedOrientation = in.getTcpTargetOrientation();
102 auto globalOri = framedOrientation->toGlobal(robot);
103
104 Eigen::Quaternionf targetOrientation(globalOri->toEigen());
105 Eigen::Quaternionf currentOrientation(
106 robot->getRobotNodeSet(kinChainName)->getTCP()->getGlobalPose().block<3, 3>(0, 0));
107
108 tcpOrientationDistanceToTarget = currentOrientation.angularDistance(targetOrientation);
109 }
110
111 out.setTcpFinalPositionDistanceToTarget(tcpPositionDistanceToTarget);
112 out.setTcpFinalOrientationDistanceToTarget(tcpOrientationDistanceToTarget);
113
114 // Check goal condition
115 if (in.getDontMoveIfAlreadyClose() && tcpPositionDistanceToTarget < positionTolerance &&
116 tcpOrientationDistanceToTarget < orientationTolerance)
117 {
118 emitSuccess();
119 }
120 else
121 {
122 ARMARX_INFO << "Target not yet reached: position distance = " << tcpPositionDistanceToTarget
123 << " (Tolerance: " << positionTolerance
124 << "), orientation distance = " << tcpOrientationDistanceToTarget
125 << " (Tolerance: " << orientationTolerance << ")";
126 emitTargetNotReached();
127 }
128}
129
130void
134
135void
139
140// DO NOT EDIT NEXT FUNCTION
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
custom implementation of the StatechartContext for a statechart
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_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
Quaternion< float, 0 > Quaternionf
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
Definition FramedPose.h:207
const LogSender::manipulator flush
Definition LogSender.h:251
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)