PutdownObject.cpp
Go to the documentation of this file.
1 #include "PutdownObject.h"
2 
3 #include <VirtualRobot/Grasping/GraspSet.h>
4 #include <VirtualRobot/ManipulationObject.h>
5 #include <VirtualRobot/RobotNodeSet.h>
6 
8 #include <RobotAPI/libraries/skills/provider/SkillProxy.h>
9 
10 namespace armarx::skills
11 {
12  namespace
13  {
14  grasp_object::arondto::PutdownObjectAcceptedType
15  GetDefaultParameterization()
16  {
17  grasp_object::arondto::PutdownObjectAcceptedType ret;
18  ret.platformOrientationalAccuracy = 0.1;
19  ret.platformPositionalAccuracy = 10;
20  ret.tcpOrientationalAccuracy = 0.1;
21  ret.tcpPositionalAccuracy = 20;
22  return ret;
23  }
24  } // namespace
25 
26  SkillDescription PutdownObjectSkill::Description =
27  SkillDescription{"PutdownObject",
28  "Putdown an object already in hand of robot",
29  {},
31  grasp_object::arondto::PutdownObjectAcceptedType::ToAronType(),
32  GetDefaultParameterization().toAron()};
33 
35  armarx::viz::Client& arviz,
37  TwoArmGraspControlSkill(mns, arviz, Description.skillName, context),
38  SimpleSpecializedSkill<ArgType>(Description)
39  {
40  }
41 
43  PutdownObjectSkill::main(const SpecializedMainInput& in)
44  {
46  armem::obj::instance::Reader objectReader(mns);
48  armem::obj::instance::Writer objectWriter(mns);
49 
50  robotReader.connect();
51  objectReader.connect();
52  graspReader.connect();
53  objectWriter.connect();
54 
55  // //////////////////////////////
56  // get robot
57  // //////////////////////////////
58  auto robot =
59  robotReader.getSynchronizedRobot(in.parameters.robotName,
61  VirtualRobot::RobotIO::RobotDescription::eStructure);
62 
63  // //////////////////////////////
64  // get object pose
65  // //////////////////////////////
66  auto objInstance = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
67  if (!objInstance)
68  {
69  ARMARX_ERROR << "Lost object pose.";
70  return {TerminatedSkillStatus::Failed, nullptr};
71  }
72 
73 
74  ARMARX_CHECK(objInstance->attachment->agentName == in.parameters.robotName);
75 
76  std::string kinematicChainName = "LeftArm";
77  if (simox::alg::ends_with(objInstance->attachment->frameName, " R"))
78  {
79  kinematicChainName = "RightArm";
80  }
81 
82 
83  // //////////////////////////////
84  // Call subskills
85  // //////////////////////////////
86  // Move into a besser position
87  {
88  skills::grasp_object::arondto::MovePlatformForPutdownAcceptedType params;
89  params.robotName = in.parameters.robotName;
90  params.orientationalAccuracy = in.parameters.platformOrientationalAccuracy;
91  params.positionalAccuracy = in.parameters.platformPositionalAccuracy;
92  params.objectEntityId = in.parameters.objectEntityId;
93  params.tcpName = robot->getRobotNodeSet(kinematicChainName)->getTCP()->getName();
94 
95  SkillProxy prx(
96  manager, providerName, MovePlatformForPutdownSkill::Description.skillName);
97 
98  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
100  {
101  return {TerminatedSkillStatus::Failed, nullptr};
102  }
103  }
104 
105  // Execute Putdown motions
106  {
107  skills::grasp_object::arondto::ExecutePutdownAcceptedType params;
108  params.robotName = in.parameters.robotName;
109  params.orientationalAccuracy = in.parameters.platformOrientationalAccuracy;
110  params.positionalAccuracy = in.parameters.platformPositionalAccuracy;
111  params.objectEntityId = in.parameters.objectEntityId;
112 
113  SkillProxy prx(manager, providerName, ExecutePutdownSkill::Description.skillName);
114 
115  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
117  {
118  return {TerminatedSkillStatus::Failed, nullptr};
119  }
120  }
121 
122  // Open hand and detach from memory
123  {
124  skills::grasp_object::arondto::OpenHandAndDetachAcceptedType params;
125  params.kinematicChainName = kinematicChainName;
126  params.objectEntityId = in.parameters.objectEntityId;
127  params.robotName = in.parameters.robotName;
128 
129  SkillProxy prx(
130  {manager, providerName, skills::OpenHandAndDetachSkill::Description.skillName});
131 
132  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
134  {
135  return {TerminatedSkillStatus::Failed, nullptr};
136  }
137  }
138 
139  // Move TCP a bit up
140  {
141  ARMARX_CHECK(robotReader.synchronizeRobot(*robot, armem::Time::Now()));
142 
144  tcpOffset(0, 3) = 90;
145  tcpOffset(1, 3) = 10;
146 
147  Eigen::Matrix4f tcpTargetPoseGlobal =
148  robot->getRobotNodeSet(kinematicChainName)->getTCP()->getGlobalPose() * tcpOffset;
149 
150  skills::tcp_control::arondto::MoveTCPToTargetPoseAcceptedType params;
151  params.robotName = in.parameters.robotName;
152  params.kinematicChainName = kinematicChainName;
153  params.targetPoseGlobal = tcpTargetPoseGlobal;
154  params.orientationalAccuracy = in.parameters.tcpOrientationalAccuracy;
155  params.positionalAccuracy = in.parameters.tcpPositionalAccuracy;
156 
157  SkillProxy prx({manager,
160 
161  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
163  {
164  return {TerminatedSkillStatus::Failed, nullptr};
165  }
166  }
167 
168  // Move joints to zero position
169  {
170  skills::joint_control::arondto::MoveJointsToPositionAcceptedType params;
171  params.robotName = in.parameters.robotName;
172  params.jointTargetTolerance = 0.03;
173  params.jointMaxSpeed = 0.75;
174  params.accelerationTime = 500;
175  params.setVelocitiesToZeroAtEnd = true;
176 
177  for (const auto& j : robot->getRobotNodeSet(kinematicChainName)->getAllRobotNodes())
178  {
179  params.targetJointMap[j->getName()] = 0.0;
180  }
181 
182  SkillProxy prx({manager,
185 
186  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
188  {
189  return {TerminatedSkillStatus::Failed, nullptr};
190  }
191  }
192 
193  // Move platform back
194  {
195  skills::grasp_object::arondto::MovePlatformAfterPutdownAcceptedType params;
196  params.robotName = in.parameters.robotName;
197  params.orientationalAccuracy = in.parameters.platformOrientationalAccuracy;
198  params.positionalAccuracy = in.parameters.platformPositionalAccuracy;
199 
200  SkillProxy prx(
201  manager, providerName, MovePlatformAfterPutdownSkill::Description.skillName);
202 
203  if (prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron())
205  {
206  return {TerminatedSkillStatus::Failed, nullptr};
207  }
208  }
209 
210  clearLayer();
211  return {TerminatedSkillStatus::Succeeded, nullptr};
212  }
213 } // namespace armarx::skills
armarx::skills::mixin::MNSSkillMixin::mns
armem::client::MemoryNameSystem mns
Definition: MNSSkillMixin.h:11
armarx::skills::PutdownObjectSkill::Description
static SkillDescription Description
Definition: PutdownObject.h:38
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::MovePlatformForPutdownSkill::Description
static SkillDescription Description
Definition: MovePlatformForPutdown.h:27
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::skills::OpenHandAndDetachSkill::Description
static SkillDescription Description
Definition: OpenHandAndDetach.h:28
armarx::armem::obj::instance::Reader
Definition: ObjectReader.h:40
armarx::skills::ExecutePutdownSkill::Description
static SkillDescription Description
Definition: ExecutePutdown.h:27
armarx::skills::PutdownObjectSkill::PutdownObjectSkill
PutdownObjectSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, TwoArmGraspControlSkillContext &)
Definition: PutdownObject.cpp:34
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::skills::PutdownObjectSkill::ArgType
grasp_object::arondto::PutdownObjectAcceptedType ArgType
Definition: PutdownObject.h:30
armarx::skills::MovePlatformAfterPutdownSkill::Description
static SkillDescription Description
Definition: MovePlatformAfterPutdown.h:27
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::skills::TwoArmGraspControlSkillContext::jointControlSkillProvider
std::string jointControlSkillProvider
Definition: GraspControlSkill.h:50
FramedPose.h
armarx::armem::grasping::known_grasps::Reader
Definition: KnownGraspCandidateReader.h:35
armarx::armem::obj::instance::Writer
Definition: ObjectWriter.h:36
armarx::skills::SimpleSpecializedSkill
Definition: SimpleSpecializedSkill.h:10
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
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::PutdownObjectAcceptedType >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::skills::mixin::ArvizSkillMixin::clearLayer
void clearLayer()
Definition: ArvizSkillMixin.h:20
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
PutdownObject.h
armarx::viz::Client
Definition: Client.h:109
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