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 #include <VirtualRobot/math/Helpers.h>
26 
28 
29 using namespace armarx;
30 
31 
32 GraspCandidateHelper::GraspCandidateHelper(const grasping::GraspCandidatePtr& candidate, VirtualRobot::RobotPtr robot)
33  : candidate(candidate), robot(robot)
34 {
35  ARMARX_CHECK_NOT_NULL(candidate);
36  ARMARX_CHECK_NOT_NULL(robot);
37 }
38 
40 {
41  /* As the (current) robot might have moved after the grasp was generated,
42  * we must first transform the grasp to global with its original robot pose (stored in the grasp),
43  * then transform it to the current robot frame. */
44  const Eigen::Matrix4f curRobotPose = robot->getGlobalPose();
45  const Eigen::Matrix4f graspPose = curRobotPose.inverse() * getGraspPoseInGlobal();
46  return graspPose;
47 }
48 
50 {
51  return math::Helpers::TranslatePose(getGraspPoseInRobotRoot(), getApproachVector() * approachDistance);
52 }
53 
55 {
56  return getGraspPoseInRobotRoot().topLeftCorner<3, 3>();
57 }
58 
60 {
61  return math::Helpers::GetPosition(getGraspPoseInRobotRoot());
62 }
63 
65 {
66  // We must use the original robot pose from when the grasp was generated (stored in the grasp candidate).
67  const Eigen::Matrix4f originalGraspPose = fromIce(candidate->graspPose);
68  const Eigen::Matrix4f originalRobotPose = fromIce(candidate->robotPose);
69  return originalRobotPose * originalGraspPose;
70 }
72 {
73  return getGraspPoseInGlobal().topLeftCorner<3, 3>();
74 }
76 {
77  return math::Helpers::GetPosition(getGraspPoseInGlobal());
78 }
79 
81 {
82  return fromIce(candidate->approachVector);
83 }
84 
86 {
87  return candidate->executionHints->approach == grasping::ApproachType::TopApproach;
88 }
89 
91 {
92  return candidate->executionHints->approach == grasping::ApproachType::SideApproach;
93 }
94 
95 
96 void GraspCandidateHelper::setGraspCandidate(const grasping::GraspCandidatePtr& p)
97 {
99  candidate = p;
100 }
armarx::GraspCandidateHelper::setGraspCandidate
void setGraspCandidate(const grasping::GraspCandidatePtr &p)
Definition: GraspCandidateHelper.cpp:96
armarx::GraspCandidateHelper::getGraspPoseInRobotRoot
Eigen::Matrix4f getGraspPoseInRobotRoot() const
Definition: GraspCandidateHelper.cpp:39
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:85
armarx::GraspCandidateHelper::GraspCandidateHelper
GraspCandidateHelper()=default
armarx::GraspCandidateHelper::getGraspPositionInRobotRoot
Eigen::Vector3f getGraspPositionInRobotRoot() const
Definition: GraspCandidateHelper.cpp:59
GraspCandidateHelper.h
armarx::GraspCandidateHelper::getGraspOrientationInRobotRoot
Eigen::Matrix3f getGraspOrientationInRobotRoot() const
Definition: GraspCandidateHelper.cpp:54
armarx::GraspCandidateHelper::getApproachVector
Eigen::Vector3f getApproachVector() const
Definition: GraspCandidateHelper.cpp:80
armarx::GraspCandidateHelper::getGraspPositionInGlobal
Eigen::Vector3f getGraspPositionInGlobal() const
Definition: GraspCandidateHelper.cpp:75
armarx::GraspCandidateHelper::getPrePoseInRobotRoot
Eigen::Matrix4f getPrePoseInRobotRoot(float approachDistance) const
Definition: GraspCandidateHelper.cpp:49
armarx::fromIce
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:26
ExpressionException.h
armarx::GraspCandidateHelper::isSideGrasp
bool isSideGrasp()
Definition: GraspCandidateHelper.cpp:90
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::GraspCandidateHelper::getGraspPoseInGlobal
Eigen::Matrix4f getGraspPoseInGlobal() const
Definition: GraspCandidateHelper.cpp:64
armarx::GraspCandidateHelper::getGraspOrientationInGlobal
Eigen::Matrix3f getGraspOrientationInGlobal() const
Definition: GraspCandidateHelper.cpp:71
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