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 
9 namespace armarx::skills
10 {
11  namespace grasp_control::util
12  {
16  {
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 
104  out.platformGlobalPose =
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 
123  out.platformGlobalPose =
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
armarx::skills::grasp_control::util::SelectBestGraspSetForObjectOutput::graspSet
armarx::armem::grasping::arondto::KnownGraspSet graspSet
Definition: GraspObjectUtil.h:36
armarx::skills::grasp_control::util::GetGlobalPlatformPoseForObjectGrasp
GetPlatformOffsetForObjectGraspOutput GetGlobalPlatformPoseForObjectGrasp(const GetPlatformOffsetForObjectGraspInput &in)
Definition: GraspObjectUtil.cpp:85
armarx::skills
This file is part of ArmarX.
Definition: PeriodicUpdateWidget.cpp:11
armarx::skills::grasp_control::util::SelectBestGraspSetForObject
SelectBestGraspSetForObjectOutput SelectBestGraspSetForObject(const SelectBestGraspSetForObjectInput &in)
Definition: GraspObjectUtil.cpp:64
armarx::skills::grasp_control::util::SelectBestKinematicChainForObjectGraspOutput::tcpName
std::string tcpName
Definition: GraspObjectUtil.h:19
armarx::skills::grasp_control::util::GetPlatformOffsetForObjectGraspOutput::distanceToDrive
float distanceToDrive
Definition: GraspObjectUtil.h:53
armarx::skills::grasp_control::util::SelectBestKinematicChainForObjectGraspOutput::distanceToObject
float distanceToObject
Definition: GraspObjectUtil.h:21
GraspObjectUtil.h
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:43
armarx::skills::grasp_control::util::GetPlatformOffsetForObjectGraspInput
Definition: GraspObjectUtil.h:42
armarx::skills::grasp_control::util::GetPlatformOffsetForObjectGraspInput::objectPose
armarx::objpose::ObjectPose & objectPose
Definition: GraspObjectUtil.h:44
armarx::armem::contains
bool contains(const MemoryID &general, const MemoryID &specific)
Indicates whether general is "less specific" than, or equal to, specific, i.e.
Definition: MemoryID.cpp:558
armarx::skills::grasp_control::util::SelectBestKinematicChainForObjectGraspInput
Definition: GraspObjectUtil.h:10
armarx::skills::grasp_control::util::SelectBestKinematicChainForObjectGraspOutput
Definition: GraspObjectUtil.h:17
armarx::skills::grasp_control::util::GetPlatformOffsetAfterObjectGraspInput::synchronizedRobot
VirtualRobot::Robot & synchronizedRobot
Definition: GraspObjectUtil.h:61
armarx::skills::grasp_control::util::GetPlatformOffsetForObjectGraspOutput
Definition: GraspObjectUtil.h:50
armarx::skills::grasp_control::util::SelectBestKinematicChainForObjectGraspInput::objectPose
armarx::objpose::ObjectPose & objectPose
Definition: GraspObjectUtil.h:12
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
FramedPose.h
armarx::skills::grasp_control::util::GetPlatformOffsetAfterObjectGraspOutput::platformGlobalPose
Eigen::Matrix4f platformGlobalPose
Definition: GraspObjectUtil.h:66
armarx::skills::grasp_control::util::GetPlatformOffsetAfterObjectGraspOutput::distanceToDrive
float distanceToDrive
Definition: GraspObjectUtil.h:67
armarx::skills::grasp_control::util::SelectBestGraspSetForObjectInput::graspInfo
armem::grasping::arondto::KnownGraspInfo & graspInfo
Definition: GraspObjectUtil.h:29
armarx::skills::grasp_control::util::SelectBestGraspSetForObjectOutput::graspSetName
std::string graspSetName
Definition: GraspObjectUtil.h:35
armarx::skills::grasp_control::util::GetPlatformOffsetAfterObjectGraspInput
Definition: GraspObjectUtil.h:59
armarx::skills::grasp_control::util::GetPlatformOffsetAfterObjectGraspOutput
Definition: GraspObjectUtil.h:64
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::skills::grasp_control::util::GetGlobalPlatformPoseAfterObjectGrasp
GetPlatformOffsetAfterObjectGraspOutput GetGlobalPlatformPoseAfterObjectGrasp(const GetPlatformOffsetAfterObjectGraspInput &in)
Definition: GraspObjectUtil.cpp:116
armarx::skills::grasp_control::util::SelectBestGraspSetForObjectInput
Definition: GraspObjectUtil.h:27
armarx::skills::grasp_control::util::SelectBestGraspSetForObjectInput::tcpName
std::string tcpName
Definition: GraspObjectUtil.h:30
armarx::skills::grasp_control::util::GetPlatformOffsetForObjectGraspOutput::platformGlobalPose
Eigen::Matrix4f platformGlobalPose
Definition: GraspObjectUtil.h:52
armarx::skills::grasp_control::util::SelectBestKinematicChainForObjectGrasp
SelectBestKinematicChainForObjectGraspOutput SelectBestKinematicChainForObjectGrasp(const SelectBestKinematicChainForObjectGraspInput &in)
Definition: GraspObjectUtil.cpp:14
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::objpose::ObjectPose::objectPoseGlobal
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition: ObjectPose.h:73
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::skills::grasp_control::util::GetPlatformOffsetForObjectGraspInput::synchronizedRobot
VirtualRobot::Robot & synchronizedRobot
Definition: GraspObjectUtil.h:46
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::skills::grasp_control::util::SelectBestKinematicChainForObjectGraspOutput::kinematicChainName
std::string kinematicChainName
Definition: GraspObjectUtil.h:20
armarx::skills::grasp_control::util::GetPlatformOffsetForObjectGraspInput::tcpName
std::string tcpName
Definition: GraspObjectUtil.h:47
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:88
armarx::skills::grasp_control::util::SelectBestGraspSetForObjectOutput
Definition: GraspObjectUtil.h:33
armarx::skills::grasp_control::util::SelectBestKinematicChainForObjectGraspInput::synchronizedRobot
VirtualRobot::Robot & synchronizedRobot
Definition: GraspObjectUtil.h:14
norm
double norm(const Point &a)
Definition: point.hpp:94