GraspObjectUtil.cpp
Go to the documentation of this file.
1#include "GraspObjectUtil.h"
2
3#include <VirtualRobot/Grasping/GraspSet.h>
4#include <VirtualRobot/ManipulationObject.h>
5#include <VirtualRobot/RobotNodeSet.h>
6
8
9namespace armarx::skills
10{
12 {
13 SelectBestKinematicChainForObjectGraspOutput
16 {
18 out.distanceToObject = std::numeric_limits<float>::max();
19 out.tcpName = "";
20 out.kinematicChainName = "";
21 int numOfJoints = std::numeric_limits<int>::max();
22
23 std::vector<VirtualRobot::RobotNodeSetPtr> possibleNodeSets;
24 for (const auto& nodeSet : in.synchronizedRobot.getRobotNodeSets())
25 {
26 // Here i hardcoded some requrements for the robot nodes. Not sure whether this is true for all our robots
27 if (nodeSet->getTCP() and simox::alg::contains(nodeSet->getName(), "Arm") and
28 !simox::alg::contains(nodeSet->getName(), "ColModel") and
29 simox::alg::starts_with(nodeSet->getTCP()->getName(), "TCP"))
30 {
31 ARMARX_INFO << "Found possible node set for grasp: " << nodeSet->getName()
32 << ". The TCP is: " << nodeSet->getTCP()->getName();
33 auto nodeSetName = nodeSet->getName();
34 auto tcpName = nodeSet->getTCP()->getName();
35 auto tcpPoseGlobal =
36 in.synchronizedRobot.getRobotNode(tcpName)->getGlobalPose();
37 auto currentNumOfJoints = nodeSet->size();
38
39 auto distance = (in.objectPose.objectPoseGlobal.block<3, 1>(0, 3) -
40 tcpPoseGlobal.block<3, 1>(0, 3))
41 .norm();
42
43 if ((tcpName == out.tcpName &&
44 numOfJoints >
45 (int)
46 currentNumOfJoints) or // We found a better kinematic chain with less nodes in it but it has the same tcp
47 (distance < out.distanceToObject)) // the distance is better of that tcp
48 {
49 ARMARX_INFO << "Deciding to use this kinematic chain: " << VAROUT(tcpName)
50 << ", " << VAROUT(distance) << " <-> "
51 << VAROUT(out.distanceToObject) << ", "
52 << VAROUT(currentNumOfJoints) << " <-> " << VAROUT(numOfJoints);
53 out.kinematicChainName = nodeSetName;
54 out.tcpName = tcpName;
56 numOfJoints = currentNumOfJoints;
57 }
58 }
59 }
60 return out;
61 }
62
63 SelectBestGraspSetForObjectOutput
65 {
67 out.graspSetName = "";
68
69 for (const auto& [name, gs] : in.graspInfo.graspSets)
70 {
71 // Check if grasp is applicable
72 if (gs.endeffector != in.tcpName)
73 {
74 continue;
75 }
76
77 // GraspSet is ok
78 out.graspSetName = name;
79 out.graspSet = gs;
80 }
81 return out;
82 }
83
84 GetPlatformOffsetForObjectGraspOutput
86 {
88
89 auto tcpPoseLocal = in.synchronizedRobot.getRobotNode(in.tcpName)->getPoseInRootFrame();
90 auto targetPlatformPoseLocal =
91 in.synchronizedRobot.getRootNode()->toLocalCoordinateSystem(
93
94 targetPlatformPoseLocal(1, 3) += -600;
95 if (tcpPoseLocal(0, 3) < 0) // Left Hand
96 {
97 targetPlatformPoseLocal(0, 3) += 100;
98 }
99 else
100 {
101 targetPlatformPoseLocal(0, 3) += -100;
102 }
103
105 in.synchronizedRobot.getRootNode()->getGlobalPose() * targetPlatformPoseLocal;
106 out.distanceToDrive =
107 (in.synchronizedRobot.getRootNode()->getGlobalPose().block<3, 1>(0, 3) -
108 out.platformGlobalPose.block<3, 1>(0, 3))
109 .norm(); // only calc cartesian distance
110
111 //ARMARX_INFO << "In order to grasp an object the robot should drive from " << in.synchronizedRobot.getRootNode()->getGlobalPose() << " to " << out.platformGlobalPose << "(distance: " << out.distanceToDrive << ").";
112 return out;
113 }
114
115 GetPlatformOffsetAfterObjectGraspOutput
117 {
119
120 Eigen::Matrix4f movePlatformBack = Eigen::Matrix4f::Identity();
121 movePlatformBack(1, 3) = -400;
122
124 in.synchronizedRobot.getRootNode()->getGlobalPose() * movePlatformBack;
125 out.distanceToDrive =
126 (in.synchronizedRobot.getRootNode()->getGlobalPose().block<3, 1>(0, 3) -
127 out.platformGlobalPose.block<3, 1>(0, 3))
128 .norm(); // only calc cartesian distance
129
130 //ARMARX_INFO << "In order to retreat from a grasp an object the robot should drive from " << in.synchronizedRobot.getRootNode()->getGlobalPose() << " to " << out.platformGlobalPose << "(distance: " << out.distanceToDrive << ").";
131 return out;
132 }
133 } // namespace grasp_control::util
134} // namespace armarx::skills
#define VAROUT(x)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
SelectBestKinematicChainForObjectGraspOutput SelectBestKinematicChainForObjectGrasp(const SelectBestKinematicChainForObjectGraspInput &in)
GetPlatformOffsetAfterObjectGraspOutput GetGlobalPlatformPoseAfterObjectGrasp(const GetPlatformOffsetAfterObjectGraspInput &in)
SelectBestGraspSetForObjectOutput SelectBestGraspSetForObject(const SelectBestGraspSetForObjectInput &in)
GetPlatformOffsetForObjectGraspOutput GetGlobalPlatformPoseForObjectGrasp(const GetPlatformOffsetForObjectGraspInput &in)
This file is part of ArmarX.
double norm(const Point &a)
Definition point.hpp:102
double distance(const Point &a, const Point &b)
Definition point.hpp:95
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition ObjectPose.h:71
armarx::armem::grasping::arondto::KnownGraspSet graspSet