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"
26 
27 #include <VirtualRobot/LinkedCoordinate.h>
28 
30 
31 using namespace armarx;
32 using namespace FindAndGraspObjectGroup;
33 
34 // DO NOT EDIT NEXT LINE
35 ValidateTcpPose::SubClassRegistry ValidateTcpPose::Registry(ValidateTcpPose::GetName(),
37 
40 {
41 }
42 
43 void
45 {
46  using namespace Eigen;
47 
48  RobotStatechartContext* context = getContext<RobotStatechartContext>();
50  new RemoteRobot(context->robotStateComponent->getRobotSnapshot("ValidateTCPPoseTime")));
51  VirtualRobot::LinkedCoordinate actualPose(robot);
52  actualPose.set(
53  robot->getRobotNodeSet(getInput<std::string>("kinematicChainName"))->getTCP()->getName(),
54  Vector3f(0, 0, 0));
55  actualPose.changeFrame(robot->getRootNode());
56  Vector3f actualPosition = actualPose.getPosition();
57  Quaternionf actualOrientation(actualPose.getPose().block<3, 3>(0, 0));
58 
59 
60  VirtualRobot::LinkedCoordinate targetPose =
62  getInput<FramedPosition>("targetTCPPosition"),
63  getInput<FramedOrientation>("targetTCPOrientation"));
64  targetPose.changeFrame(robot->getRootNode());
65  Vector3f targetPosition = targetPose.getPosition();
66  Quaternionf targetOrientation(targetPose.getPose().block<3, 3>(0, 0));
67 
68  float cartesianDistance =
69  sqrtf(((targetPosition - actualPosition).dot(targetPosition - actualPosition)));
70  float orientationDistance = actualOrientation.angularDistance(targetOrientation);
71 
72  setOutput("TCPDistanceToTarget", cartesianDistance);
73  setOutput("TCPOrientationDistanceToTarget", orientationDistance);
74  bool withOri = getInput<bool>("ikWithOrientation");
75 
76  if (cartesianDistance <= getInput<float>("targetPositionDistanceTolerance") &&
77  (!withOri || orientationDistance <= getInput<float>("targetOrientationDistanceTolerance")))
78  {
79  sendEvent<Success>();
80  }
81  else
82  {
84  << "Target pose has not been reached with the desired accuracy. Cartesian distance: "
85  << cartesianDistance << ", orientation distance: " << orientationDistance << " ";
86  ARMARX_INFO << "Actual pose: " << actualPose.getPose();
87  ARMARX_INFO << "Target pose: " << targetPose.getPose();
88  sendEvent<Failure>();
89  }
90 
91  ARMARX_VERBOSE << "Done ValidateTcpPose::onEnter()";
92 }
93 
94 // DO NOT EDIT NEXT FUNCTION
95 std::string
97 {
98  return "ValidateTcpPose";
99 }
100 
101 // DO NOT EDIT NEXT FUNCTION
104 {
105  return XMLStateFactoryBasePtr(new ValidateTcpPose(stateData));
106 }
RemoteRobot.h
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
Eigen
Definition: Elements.h:32
armarx::State::setOutput
void setOutput(std::string const &key, const Variant &value)
setOuput() sets an output parameter of this state.
Definition: State.cpp:482
armarx::FramedPose::createLinkedCoordinate
static VirtualRobot::LinkedCoordinate createLinkedCoordinate(const VirtualRobot::RobotPtr &virtualRobot, const FramedPositionPtr &position, const FramedOrientationPtr &orientation)
Definition: FramedPose.cpp:1336
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::FindAndGraspObjectGroup::ValidateTcpPose::Registry
static SubClassRegistry Registry
Definition: ValidateTcpPose.h:47
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle
Definition: forward_declarations.h:8
ValidateTcpPose.h
armarx::RobotStatechartContext
Definition: RobotStatechartContext.h:79
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::FindAndGraspObjectGroup::ValidateTcpPose::ValidateTcpPose
ValidateTcpPose(XMLStateConstructorParams stateData)
Definition: ValidateTcpPose.cpp:38
armarx::RemoteRobot
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
Definition: RemoteRobot.h:144
armarx::FindAndGraspObjectGroup::ValidateTcpPose
Definition: ValidateTcpPose.h:34
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::Quaternion< float, 0 >
armarx::RobotStatechartContext::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Prx for the RobotState.
Definition: RobotStatechartContext.h:111
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:44
dot
double dot(const Point &x, const Point &y)
Definition: point.hpp:57
armarx::FindAndGraspObjectGroup::ValidateTcpPose::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: ValidateTcpPose.cpp:103
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
armarx::FindAndGraspObjectGroup::ValidateTcpPose::GetName
static std::string GetName()
Definition: ValidateTcpPose.cpp:96