ExecutePutdown.cpp
Go to the documentation of this file.
1#include <SimoxUtility/algorithm/string/string_tools.h>
2#include "ExecutePutdown.h"
3
4#include <VirtualRobot/RobotNodeSet.h>
5
8
11
13
14namespace armarx::skills
15{
16 namespace
17 {
18 grasp_object::arondto::ExecutePutdownAcceptedType
19 GetDefaultParameterization()
20 {
21 grasp_object::arondto::ExecutePutdownAcceptedType ret;
22 ret.orientationalAccuracy = 0.01;
23 ret.positionalAccuracy = 25;
24 return ret;
25 }
26 } // namespace
27
28 SkillDescription ExecutePutdownSkill::Description = skills::SkillDescription{
29 .skillId = {.skillName = "ExecutePutdown"},
30 .description = "Execute a putdown for some grasped object",
31 .rootProfileDefaults = GetDefaultParameterization().toAron(),
32 .timeout = armarx::Duration::MilliSeconds(120000),
33 .parametersType = grasp_object::arondto::ExecutePutdownAcceptedType::ToAronType(),
34 };
35
43
45 ExecutePutdownSkill::main(const SpecializedMainInput& in)
46 {
50
51 robotReader.connect(mns);
52 objectReader.connect(mns);
53 graspReader.connect(mns);
54
55 // //////////////////////////////
56 // get robot
57 // //////////////////////////////
58 auto robot =
59 robotReader.getSynchronizedRobot(in.parameters.robotName,
61 VirtualRobot::RobotIO::RobotDescription::eStructure);
62 if (!robot)
63 {
64 ARMARX_ERROR << "Lost robot.";
65 return {TerminatedSkillStatus::Failed, nullptr};
66 }
67
68 // //////////////////////////////
69 // get object pose
70 // //////////////////////////////
71 auto objInstance = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
72 if (!objInstance)
73 {
74 ARMARX_ERROR << "Lost object pose.";
75 return {TerminatedSkillStatus::Failed, nullptr};
76 }
77
78
79 ARMARX_CHECK(objInstance->attachment->agentName == in.parameters.robotName);
80
81 std::string kinematicChainName = "LeftArm";
82 std::string otherArmKinematicChainName = "RightArm";
83 if (simox::alg::ends_with(objInstance->attachment->frameName, " R"))
84 {
85 kinematicChainName = "RightArm";
86 otherArmKinematicChainName = "LeftArm";
87 }
88
89 // //////////////////////////////
90 // Move TCPs
91 // //////////////////////////////
92 {
93 skills::joint_control::arondto::MoveJointsToPositionAcceptedType params;
94 params.robotName = in.parameters.robotName;
95 params.jointTargetTolerance = 0.03;
96 params.jointMaxSpeed = 0.75;
97 params.accelerationTime = 500;
98 params.setVelocitiesToZeroAtEnd = true;
99
100 params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
101 ->getNodeNames()[0]] = 0.47;
102 params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
103 ->getNodeNames()[1]] = 0.0;
104 params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
105 ->getNodeNames()[2]] = 0.0;
106 params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
107 ->getNodeNames()[3]] = 0.32;
108 params.targetJointMap[robot->getRobotNodeSet(otherArmKinematicChainName)
109 ->getNodeNames()[4]] = 0.47;
110
111 SkillProxy prx(manager, SkillID{
112 .providerId = ProviderID{.providerName = context.jointControlSkillProvider},
114
115 if (prx.executeSkill(in.executorName, params.toAron())
117 {
118 return {TerminatedSkillStatus::Failed, nullptr};
119 }
120 }
121
122 // Look at hand
123 {
124 skills::joint_control::arondto::MoveJointsToPositionAcceptedType params;
125 params.robotName = in.parameters.robotName;
126 params.jointTargetTolerance = 0.03; // Todo
127 params.jointMaxSpeed = 0.75;
128 params.accelerationTime = 500;
129 params.setVelocitiesToZeroAtEnd = true;
130 params.targetJointMap["Neck_1_Pitch"] = 0.6;
131
132 SkillProxy prx(manager, SkillID{
133 .providerId = ProviderID{.providerName = context.jointControlSkillProvider},
135
136 if (prx.executeSkill(in.executorName, params.toAron())
138 {
139 return {TerminatedSkillStatus::Failed, nullptr};
140 }
141 }
142
143 ARMARX_CHECK(robotReader.synchronizeRobot(*robot, armem::Time::Now()));
144
145 const auto objPoseLocal = objInstance->objectPoseRobot;
146 const auto objPoseGlobal = robot->getRootNode()->toGlobalCoordinateSystem(objPoseLocal);
147 const auto objectInTCPFrame = objInstance->attachment->poseInFrame;
148 Eigen::Matrix4f tcpPlacePoseGlobal = objPoseGlobal * objectInTCPFrame.inverse();
149 tcpPlacePoseGlobal(2, 3) += 50;
150
151 auto tcpPlacePrePoseGlobal = tcpPlacePoseGlobal;
152 tcpPlacePrePoseGlobal(2, 3) += 80;
153
154 std::vector<Eigen::Matrix4f> targetPosesGlobal = {tcpPlacePrePoseGlobal,
155 tcpPlacePoseGlobal};
156
157 for (const auto& tcpTargetPoseGlobal : targetPosesGlobal)
158 {
159 skills::tcp_control::arondto::MoveTCPToTargetPoseAcceptedType params;
160 params.robotName = in.parameters.robotName;
161 params.kinematicChainName = kinematicChainName;
162 params.targetPoseGlobal = tcpTargetPoseGlobal;
163 params.orientationalAccuracy = in.parameters.orientationalAccuracy;
164 params.positionalAccuracy = in.parameters.positionalAccuracy;
165
166 SkillProxy prx(manager, SkillID{
167 .providerId = ProviderID{.providerName = context.tcpControlSkillProvider},
169
170 if (prx.executeSkill(in.executorName, params.toAron())
172 {
173 return {TerminatedSkillStatus::Failed, nullptr};
174 }
175 }
176
177 // Look up
178 {
179 skills::joint_control::arondto::MoveJointsToPositionAcceptedType params;
180 params.robotName = in.parameters.robotName;
181 params.jointTargetTolerance = 0.03; // Todo
182 params.jointMaxSpeed = 0.75;
183 params.accelerationTime = 500;
184 params.setVelocitiesToZeroAtEnd = true;
185 params.targetJointMap["Neck_1_Pitch"] = 0.0;
186
187 SkillProxy prx(manager, SkillID{
188 .providerId = ProviderID{.providerName = context.jointControlSkillProvider},
190
191 if (prx.executeSkill(in.executorName, params.toAron())
193 {
194 return {TerminatedSkillStatus::Failed, nullptr};
195 }
196 }
197
198 return {TerminatedSkillStatus::Succeeded, nullptr};
199 }
200} // namespace armarx::skills
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
The memory name system (MNS) client.
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
std::optional< objpose::ObjectPose > queryLatestObjectInstance(const ObjectID &instanceId)
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
VirtualRobot::RobotPtr getSynchronizedRobot(const std::string &name, const VirtualRobot::RobotIO::RobotDescription &loadMode=VirtualRobot::RobotIO::RobotDescription::eStructure, bool blocking=true)
bool synchronizeRobot(VirtualRobot::Robot &robot, const armem::Time &timestamp) const
Synchronize both the platform pose and the joint values of a virtual robot, according to the robot st...
static DateTime Now()
Definition DateTime.cpp:51
ExecutePutdownSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, TwoArmGraspControlSkillContext &)
static SkillDescription Description
grasp_object::arondto::ExecutePutdownAcceptedType ArgType
std::string skillName
Definition SkillID.h:41
manager::dti::SkillManagerInterfacePrx manager
Definition Skill.h:363
virtual MainResult main()
Override this method with the actual implementation.
Definition Skill.cpp:542
TwoArmGraspControlSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, const std::string &layerName, TwoArmGraspControlSkillContext &c)
TwoArmGraspControlSkillContext & context
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file is part of ArmarX.
A result struct for th main method of a skill.
Definition Skill.h:62
armem::client::MemoryNameSystem & mns