OpenHandAndDetach.cpp
Go to the documentation of this file.
1#include "OpenHandAndDetach.h"
2
3#include <VirtualRobot/RobotNodeSet.h>
4
5#include <RobotAPI/libraries/skills/provider/SkillProxy.h>
6
8
9namespace armarx::skills
10{
12 "OpenHandAndDetach",
13 "Open the hand and detach an object from it",
14 {},
16 grasp_object::arondto::OpenHandAndDetachAcceptedType::ToAronType()};
17
25
27 OpenHandAndDetachSkill::main(const SpecializedMainInput& in)
28 {
30 armem::obj::instance::Writer objectWriter(mns);
31 armem::obj::instance::Reader objectReader(mns);
32
33 robotReader.connect();
34 objectWriter.connect();
35 objectReader.connect();
36
37 // //////////////////////////////
38 // get robot
39 // //////////////////////////////
40 auto robot =
41 robotReader.getSynchronizedRobot(in.parameters.robotName,
43 VirtualRobot::RobotIO::RobotDescription::eStructure);
44 if (!robot)
45 {
46 ARMARX_ERROR << "Lost robot.";
47 return {TerminatedSkillStatus::Failed, nullptr};
48 }
49
50 // //////////////////////////////
51 // get object pose
52 // //////////////////////////////
53 auto objInstance = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
54 if (!objInstance)
55 {
56 ARMARX_ERROR << "Lost object pose.";
57 return {TerminatedSkillStatus::Failed, nullptr};
58 }
59
60 // Open hand
61 skills::hand_control::arondto::OpenHandAcceptedType params;
62 params.kinematicChainName = in.parameters.kinematicChainName;
63
64 SkillProxy prx(
65 {manager, context.handControlSkillProvider, OpenHand::Description.skillName});
66 auto su = prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron());
67
68 ARMARX_CHECK(robotReader.synchronizeRobot(*robot, armem::Time::Now()));
69 objInstance = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
70 if (!objInstance)
71 {
72 ARMARX_ERROR << "Lost object pose.";
73 return {TerminatedSkillStatus::Failed, nullptr};
74 }
75
76 auto objPoseInRootFrame = objInstance->objectPoseRobot;
77 auto robotPoseGlobal = robot->getRootNode()->getGlobalPose();
78
79 auto newObjPoseGlobal = robotPoseGlobal * objPoseInRootFrame;
80
81 //auto objPoseInTCPFrame = robot->getRobotNodeSet(in.kinematicChainName)->getTCP()->toLocalCoordinateSystem(objPoseInGlobalFrame);
82
83 armem::arondto::ObjectInstance arondto;
84
85 // TODO
86 // objInstance->attachmentValid = false;
87 // objInstance->attachment.agentName = "";
88 // objInstance->attachment.frameName = "";
89 // objInstance->objectPoseGlobal = newObjPoseGlobal;
90 // objInstance->objectPoseRobot = objPoseInRootFrame;
91 // objInstance->robotPose = robot->getRootNode()->getGlobalPose();
92 // objInstance->robotConfig = robot->getJointValues();
93
94 objectWriter.commitObject(arondto, objInstance->providerName, armem::Time::Now());
95
96 return {su.status, nullptr};
97 }
98} // 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.
static DateTime Now()
Definition DateTime.cpp:51
grasp_object::arondto::OpenHandAndDetachAcceptedType ArgType
OpenHandAndDetachSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, TwoArmGraspControlSkillContext &)
static SkillDescription Description
Definition OpenHand.h:46
manager::dti::SkillManagerInterfacePrx manager
Definition Skill.h:363
virtual MainResult main()
Override this method with the actual implementation.
Definition Skill.cpp:542
SkillID getSkillId() const
Get the id of the skill.
Definition Skill.cpp:587
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.
const char * toString(InteractionFeedbackType type)
Definition Interaction.h:28
A result struct for th main method of a skill.
Definition Skill.h:62
armem::client::MemoryNameSystem mns