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
25
26#include <VirtualRobot/Robot.h>
27#include <VirtualRobot/math/Helpers.h>
28
30
31using namespace armarx;
32
33GraspCandidateHelper::GraspCandidateHelper(const grasping::GraspCandidatePtr& candidate,
35 candidate(candidate), robot(robot)
36{
37 ARMARX_CHECK_NOT_NULL(candidate);
39}
40
41Eigen::Matrix4f
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
52Eigen::Matrix4f
54{
55 return math::Helpers::TranslatePose(getGraspPoseInRobotRoot(),
56 getApproachVector() * approachDistance);
57}
58
59Eigen::Matrix3f
61{
62 return getGraspPoseInRobotRoot().topLeftCorner<3, 3>();
63}
64
65Eigen::Vector3f
67{
68 return math::Helpers::GetPosition(getGraspPoseInRobotRoot());
69}
70
71Eigen::Matrix4f
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
80Eigen::Matrix3f
82{
83 return getGraspPoseInGlobal().topLeftCorner<3, 3>();
84}
85
86Eigen::Vector3f
88{
89 return math::Helpers::GetPosition(getGraspPoseInGlobal());
90}
91
92Eigen::Vector3f
94{
95 return fromIce(candidate->approachVector);
96}
97
98bool
100{
101 return candidate->executionHints->approach == grasping::ApproachType::TopApproach;
102}
103
104bool
106{
107 return candidate->executionHints->approach == grasping::ApproachType::SideApproach;
108}
109
110void
111GraspCandidateHelper::setGraspCandidate(const grasping::GraspCandidatePtr& p)
112{
114 candidate = p;
115}
Eigen::Vector3f getApproachVector() const
Eigen::Vector3f getGraspPositionInRobotRoot() const
Eigen::Matrix3f getGraspOrientationInRobotRoot() const
Eigen::Matrix4f getPrePoseInRobotRoot(float approachDistance) const
Eigen::Matrix4f getGraspPoseInGlobal() const
Eigen::Matrix3f getGraspOrientationInGlobal() const
void setGraspCandidate(const grasping::GraspCandidatePtr &p)
Eigen::Matrix4f getGraspPoseInRobotRoot() const
Eigen::Vector3f getGraspPositionInGlobal() const
#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...
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)