CloseHandAndAttach.cpp
Go to the documentation of this file.
1 #include "CloseHandAndAttach.h"
2 
3 #include <VirtualRobot/RobotNodeSet.h>
4 
5 #include <RobotAPI/libraries/skills/provider/SkillProxy.h>
6 
8 
9 namespace armarx::skills
10 {
11  SkillDescription CloseHandAndAttachSkill::Description = skills::SkillDescription{
12  "CloseHandAndAttach",
13  "Close the hand and attach an object to it",
14  {},
16  grasp_object::arondto::CloseHandAndAttachAcceptedType::ToAronType()};
17 
19  armarx::viz::Client& arviz,
21  TwoArmGraspControlSkill(mns, arviz, Description.skillName, context),
22  SimpleSpecializedSkill<ArgType>(Description)
23  {
24  }
25 
27  CloseHandAndAttachSkill::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  objectReader.requestLocalization(in.parameters.objectEntityId,
55  std::this_thread::sleep_for(std::chrono::milliseconds(500));
56 
57  auto objInstance = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
58  if (!objInstance)
59  {
60  ARMARX_ERROR << "Lost object pose.";
61  return {TerminatedSkillStatus::Failed, nullptr};
62  }
63 
64  // Close hand
65  skills::hand_control::arondto::CloseHandAcceptedType params;
66  params.kinematicChainName = in.parameters.kinematicChainName;
67 
68  SkillProxy prx({manager, "HandControlSkillProvider", CloseHand::Description.skillName});
69  auto su = prx.executeFullSkill(getSkillId().toString(in.executorName), params.toAron());
70 
71  ARMARX_CHECK(robotReader.synchronizeRobot(*robot, armem::Time::Now()));
72  objInstance = objectReader.queryLatestObjectInstance(in.parameters.objectEntityId);
73 
74  auto objPoseInGlobalFrame = objInstance->objectPoseGlobal;
75  auto objPoseInRootFrame =
76  robot->getRootNode()->toLocalCoordinateSystem(objPoseInGlobalFrame);
77  auto objPoseInTCPFrame = robot->getRobotNodeSet(in.parameters.kinematicChainName)
78  ->getTCP()
79  ->toLocalCoordinateSystem(objPoseInGlobalFrame);
80 
81  armem::arondto::ObjectInstance arondto;
82  armarx::armem::toAron(arondto, *objInstance);
83 
84  // TODO refactor writer to accept non-dto objects
85  arondto.pose.attachmentValid = true;
86  arondto.pose.attachment.agentName = robot->getName();
87  arondto.pose.attachment.frameName = robot->getRobotNodeSet(in.parameters.kinematicChainName)->getTCP()->getName();
88  arondto.pose.attachment.poseInFrame = objPoseInTCPFrame;
89  arondto.pose.objectPoseRobot = objPoseInRootFrame;
90  arondto.pose.robotPose = objPoseInGlobalFrame;
91  arondto.pose.robotConfig = robot->getJointValues();
92 
93  objectWriter.commitObject(arondto, objInstance->providerName, armem::Time::Now());
94 
95  return {su.status, nullptr};
96  }
97 } // namespace armarx::skills
armarx::skills::mixin::MNSSkillMixin::mns
armem::client::MemoryNameSystem mns
Definition: MNSSkillMixin.h:11
armarx::skills::CloseHand::Description
static SkillDescription Description
Definition: CloseHand.h:46
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::skills::CloseHandAndAttachSkill::ArgType
grasp_object::arondto::CloseHandAndAttachAcceptedType ArgType
Definition: CloseHandAndAttach.h:20
armarx::skills::CloseHandAndAttachSkill::Description
static SkillDescription Description
Definition: CloseHandAndAttach.h:28
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::CloseHandAndAttachSkill::CloseHandAndAttachSkill
CloseHandAndAttachSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, TwoArmGraspControlSkillContext &)
Definition: CloseHandAndAttach.cpp:18
armarx::armem::toAron
void toAron(arondto::MemoryID &dto, const MemoryID &bo)
Definition: aron_conversions.cpp:19
armarx::armem::obj::instance::Reader
Definition: ObjectReader.h:40
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::armem::obj::instance::Writer
Definition: ObjectWriter.h:36
armarx::skills::SimpleSpecializedSkill
Definition: SimpleSpecializedSkill.h:10
CloseHandAndAttach.h
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::TerminatedSkillStatus::Failed
@ Failed
armarx::skills::SimpleSpecializedSkill< grasp_object::arondto::CloseHandAndAttachAcceptedType >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
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
aron_conversions.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