ExecutePutdown.cpp
Go to the documentation of this file.
1 #include "ExecutePutdown.h"
2 
3 #include <VirtualRobot/RobotNodeSet.h>
4 
6 #include <RobotAPI/libraries/skills/provider/SkillProxy.h>
7 
10 
11 #include "util/PutdownObjectUtil.h"
12 
13 namespace armarx::skills
14 {
15  namespace
16  {
17  grasp_object::arondto::ExecutePutdownAcceptedType
18  GetDefaultParameterization()
19  {
20  grasp_object::arondto::ExecutePutdownAcceptedType ret;
21  ret.orientationalAccuracy = 0.01;
22  ret.positionalAccuracy = 25;
23  return ret;
24  }
25  } // namespace
26 
27  SkillDescription ExecutePutdownSkill::Description =
28  skills::SkillDescription{"ExecutePutdown",
29  "Execute a putdown for some grasped object",
30  {},
32  grasp_object::arondto::ExecutePutdownAcceptedType::ToAronType(),
33  GetDefaultParameterization().toAron()};
34 
36  armarx::viz::Client& arviz,
38  TwoArmGraspControlSkill(mns, arviz, Description.skillName, context),
39  SimpleSpecializedSkill<ArgType>(Description)
40  {
41  }
42 
44  ExecutePutdownSkill::main(const SpecializedMainInput& in)
45  {
47  armem::obj::instance::Reader objectReader(mns);
49 
50  robotReader.connect();
51  objectReader.connect();
52  graspReader.connect();
53 
54  // //////////////////////////////
55  // get robot
56  // //////////////////////////////
57  auto robot =
58  robotReader.getSynchronizedRobot(in.parameters.robotName,
60  VirtualRobot::RobotIO::RobotDescription::eStructure);
61  if (!robot)
62  {
63  ARMARX_ERROR << "Lost robot.";
64  return {TerminatedSkillStatus::Failed, nullptr};
65  }
66 
67  // //////////////////////////////
68  // get object pose
69  // //////////////////////////////
70  auto objInstance = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
71  if (!objInstance)
72  {
73  ARMARX_ERROR << "Lost object pose.";
74  return {TerminatedSkillStatus::Failed, nullptr};
75  }
76 
77 
78  ARMARX_CHECK(objInstance->attachment->agentName == in.parameters.robotName);
79 
80  std::string kinematicChainName = "LeftArm";
81  std::string otherArmKinematicChainName = "RightArm";
82  if (simox::alg::ends_with(objInstance->attachment->frameName, " R"))
83  {
84  kinematicChainName = "RightArm";
85  otherArmKinematicChainName = "LeftArm";
86  }
87 
88  // //////////////////////////////
89  // Move TCPs
90  // //////////////////////////////
91  {
92  skills::joint_control::arondto::MoveJointsToPositionAcceptedType params;
93  params.robotName = in.parameters.robotName;
94  params.jointTargetTolerance = 0.03;
95  params.jointMaxSpeed = 0.75;
96  params.accelerationTime = 500;
97  params.setVelocitiesToZeroAtEnd = true;
98 
99  params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
100  ->getNodeNames()[0]] = 0.47;
101  params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
102  ->getNodeNames()[1]] = 0.0;
103  params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
104  ->getNodeNames()[2]] = 0.0;
105  params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
106  ->getNodeNames()[3]] = 0.32;
107  params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
108  ->getNodeNames()[4]] = 0.47;
109 
110  SkillProxy prx({manager,
113 
114  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
116  {
117  return {TerminatedSkillStatus::Failed, nullptr};
118  }
119  }
120 
121  // Look at hand
122  {
123  skills::joint_control::arondto::MoveJointsToPositionAcceptedType params;
124  params.robotName = in.parameters.robotName;
125  params.jointTargetTolerance = 0.03; // Todo
126  params.jointMaxSpeed = 0.75;
127  params.accelerationTime = 500;
128  params.setVelocitiesToZeroAtEnd = true;
129  params.targetJointMap["Neck_1_Pitch"] = 0.6;
130 
131  SkillProxy prx({manager,
134 
135  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
137  {
138  return {TerminatedSkillStatus::Failed, nullptr};
139  }
140  }
141 
142  ARMARX_CHECK(robotReader.synchronizeRobot(*robot, armem::Time::Now()));
143 
144  const auto objPoseLocal = objInstance->objectPoseRobot;
145  const auto objPoseGlobal = robot->getRootNode()->toGlobalCoordinateSystem(objPoseLocal);
146  const auto objectInTCPFrame = objInstance->attachment->poseInFrame;
147  Eigen::Matrix4f tcpPlacePoseGlobal = objPoseGlobal * objectInTCPFrame.inverse();
148  tcpPlacePoseGlobal(2, 3) += 50;
149 
150  auto tcpPlacePrePoseGlobal = tcpPlacePoseGlobal;
151  tcpPlacePrePoseGlobal(2, 3) += 80;
152 
153  std::vector<Eigen::Matrix4f> targetPosesGlobal = {tcpPlacePrePoseGlobal,
154  tcpPlacePoseGlobal};
155 
156  for (const auto& tcpTargetPoseGlobal : targetPosesGlobal)
157  {
158  skills::tcp_control::arondto::MoveTCPToTargetPoseAcceptedType params;
159  params.robotName = in.parameters.robotName;
160  params.kinematicChainName = kinematicChainName;
161  params.targetPoseGlobal = tcpTargetPoseGlobal;
162  params.orientationalAccuracy = in.parameters.orientationalAccuracy;
163  params.positionalAccuracy = in.parameters.positionalAccuracy;
164 
165  SkillProxy prx({manager,
168 
169  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
171  {
172  return {TerminatedSkillStatus::Failed, nullptr};
173  }
174  }
175 
176  // Look up
177  {
178  skills::joint_control::arondto::MoveJointsToPositionAcceptedType params;
179  params.robotName = in.parameters.robotName;
180  params.jointTargetTolerance = 0.03; // Todo
181  params.jointMaxSpeed = 0.75;
182  params.accelerationTime = 500;
183  params.setVelocitiesToZeroAtEnd = true;
184  params.targetJointMap["Neck_1_Pitch"] = 0.0;
185 
186  SkillProxy prx({manager,
189 
190  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
192  {
193  return {TerminatedSkillStatus::Failed, nullptr};
194  }
195  }
196 
197  return {TerminatedSkillStatus::Succeeded, nullptr};
198  }
199 } // 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
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
armarx::armem::obj::instance::Reader
Definition: ObjectReader.h:40
armarx::skills::ExecutePutdownSkill::Description
static SkillDescription Description
Definition: ExecutePutdown.h:27
armarx::skills::ExecutePutdownSkill::ArgType
grasp_object::arondto::ExecutePutdownAcceptedType ArgType
Definition: ExecutePutdown.h:19
PutdownObjectUtil.h
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::skills::TwoArmGraspControlSkillContext::jointControlSkillProvider
std::string jointControlSkillProvider
Definition: GraspControlSkill.h:50
FramedPose.h
MoveJointsToPosition.h
armarx::armem::grasping::known_grasps::Reader
Definition: KnownGraspCandidateReader.h:35
armarx::skills::SimpleSpecializedSkill
Definition: SimpleSpecializedSkill.h:10
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::skills::ExecutePutdownSkill::ExecutePutdownSkill
ExecutePutdownSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, TwoArmGraspControlSkillContext &)
Definition: ExecutePutdown.cpp:35
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::ExecutePutdownAcceptedType >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
ExecutePutdown.h
armarx::skills::MoveTCPToTargetPose::Description
static SkillDescription Description
Definition: MoveTCPToTargetPose.h:50
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp: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
armarx::skills::MoveJointsToPosition::Description
static SkillDescription Description
Definition: MoveJointsToPosition.h:48