ValidateTcpPose.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::FindAndGraspObjectGroup
19  * @author Valerij Wittenbeck ( valerij dot wittenbeck at student dot 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 "ValidateTcpPose.h"
27 #include <VirtualRobot/LinkedCoordinate.h>
28 
29 using namespace armarx;
30 using namespace FindAndGraspObjectGroup;
31 
32 // DO NOT EDIT NEXT LINE
34 
35 
36 
38  XMLStateTemplate < ValidateTcpPose > (stateData)
39 {
40 }
41 
43 {
44  using namespace Eigen;
45 
46  RobotStatechartContext* context = getContext<RobotStatechartContext>();
47  VirtualRobot::RobotPtr robot(new RemoteRobot(context->robotStateComponent->getRobotSnapshot("ValidateTCPPoseTime")));
48  VirtualRobot::LinkedCoordinate actualPose(robot);
49  actualPose.set(robot->getRobotNodeSet(getInput<std::string>("kinematicChainName"))->getTCP()->getName(), Vector3f(0, 0, 0));
50  actualPose.changeFrame(robot->getRootNode());
51  Vector3f actualPosition = actualPose.getPosition();
52  Quaternionf actualOrientation(actualPose.getPose().block<3, 3>(0, 0));
53 
54 
55  VirtualRobot::LinkedCoordinate targetPose = FramedPose::createLinkedCoordinate(robot, getInput<FramedPosition>("targetTCPPosition"), getInput<FramedOrientation>("targetTCPOrientation"));
56  targetPose.changeFrame(robot->getRootNode());
57  Vector3f targetPosition = targetPose.getPosition();
58  Quaternionf targetOrientation(targetPose.getPose().block<3, 3>(0, 0));
59 
60  float cartesianDistance = sqrtf(((targetPosition - actualPosition).dot(targetPosition - actualPosition)));
61  float orientationDistance = actualOrientation.angularDistance(targetOrientation);
62 
63  setOutput("TCPDistanceToTarget", cartesianDistance);
64  setOutput("TCPOrientationDistanceToTarget", orientationDistance);
65  bool withOri = getInput<bool>("ikWithOrientation");
66 
67  if (cartesianDistance <= getInput<float>("targetPositionDistanceTolerance") && (!withOri || orientationDistance <= getInput<float>("targetOrientationDistanceTolerance")))
68  {
69  sendEvent<Success>();
70  }
71  else
72  {
73  ARMARX_WARNING << "Target pose has not been reached with the desired accuracy. Cartesian distance: " << cartesianDistance << ", orientation distance: " << orientationDistance << " ";
74  ARMARX_INFO << "Actual pose: " << actualPose.getPose();
75  ARMARX_INFO << "Target pose: " << targetPose.getPose();
76  sendEvent<Failure>();
77  }
78 
79  ARMARX_VERBOSE << "Done ValidateTcpPose::onEnter()";
80 }
81 
82 // DO NOT EDIT NEXT FUNCTION
84 {
85  return "ValidateTcpPose";
86 }
87 
88 // DO NOT EDIT NEXT FUNCTION
90 {
91  return XMLStateFactoryBasePtr(new ValidateTcpPose(stateData));
92 }
93 
RemoteRobot.h
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
Eigen
Definition: Elements.h:36
armarx::State::setOutput
void setOutput(std::string const &key, const Variant &value)
setOuput() sets an output parameter of this state.
Definition: State.cpp:434
armarx::FramedPose::createLinkedCoordinate
static VirtualRobot::LinkedCoordinate createLinkedCoordinate(const VirtualRobot::RobotPtr &virtualRobot, const FramedPositionPtr &position, const FramedOrientationPtr &orientation)
Definition: FramedPose.cpp:1133
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::FindAndGraspObjectGroup::ValidateTcpPose::Registry
static SubClassRegistry Registry
Definition: ValidateTcpPose.h:46
IceInternal::Handle
Definition: forward_declarations.h:8
ValidateTcpPose.h
armarx::RobotStatechartContext
Definition: RobotStatechartContext.h:66
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::FindAndGraspObjectGroup::ValidateTcpPose::ValidateTcpPose
ValidateTcpPose(XMLStateConstructorParams stateData)
Definition: ValidateTcpPose.cpp:37
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::RemoteRobot
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
Definition: RemoteRobot.h:139
armarx::FindAndGraspObjectGroup::ValidateTcpPose
Definition: ValidateTcpPose.h:33
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::Quaternion< float, 0 >
armarx::RobotStatechartContext::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Prx for the RobotState.
Definition: RobotStatechartContext.h:96
armarx::FindAndGraspObjectGroup::ValidateTcpPose::onEnter
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
Definition: ValidateTcpPose.cpp:42
dot
double dot(const Point &x, const Point &y)
Definition: point.hpp:53
armarx::FindAndGraspObjectGroup::ValidateTcpPose::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: ValidateTcpPose.cpp:89
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
armarx::FindAndGraspObjectGroup::ValidateTcpPose::GetName
static std::string GetName()
Definition: ValidateTcpPose.cpp:83