SimpleHandoverObject.cpp
Go to the documentation of this file.
2
3#include <VirtualRobot/Grasping/GraspSet.h>
4#include <VirtualRobot/ManipulationObject.h>
5#include <VirtualRobot/RobotNodeSet.h>
6
8
9namespace armarx::skills
10{
12 SkillDescription{"SimpleHandoverObject",
13 "Handover an object already in hand of robot",
14 {},
16 grasp_object::arondto::PutdownObjectAcceptedType::ToAronType()};
17
18 /*SimpleHandoverObject::SimpleHandoverObject(armem::client::MemoryNameSystem& mns, armarx::viz::Client& arviz, GraspControlSkillContext& context) :
19 Base(GraspObjectDesc, mns, arviz, context),
20 movePlatformToPose(mns, arviz, context.platformControlSkillContext)
21 {
22 }
23
24 void SimpleHandoverObject::reset()
25 {
26 Base::reset();
27 movePlatformToPose.reset();
28 }
29
30 void SimpleHandoverObject::notifyStopped()
31 {
32 Base::notifyStopped();
33 movePlatformToPose.notifyStopped();
34 }
35
36 void SimpleHandoverObject::notifyTimeoutReached()
37 {
38 Base::notifyTimeoutReached();
39 movePlatformToPose.notifyTimeoutReached();
40 }
41
42 Skill::Status SimpleHandoverObject::execute(const grasp_object::arondto::PutdownObjectAcceptedType& in, const CallbackT& callback)
43 {
44 // Members
45 armem::robot_state::VirtualRobotReader robotReader(mns);
46 armem::obj::instance::Reader objectReader(mns);
47 armem::grasping::known_grasps::Reader graspReader(mns);
48 armem::obj::instance::Writer objectWriter(mns);
49
50 robotReader.connect();
51 objectReader.connect();
52 graspReader.connect();
53
54 objectWriter.connect();
55
56 // //////////////////////////////
57 // check args
58 // //////////////////////////////
59 auto split = simox::alg::split(in.objectEntityId, "/");
60 auto objectId = in.objectEntityId;
61 if (split.size() > 3)
62 {
63 ARMARX_ERROR << "Unknown structure of object entitiy id!";
64 return Skill::Status::Failed;
65 }
66 else if (split.size() == 3)
67 {
68 objectId = split[0] + "/" + split[1];
69 }
70
71 if (in.kinematicChainName.empty())
72 {
73 ARMARX_ERROR << "No kinematic chain candidate set";
74 return Skill::Status::Failed;
75 }
76
77 auto now = armem::Time::now();
78 // //////////////////////////////
79 // get robot
80 // //////////////////////////////
81 auto robot = robotReader.getSynchronizedRobot(in.robot, now, VirtualRobot::RobotIO::RobotDescription::eStructure);
82
83 auto kinematicChain = robot->getRobotNodeSet(in.kinematicChainName);
84 const auto tcpName = kinematicChain->getTCP()->getName();
85 const auto kinematicChainJointNames = kinematicChain->getNodeNames();
86
87
88 // //////////////////////////////
89 // get object pose
90 // //////////////////////////////
91 auto objInstanceOpt = objectReader.queryObjectByEntityID(in.objectEntityId, now);
92 if (!objInstanceOpt)
93 {
94 ARMARX_ERROR << "Lost object pose.";
95 return Skill::Status::Failed;
96 }
97 auto objInstance = *objInstanceOpt;
98
99 // //////////////////////////////
100 // Setup vars
101 // //////////////////////////////
102 auto skillRet = Skill::Status::Succeeded;
103
104 auto handRootNodeName = "Hand L Base";
105 if (simox::alg::starts_with(in.kinematicChainName, "Right"))
106 {
107 handRootNodeName = "Hand R Base";
108 }
109 const FramedPosePtr handRoot = new FramedPose(robot->getRobotNode(handRootNodeName)->getPoseInRootFrame(), robot->getRootNode()->getName(), robot->getName());
110 const FramedPosePtr tcp = new FramedPose(robot->getRobotNode(tcpName)->getPoseInRootFrame(), robot->getRootNode()->getName(), robot->getName());
111 const Eigen::Matrix4f handRootPoseGlobal = handRoot->toGlobalEigen(robot);
112 const Eigen::Matrix4f tcpPoseGlobal = tcp->toGlobalEigen(robot);
113
114 const Eigen::Matrix4f tcp2handRoot = tcpPoseGlobal.inverse() * handRootPoseGlobal;
115
116
117 // //////////////////////////////
118 // Move arm back
119 // //////////////////////////////
120 {
121 auto otherArmKinematicChain = robot->getRobotNodeSet(in.otherArmKinematicChainName);
122 auto otherArmJointNames = otherArmKinematicChain->getNodeNames();
123
124 ARMARX_CHECK_EQUAL(otherArmJointNames.size(), 7); // TODO
125
126 joint_control::arondto::MoveJointsToPositionAcceptedType nextArgs;
127 nextArgs.accelerationTime = 500;
128 nextArgs.jointMaxSpeed = 0.75;
129 nextArgs.jointTargetTolerance = 0.03;
130 nextArgs.setVelocitiesToZeroAtEnd = true;
131 nextArgs.targetJointMap[otherArmJointNames[0]] = 0.47;
132 nextArgs.targetJointMap[otherArmJointNames[1]] = 0.0;
133 nextArgs.targetJointMap[otherArmJointNames[2]] = 0.0;
134 nextArgs.targetJointMap[otherArmJointNames[3]] = 0.32;
135 nextArgs.targetJointMap[otherArmJointNames[4]] = 0.47;
136 skillRet = moveJointsToPosition._execute(nextArgs, callback);
137 }
138
139 if (skillRet != Skill::Status::Succeeded)
140 {
141 clearLayer();
142 return skillRet;
143 }
144
145 // //////////////////////////////
146 // Move platform relative
147 // //////////////////////////////
148 {
149 // not used here
150 }
151
152 if (skillRet != Skill::Status::Succeeded)
153 {
154 clearLayer();
155 return skillRet;
156 }
157
158
159 // //////////////////////////////
160 // Move TCP to handover pose
161 // //////////////////////////////
162 {
163 now = IceUtil::Time::now();
164 robotReader.synchronizeRobot(*robot, now);
165
166 FramedPose tcp(robot->getRobotNode(tcpName)->getPoseInRootFrame(), robot->getRootNode()->getName(), robot->getName());
167 //const Eigen::Matrix4f robotRoot = robotRootFramedPose.toEigen();
168 //const Eigen::Matrix4f robotRootPoseGlobalEigen = robotRootFramedPose.toGlobalEigen(robot);
169
170 // query obj target location from grasp
171 auto objPoseRobot = objInstance.pose.objectPoseRobot;
172 objPoseRobot(1,3) += 40; // move further away
173 FramedPose targetObjectFramedPoseRoot(objPoseRobot, robot->getRootNode()->getName(), robot->getName());
174 const auto targetObjectPoseGlobalEigen = targetObjectFramedPoseRoot.toGlobalEigen(robot);
175
176 const auto transformationFromTCPToObject = objInstance.pose.attachment.poseInFrame;
177
178 const auto placePoseGlobal = Eigen::Matrix4f(targetObjectPoseGlobalEigen * transformationFromTCPToObject.inverse());
179
180 Eigen::Matrix4f handRootTargetPoseGlobal = placePoseGlobal * tcp2handRoot;
181 handRootTargetPoseGlobal(2,3) += 20;
182
183 auto l = arviz.layer(layerName);
184 auto o = armarx::viz::Robot("grasp");
185 o.file("RobotAPI", "RobotAPI/robots/Armar3/ArmarIII-LeftHand.xml"); // TODO!
186 o.pose(handRootTargetPoseGlobal);
187 l.add(o);
188 arviz.commit(l);
189
190 {
191 tcp_control::arondto::MoveTCPToTargetPoseAcceptedType nextArgs;
192 nextArgs.kinematicChainName = in.kinematicChainName;
193 nextArgs.orientationalAccuracy = in.orientationalAccuracy;
194 nextArgs.positionalAccuracy = in.positionalAccuracy;
195 nextArgs.targetPoseGlobal = handRootTargetPoseGlobal;
196 skillRet = moveTcpToTargetSkill.execute(nextArgs, callback);
197 }
198
199 clearLayer();
200 }
201
202
203 if (skillRet != Skill::Status::Succeeded)
204 {
205 clearLayer();
206 return skillRet;
207 }
208
209
210 // //////////////////////////////
211 // Open hand and detach from memory
212 // //////////////////////////////
213 {
214 now = IceUtil::Time::now();
215 robotReader.synchronizeRobot(*robot, now);
216
217 FramedPose robotRootFramedPose(robot->getRootNode()->getPoseInRootFrame(), robot->getRootNode()->getName(), robot->getName());
218 //const Eigen::Matrix4f robotRoot = robotRootFramedPose.toEigen();
219 const Eigen::Matrix4f robotRootGlobal = robotRootFramedPose.toGlobalEigen(robot);
220
221 FramedPose objInRobotRootFramedPose(objInstance.pose.objectPoseRobot, robot->getRootNode()->getName(), robot->getName());
222 const auto objPoseGlobalEigen = objInRobotRootFramedPose.toGlobalEigen(robot);
223 const auto objPoseRootEigen = objInRobotRootFramedPose.toEigen();
224
225 //objInstanceUpdate.pose.providerName = description.skillName;
226 objInstance.pose.attachmentValid = false;
227 objInstance.pose.attachment.resetHard();
228 objInstance.pose.objectPoseGlobal = objPoseGlobalEigen;
229 objInstance.pose.objectPoseRobot = objPoseRootEigen;
230 objInstance.pose.robotPose = robotRootGlobal;
231 objInstance.pose.robotConfig = robot->getJointValues();
232
233 objectWriter.commitObject(objInstance, objInstance.pose.providerName, IceUtil::Time::now());
234
235 skillRet = openHand.execute(nullptr, callback);
236 }
237
238 if (skillRet != Skill::Status::Succeeded)
239 {
240 clearLayer();
241 return skillRet;
242 }
243
244
245 // //////////////////////////////
246 // Move TCP to retreat pose
247 // //////////////////////////////
248 {
249 const float xRetreatOffset = 90;
250 const float yRetreatOffset = 10;
251
252 Eigen::Matrix4f offset = Eigen::Matrix4f::Identity();
253 offset(0,3) = xRetreatOffset;
254 offset(1,3) = yRetreatOffset;
255
256 now = IceUtil::Time::now();
257 robotReader.synchronizeRobot(*robot, now);
258
259 auto TcpPoseGlobalEigen = robot->getRobotNode(tcpName)->getGlobalPose();
260 Eigen::Matrix4f newTCPPoseGlobalEigen = TcpPoseGlobalEigen * offset;
261
262 tcp_control::arondto::MoveTCPToTargetPoseAcceptedType nextArgs;
263 nextArgs.kinematicChainName = in.kinematicChainName;
264 nextArgs.orientationalAccuracy = in.orientationalAccuracy;
265 nextArgs.positionalAccuracy = in.positionalAccuracy;
266 nextArgs.targetPoseGlobal = newTCPPoseGlobalEigen;
267 skillRet = moveTcpToTargetSkill.execute(nextArgs, callback);
268 }
269
270 if (skillRet != Skill::Status::Succeeded)
271 {
272 clearLayer();
273 return skillRet;
274 }
275
276 // //////////////////////////////
277 // Move joints to zero position
278 // //////////////////////////////
279 {
280 joint_control::arondto::MoveJointsToPositionAcceptedType nextArgs;
281 nextArgs.accelerationTime = 500;
282 nextArgs.jointMaxSpeed = 0.75;
283 nextArgs.jointTargetTolerance = 0.03;
284 nextArgs.setVelocitiesToZeroAtEnd = true;
285 for (const auto& j : kinematicChainJointNames)
286 {
287 nextArgs.targetJointMap[j] = 0.0;
288 }
289 for (const auto& j : robot->getRobotNodeSet(in.otherArmKinematicChainName)->getNodeNames())
290 {
291 nextArgs.targetJointMap[j] = 0.0;
292 }
293 skillRet = moveJointsToPosition._execute(nextArgs, callback);
294 }
295
296 clearLayer();
297 return skillRet;
298 }*/
299} // namespace armarx::skills
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
This file is part of ArmarX.
const SkillDescription GraspObjectSkillDesc