ExecuteGrasp.cpp
Go to the documentation of this file.
1 #include "ExecuteGrasp.h"
2 
4 #include <RobotAPI/libraries/skills/provider/SkillProxy.h>
5 
7 
8 #include "util/GraspObjectUtil.h"
9 
10 namespace armarx::skills
11 {
12  namespace
13  {
14  grasp_object::arondto::ExecuteGraspAcceptedType
15  GetDefaultParameterization()
16  {
17  grasp_object::arondto::ExecuteGraspAcceptedType ret;
18  ret.orientationalAccuracy = 0.01;
19  ret.positionalAccuracy = 25;
20  return ret;
21  }
22  } // namespace
23 
24  SkillDescription ExecuteGraspSkill::Description =
25  skills::SkillDescription{"ExecuteGrasp",
26  "Execute a graspset on some object",
27  {},
29  grasp_object::arondto::ExecuteGraspAcceptedType::ToAronType(),
30  GetDefaultParameterization().toAron()};
31 
33  armarx::viz::Client& arviz,
35  TwoArmGraspControlSkill(mns, arviz, Description.skillName, context),
36  SimpleSpecializedSkill<ArgType>(Description)
37  {
38  }
39 
41  ExecuteGraspSkill::main(const SpecializedMainInput& in)
42  {
44  armem::obj::instance::Reader objectReader(mns);
46 
47  robotReader.connect();
48  objectReader.connect();
49  graspReader.connect();
50 
51  // //////////////////////////////
52  // get robot
53  // //////////////////////////////
54  auto robot =
55  robotReader.getSynchronizedRobot(in.parameters.robotName,
57  VirtualRobot::RobotIO::RobotDescription::eStructure);
58  if (!robot)
59  {
60  ARMARX_ERROR << "Lost robot.";
61  return {TerminatedSkillStatus::Failed, nullptr};
62  }
63 
64  // //////////////////////////////
65  // get object pose
66  // //////////////////////////////
67  auto objInstance = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
68  if (!objInstance)
69  {
70  ARMARX_ERROR << "Lost object pose.";
71  return {TerminatedSkillStatus::Failed, nullptr};
72  }
73 
74  // //////////////////////////////
75  // get all possible grasps
76  // //////////////////////////////
77  auto graspInfo = graspReader.queryKnownGraspInfoByEntityName(in.parameters.objectEntityId,
79  if (!graspInfo)
80  {
81  ARMARX_ERROR << "Lost grasp info.";
82  return {TerminatedSkillStatus::Failed, nullptr};
83  }
84 
85  if (const auto& it = graspInfo->graspSets.find(in.parameters.graspSetName);
86  it == graspInfo->graspSets.end())
87  {
88  ARMARX_ERROR << "Grasp set name " << in.parameters.graspSetName << " not found.";
89  return {TerminatedSkillStatus::Failed, nullptr};
90  }
91 
92  for (const auto& grasp : graspInfo->graspSets.at(in.parameters.graspSetName).grasps)
93  {
94  {
95  // Generate Grasp
96  auto objPose = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
97 
98  const Eigen::Matrix4f graspPoseGlobal =
99  objPose->objectPoseGlobal * grasp.pose.inverse();
100  const Eigen::Matrix4f tcpTargetPoseGlobal = graspPoseGlobal;
101 
102  //}
103 
104  // Move TCP to poses
105  //{
106  skills::tcp_control::arondto::MoveTCPToTargetPoseAcceptedType params;
107  params.robotName = in.parameters.robotName;
108  params.kinematicChainName = in.parameters.kinematicChainName;
109  params.targetPoseGlobal = tcpTargetPoseGlobal;
110  params.orientationalAccuracy = in.parameters.orientationalAccuracy;
111  params.positionalAccuracy = in.parameters.positionalAccuracy;
112 
113  SkillProxy prx({manager,
116 
117  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
119  {
120  return {TerminatedSkillStatus::Failed, nullptr};
121  }
122  }
123  }
124  return {TerminatedSkillStatus::Succeeded, nullptr};
125  }
126 } // namespace armarx::skills
armarx::skills::mixin::MNSSkillMixin::mns
armem::client::MemoryNameSystem mns
Definition: MNSSkillMixin.h:11
armarx::armem::robot_state::VirtualRobotReader
The VirtualRobotReader class.
Definition: VirtualRobotReader.h:40
armarx::skills::Skill::manager
manager::dti::SkillManagerInterfacePrx manager
Definition: Skill.h:327
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::skills::TerminatedSkillStatus::Succeeded
@ Succeeded
armarx::skills::ExecuteGraspSkill::ArgType
grasp_object::arondto::ExecuteGraspAcceptedType ArgType
Definition: ExecuteGrasp.h:19
armarx::skills
This file is part of ArmarX.
Definition: PeriodicUpdateWidget.cpp:11
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::skills::TwoArmGraspControlSkill::context
TwoArmGraspControlSkillContext & context
Definition: GraspControlSkill.h:84
GraspObjectUtil.h
armarx::armem::obj::instance::Reader
Definition: ObjectReader.h:40
ExecuteGrasp.h
FramedPose.h
armarx::armem::grasping::known_grasps::Reader
Definition: KnownGraspCandidateReader.h:35
armarx::skills::SimpleSpecializedSkill
Definition: SimpleSpecializedSkill.h:10
armarx::skills::ExecuteGraspSkill::Description
static SkillDescription Description
Definition: ExecuteGrasp.h:27
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::skills::ExecuteGraspSkill::ExecuteGraspSkill
ExecuteGraspSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, TwoArmGraspControlSkillContext &)
Definition: ExecuteGrasp.cpp:32
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:48
armarx::skills::TwoArmGraspControlSkillContext::tcpControlSkillProvider
std::string tcpControlSkillProvider
Definition: GraspControlSkill.h:49
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::skills::TerminatedSkillStatus::Failed
@ Failed
armarx::skills::SimpleSpecializedSkill< grasp_object::arondto::ExecuteGraspAcceptedType >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::skills::MoveTCPToTargetPose::Description
static SkillDescription Description
Definition: MoveTCPToTargetPose.h:50
armarx::skills::TwoArmGraspControlSkill
Definition: GraspControlSkill.h:77
armarx::viz::toString
const char * toString(InteractionFeedbackType type)
Definition: Interaction.h:27
armarx::skills::TwoArmGraspControlSkillContext
Definition: GraspControlSkill.h:46
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::viz::Client
Definition: Client.h:109
MoveTCPToTargetPose.h
armarx::skills::Skill::getSkillId
SkillID getSkillId() const
Get the id of the skill.
Definition: Skill.h:74
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55