LookAtArticulatedObjectFrame.cpp
Go to the documentation of this file.
2
3#include <Eigen/Core>
4
5#include <VirtualRobot/XML/RobotIO.h>
6
10
17
18#include <armarx/view_selection/skills/aron/LookAt.aron.generated.h>
21
23{
28
30 LookAtArticulatedObjectFrame::init(const Base::SpecializedInitInput& in)
31 {
32 return ::armarx::skills::Skill::InitResult{
34 }
35
37 LookAtArticulatedObjectFrame::main(const Base::SpecializedMainInput& in)
38 {
39 ARMARX_INFO << "Querying descriptions";
40 const auto descriptions = srv_.articulatedObjectReader->queryDescriptions(
41 Clock::Now(), in.parameters.objectPoseProvider);
42
43 ARMARX_INFO << "Available descriptions are:";
44 for (const auto& description : descriptions)
45 {
47 }
48
49 ObjectID objectID;
50 fromAron(in.parameters.object, objectID);
51
52 const std::string objectName = objectID.dataset() + "/" + objectID.className();
53 ARMARX_INFO << "Searching for object name `" << objectName << "`";
54
55 const auto isMatchingDescription = [&objectID](const auto& description) -> bool
56 { return objectID.equalClass(ObjectID(description.name)); };
57
58 const auto descriptionIt =
59 std::find_if(descriptions.begin(), descriptions.end(), isMatchingDescription);
60 ARMARX_CHECK(descriptionIt != descriptions.end())
61 << "Description " << objectID << " not available";
62
63 ARMARX_INFO << "getting object";
64 std::optional<armarx::armem::articulated_object::ArticulatedObject> objectOpt =
65 srv_.articulatedObjectReader->get(*descriptionIt,
66 Clock::Now(),
67 objectID.instanceName(),
68 in.parameters.objectPoseProvider);
69 ARMARX_CHECK(objectOpt);
70
71 // load object
72
73 armarx::armem::articulated_object::ArticulatedObject articulatedObject = *objectOpt;
74
75 const std::string xmlFilename = articulatedObject.description.xml.toSystemPath();
76 ARMARX_INFO << "Loading (virtual) robot '" << articulatedObject.description.name
77 << "' from XML file '" << xmlFilename << "'";
78
79 auto object = VirtualRobot::RobotIO::loadRobot(
80 xmlFilename, VirtualRobot::RobotIO::RobotDescription::eStructure);
82
83 object->setJointValues(articulatedObject.config.jointMap);
84 object->setGlobalPose(articulatedObject.config.globalPose.matrix());
85 object->setName(objectID.str()); // this is optional, name not used directly
86
87 // obtain global pose of frame
88
89 const auto node = object->getRobotNode(in.parameters.node);
90 ARMARX_CHECK_NOT_NULL(node) << ("`" + in.parameters.node + "` node does not exist");
91
92 const Eigen::Vector3f globalPose = node->getGlobalPosition();
93
94 // generate view target
95 const armarx::view_selection::gaze_targets::arondto::GazeTarget gazeTarget = [&]()
96 {
97 armarx::view_selection::gaze_targets::arondto::GazeTarget gazeTarget;
98 gazeTarget.name =
99 "LookAtArticulatedObjectFrame_" + objectID.str() + ":" + in.parameters.node;
100
101 gazeTarget.position.header.agent = ""; // not needed
102 gazeTarget.position.header.frame = armarx::GlobalFrame; // not needed
103
104 gazeTarget.position.position = globalPose;
105
106 gazeTarget.duration =
107 armarx::core::time::Duration::SecondsDouble(in.parameters.durationSeconds);
108
109 gazeTarget.priority.attentionType =
110 gaze_targets::arondto::AttentionType::ImplEnum::TaskDriven;
111 gazeTarget.priority.priority = in.parameters.priority;
112
113 gazeTarget.creationTimestamp = Clock::Now();
114 gazeTarget.keepInQueue = false;
115
116 return gazeTarget;
117 }();
118
119 // execute subskill
120 {
121 using Parameters = armarx::view_selection::skills::arondto::LookAtParams;
122
123 ::armarx::skills::SkillID skillId{
124 .providerId =
125 ::armarx::skills::ProviderID{.providerName = armarx::view_selection::skills::
126 constants::ViewSelectionSkillProviderName},
128
129 auto update = callSubskill<Parameters>(skillId,
130 [&](Parameters& subSkillParams)
131 {
132 subSkillParams.target = gazeTarget;
133 });
134
136 {
137 return MakeFailedResult();
138 }
139 }
140
141 return MakeSucceededResult();
142 }
143
144 void
145 LookAtArticulatedObjectFrame::onStopRequested()
146 {
147 }
148
149 ::armarx::skills::SkillDescription
151 {
152 Params defaults;
153 defaults.priority = 100;
154 defaults.objectPoseProvider = std::nullopt; // "any"
155
158 .description = "",
159 .rootProfileDefaults = defaults.toAron(),
160 .timeout = armarx::Duration::Minutes(10),
161 .parametersType = Params::ToAronType(),
162 .resultType = Result::ToAronType(),
163 };
164 }
165
166} // namespace armarx::view_selection::skills
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
static Duration Minutes(std::int64_t minutes)
Constructs a duration in minutes.
Definition Duration.cpp:96
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
static Duration SecondsDouble(double seconds)
Constructs a duration in seconds.
Definition Duration.cpp:78
std::optional< TerminatedSkillStatusUpdate > callSubskill(const SkillID &skillId)
Call a subskill with the given ID and its default parameters.
Definition Skill.cpp:119
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:413
SkillDescription description
Definition Skill.h:372
static MainResult MakeFailedResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:422
::armarx::skills::SimpleSpecializedSkill< Params > Base
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
armarx::armem::robot_state::Robot ArticulatedObject
Definition types.h:140
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition mongodb.cpp:68
aron::data::DictPtr Parameters
bool skillExecutionFailed(const std::optional< armarx::skills::TerminatedSkillStatusUpdate > &update)
const armarx::skills::SkillID LookAtArticulatedObjectFrame
Definition skill_ids.cpp:40
This file is part of ArmarX.
Definition constants.cpp:26
void fromAron(const arondto::PackagePath &dto, PackageFileLocation &bo)
description::RobotDescription description
Definition types.h:128
A result struct for skill initialization.
Definition Skill.h:50
A result struct for th main method of a skill.
Definition Skill.h:62
std::experimental::observer_ptr<::armarx::armem::articulated_object::Reader > articulatedObjectReader