GraspObjectUtil.cpp
Go to the documentation of this file.
1#include <SimoxUtility/algorithm/string/string_tools.h>
2#include "GraspObjectUtil.h"
3
4#include <VirtualRobot/Grasping/GraspSet.h>
5#include <VirtualRobot/ManipulationObject.h>
6#include <VirtualRobot/RobotNodeSet.h>
7
9
10namespace armarx::skills
11{
13 {
14 SelectBestKinematicChainForObjectGraspOutput
17 {
19 out.distanceToObject = std::numeric_limits<float>::max();
20 out.tcpName = "";
21 out.kinematicChainName = "";
22 int numOfJoints = std::numeric_limits<int>::max();
23
24 std::vector<VirtualRobot::RobotNodeSetPtr> possibleNodeSets;
25 for (const auto& nodeSet : in.synchronizedRobot.getRobotNodeSets())
26 {
27 // Here i hardcoded some requrements for the robot nodes. Not sure whether this is true for all our robots
28 if (nodeSet->getTCP() and simox::alg::contains(nodeSet->getName(), "Arm") and
29 !simox::alg::contains(nodeSet->getName(), "ColModel") and
30 simox::alg::starts_with(nodeSet->getTCP()->getName(), "TCP"))
31 {
32 ARMARX_INFO << "Found possible node set for grasp: " << nodeSet->getName()
33 << ". The TCP is: " << nodeSet->getTCP()->getName();
34 auto nodeSetName = nodeSet->getName();
35 auto tcpName = nodeSet->getTCP()->getName();
36 auto tcpPoseGlobal =
37 in.synchronizedRobot.getRobotNode(tcpName)->getGlobalPose();
38 auto currentNumOfJoints = nodeSet->size();
39
40 auto distance = (in.objectPose.objectPoseGlobal.block<3, 1>(0, 3) -
41 tcpPoseGlobal.block<3, 1>(0, 3))
42 .norm();
43
44 if ((tcpName == out.tcpName &&
45 numOfJoints >
46 (int)
47 currentNumOfJoints) or // We found a better kinematic chain with less nodes in it but it has the same tcp
48 (distance < out.distanceToObject)) // the distance is better of that tcp
49 {
50 ARMARX_INFO << "Deciding to use this kinematic chain: " << VAROUT(tcpName)
51 << ", " << VAROUT(distance) << " <-> "
52 << VAROUT(out.distanceToObject) << ", "
53 << VAROUT(currentNumOfJoints) << " <-> " << VAROUT(numOfJoints);
54 out.kinematicChainName = nodeSetName;
55 out.tcpName = tcpName;
57 numOfJoints = currentNumOfJoints;
58 }
59 }
60 }
61 return out;
62 }
63
64 SelectBestGraspSetForObjectOutput
66 {
68 out.graspSetName = "";
69
70 for (const auto& [name, gs] : in.graspInfo.graspSets)
71 {
72 // Check if grasp is applicable
73 if (gs.endeffector != in.tcpName)
74 {
75 continue;
76 }
77
78 // GraspSet is ok
79 out.graspSetName = name;
80 out.graspSet = gs;
81 }
82 return out;
83 }
84
85 GetPlatformOffsetForObjectGraspOutput
87 {
89
90 auto tcpPoseLocal = in.synchronizedRobot.getRobotNode(in.tcpName)->getPoseInRootFrame();
91 auto targetPlatformPoseLocal =
92 in.synchronizedRobot.getRootNode()->toLocalCoordinateSystem(
94
95 targetPlatformPoseLocal(1, 3) += -600;
96 if (tcpPoseLocal(0, 3) < 0) // Left Hand
97 {
98 targetPlatformPoseLocal(0, 3) += 100;
99 }
100 else
101 {
102 targetPlatformPoseLocal(0, 3) += -100;
103 }
104
106 in.synchronizedRobot.getRootNode()->getGlobalPose() * targetPlatformPoseLocal;
107 out.distanceToDrive =
108 (in.synchronizedRobot.getRootNode()->getGlobalPose().block<3, 1>(0, 3) -
109 out.platformGlobalPose.block<3, 1>(0, 3))
110 .norm(); // only calc cartesian distance
111
112 //ARMARX_INFO << "In order to grasp an object the robot should drive from " << in.synchronizedRobot.getRootNode()->getGlobalPose() << " to " << out.platformGlobalPose << "(distance: " << out.distanceToDrive << ").";
113 return out;
114 }
115
116 GetPlatformOffsetAfterObjectGraspOutput
118 {
120
121 Eigen::Matrix4f movePlatformBack = Eigen::Matrix4f::Identity();
122 movePlatformBack(1, 3) = -400;
123
125 in.synchronizedRobot.getRootNode()->getGlobalPose() * movePlatformBack;
126 out.distanceToDrive =
127 (in.synchronizedRobot.getRootNode()->getGlobalPose().block<3, 1>(0, 3) -
128 out.platformGlobalPose.block<3, 1>(0, 3))
129 .norm(); // only calc cartesian distance
130
131 //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 << ").";
132 return out;
133 }
134 } // namespace grasp_control::util
135} // 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