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 
9 namespace armarx::skills
10 {
11  SkillDescription OpenHandAndDetachSkill::Description = skills::SkillDescription{
12  "OpenHandAndDetach",
13  "Open the hand and detach an object from it",
14  {},
16  grasp_object::arondto::OpenHandAndDetachAcceptedType::ToAronType()};
17 
19  armarx::viz::Client& arviz,
21  TwoArmGraspControlSkill(mns, arviz, Description.skillName, context),
22  SimpleSpecializedSkill<ArgType>(Description)
23  {
24  }
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(
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
armarx::skills::mixin::MNSSkillMixin::mns
armem::client::MemoryNameSystem mns
Definition: MNSSkillMixin.h:11
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
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::skills::OpenHandAndDetachSkill::ArgType
grasp_object::arondto::OpenHandAndDetachAcceptedType ArgType
Definition: OpenHandAndDetach.h:20
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::skills::OpenHand::Description
static SkillDescription Description
Definition: OpenHand.h:46
OpenHand.h
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
OpenHandAndDetach.h
armarx::skills::TerminatedSkillStatus::Failed
@ Failed
armarx::skills::SimpleSpecializedSkill< grasp_object::arondto::OpenHandAndDetachAcceptedType >::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::handControlSkillProvider
std::string handControlSkillProvider
Definition: GraspControlSkill.h:48
armarx::skills::TwoArmGraspControlSkillContext
Definition: GraspControlSkill.h:46
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::skills::OpenHandAndDetachSkill::OpenHandAndDetachSkill
OpenHandAndDetachSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, TwoArmGraspControlSkillContext &)
Definition: OpenHandAndDetach.cpp:18
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