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 #include "../MotionControlGroupStatechartContext.h"
27 
31 
32 #include <VirtualRobot/LinkedCoordinate.h>
33 
34 using namespace armarx;
35 using namespace MotionControlGroup;
36 
37 // DO NOT EDIT NEXT LINE
38 CartesianPositionControlVerification::SubClassRegistry CartesianPositionControlVerification::Registry(CartesianPositionControlVerification::GetName(), &CartesianPositionControlVerification::CreateInstance);
39 
40 
41 
44  CartesianPositionControlVerificationGeneratedBase<CartesianPositionControlVerification>(stateData)
45 {
46 }
47 
49 {
50 }
51 
53 {
54  MotionControlGroupStatechartContext* context = getContext<MotionControlGroupStatechartContext>();
55 
56  std::string kinChainName = in.getKinematicChainName();
57  float positionTolerance = in.getTcpPositionTolerance();
58  float orientationTolerance = in.getTcpOrientationTolerance();
59 
60  VirtualRobot::RobotPtr robot = context->getRobot()->clone();
61 
62  if (!robot)
63  {
64  ARMARX_WARNING << "Could not create robot" << flush;
65  emitFailure();
66  }
67 
68  if (!robot->hasRobotNodeSet(kinChainName))
69  {
70  ARMARX_WARNING << "Kinematic Chain '" << kinChainName << "' not available" << flush;
71  emitFailure();
72  }
73 
74  FramedPositionPtr framedPosition;
75  FramedOrientationPtr framedOrientation;
76 
77  float tcpPositionDistanceToTarget = 0;
78  float tcpOrientationDistanceToTarget = 0;
79 
80  // Compute distance to position target (if set)
81  if (isInputParameterSet("TcpTargetPosition"))
82  {
83  framedPosition = in.getTcpTargetPosition();
84  tcpPositionDistanceToTarget = (framedPosition->toGlobal(robot)->toEigen() - robot->getRobotNodeSet(kinChainName)->getTCP()->getGlobalPose().block<3, 1>(0, 3)).norm();
85  }
86 
87  // Compute distance to orientation target (if set)
88  if (isInputParameterSet("TcpTargetOrientation"))
89  {
90  framedOrientation = in.getTcpTargetOrientation();
91  auto globalOri = framedOrientation->toGlobal(robot);
92 
93  Eigen::Quaternionf targetOrientation(globalOri->toEigen());
94  Eigen::Quaternionf currentOrientation(robot->getRobotNodeSet(kinChainName)->getTCP()->getGlobalPose().block<3, 3>(0, 0));
95 
96  tcpOrientationDistanceToTarget = currentOrientation.angularDistance(targetOrientation);
97  }
98 
99  out.setTcpFinalPositionDistanceToTarget(tcpPositionDistanceToTarget);
100  out.setTcpFinalOrientationDistanceToTarget(tcpOrientationDistanceToTarget);
101 
102  // Check goal condition
103  if (in.getDontMoveIfAlreadyClose() && tcpPositionDistanceToTarget < positionTolerance && tcpOrientationDistanceToTarget < orientationTolerance)
104  {
105  emitSuccess();
106  }
107  else
108  {
109  ARMARX_INFO << "Target not yet reached: position distance = " << tcpPositionDistanceToTarget << " (Tolerance: " << positionTolerance << "), orientation distance = "
110  << tcpOrientationDistanceToTarget << " (Tolerance: " << orientationTolerance << ")";
111  emitTargetNotReached();
112  }
113 }
114 
116 {
117 }
118 
120 {
121 }
122 
123 // DO NOT EDIT NEXT FUNCTION
125 {
127 }
128 
RemoteRobot.h
armarx::MotionControlGroup::MotionControlGroupStatechartContext
Definition: MotionControlGroupStatechartContext.h:66
armarx::MotionControlGroup::CartesianPositionControlVerification::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CartesianPositionControlVerification.cpp:124
armarx::MotionControlGroup::CartesianPositionControlVerification
Definition: CartesianPositionControlVerification.h:31
Pose.h
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::MotionControlGroup::CartesianPositionControlVerification::onEnter
void onEnter() override
Definition: CartesianPositionControlVerification.cpp:48
armarx::MotionControlGroup::CartesianPositionControlVerification::onExit
void onExit() override
Definition: CartesianPositionControlVerification.cpp:119
IceInternal::Handle< FramedPosition >
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getRobot
const std::shared_ptr< RemoteRobot > getRobot()
Definition: MotionControlGroupStatechartContext.h:79
CartesianPositionControlVerification.h
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::MotionControlGroup::CartesianPositionControlVerification::onBreak
void onBreak() override
Definition: CartesianPositionControlVerification.cpp:115
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::MotionControlGroup::CartesianPositionControlVerification::Registry
static SubClassRegistry Registry
Definition: CartesianPositionControlVerification.h:45
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::Quaternion< float, 0 >
armarx::MotionControlGroup::CartesianPositionControlVerification::CartesianPositionControlVerification
CartesianPositionControlVerification(XMLStateConstructorParams stateData)
Definition: CartesianPositionControlVerification.cpp:42
armarx::MotionControlGroup::CartesianPositionControlVerification::run
void run() override
Definition: CartesianPositionControlVerification.cpp:52
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
RobotStatechartContext.h