GraspCandidateHelper.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #include "GraspCandidateHelper.h"
25 
26 #include <VirtualRobot/Robot.h>
27 #include <VirtualRobot/math/Helpers.h>
28 
30 
31 using namespace armarx;
32 
33 GraspCandidateHelper::GraspCandidateHelper(const grasping::GraspCandidatePtr& candidate,
34  VirtualRobot::RobotPtr robot) :
35  candidate(candidate), robot(robot)
36 {
37  ARMARX_CHECK_NOT_NULL(candidate);
38  ARMARX_CHECK_NOT_NULL(robot);
39 }
40 
43 {
44  /* As the (current) robot might have moved after the grasp was generated,
45  * we must first transform the grasp to global with its original robot pose (stored in the grasp),
46  * then transform it to the current robot frame. */
47  const Eigen::Matrix4f curRobotPose = robot->getGlobalPose();
48  const Eigen::Matrix4f graspPose = curRobotPose.inverse() * getGraspPoseInGlobal();
49  return graspPose;
50 }
51 
53 GraspCandidateHelper::getPrePoseInRobotRoot(float approachDistance) const
54 {
55  return math::Helpers::TranslatePose(getGraspPoseInRobotRoot(),
56  getApproachVector() * approachDistance);
57 }
58 
61 {
62  return getGraspPoseInRobotRoot().topLeftCorner<3, 3>();
63 }
64 
65 Eigen::Vector3f
67 {
68  return math::Helpers::GetPosition(getGraspPoseInRobotRoot());
69 }
70 
73 {
74  // We must use the original robot pose from when the grasp was generated (stored in the grasp candidate).
75  const Eigen::Matrix4f originalGraspPose = fromIce(candidate->graspPose);
76  const Eigen::Matrix4f originalRobotPose = fromIce(candidate->robotPose);
77  return originalRobotPose * originalGraspPose;
78 }
79 
82 {
83  return getGraspPoseInGlobal().topLeftCorner<3, 3>();
84 }
85 
86 Eigen::Vector3f
88 {
89  return math::Helpers::GetPosition(getGraspPoseInGlobal());
90 }
91 
92 Eigen::Vector3f
94 {
95  return fromIce(candidate->approachVector);
96 }
97 
98 bool
100 {
101  return candidate->executionHints->approach == grasping::ApproachType::TopApproach;
102 }
103 
104 bool
106 {
107  return candidate->executionHints->approach == grasping::ApproachType::SideApproach;
108 }
109 
110 void
111 GraspCandidateHelper::setGraspCandidate(const grasping::GraspCandidatePtr& p)
112 {
114  candidate = p;
115 }
armarx::GraspCandidateHelper::setGraspCandidate
void setGraspCandidate(const grasping::GraspCandidatePtr &p)
Definition: GraspCandidateHelper.cpp:111
armarx::GraspCandidateHelper::getGraspPoseInRobotRoot
Eigen::Matrix4f getGraspPoseInRobotRoot() const
Definition: GraspCandidateHelper.cpp:42
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::GraspCandidateHelper::isTopGrasp
bool isTopGrasp()
Definition: GraspCandidateHelper.cpp:99
armarx::GraspCandidateHelper::GraspCandidateHelper
GraspCandidateHelper()=default
armarx::GraspCandidateHelper::getGraspPositionInRobotRoot
Eigen::Vector3f getGraspPositionInRobotRoot() const
Definition: GraspCandidateHelper.cpp:66
GraspCandidateHelper.h
armarx::GraspCandidateHelper::getGraspOrientationInRobotRoot
Eigen::Matrix3f getGraspOrientationInRobotRoot() const
Definition: GraspCandidateHelper.cpp:60
armarx::GraspCandidateHelper::getApproachVector
Eigen::Vector3f getApproachVector() const
Definition: GraspCandidateHelper.cpp:93
armarx::GraspCandidateHelper::getGraspPositionInGlobal
Eigen::Vector3f getGraspPositionInGlobal() const
Definition: GraspCandidateHelper.cpp:87
armarx::GraspCandidateHelper::getPrePoseInRobotRoot
Eigen::Matrix4f getPrePoseInRobotRoot(float approachDistance) const
Definition: GraspCandidateHelper.cpp:53
armarx::fromIce
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:27
ExpressionException.h
armarx::GraspCandidateHelper::isSideGrasp
bool isSideGrasp()
Definition: GraspCandidateHelper.cpp:105
armarx::GraspCandidateHelper::getGraspPoseInGlobal
Eigen::Matrix4f getGraspPoseInGlobal() const
Definition: GraspCandidateHelper.cpp:72
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::GraspCandidateHelper::getGraspOrientationInGlobal
Eigen::Matrix3f getGraspOrientationInGlobal() const
Definition: GraspCandidateHelper.cpp:81
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