NavigateTo.cpp
Go to the documentation of this file.
1#include "NavigateTo.h"
2
3#include <chrono>
4#include <future>
5#include <string>
6
7#include <Eigen/Core>
8#include <Eigen/Geometry>
9
13
16
22
24{
25 template <typename R>
26 bool
27 is_ready(std::future<R> const& f)
28 {
29 if (!f.valid())
30 {
31 return true;
32 }
33 std::future_status status = f.wait_for(std::chrono::seconds(0));
34 if (status == std::future_status::ready)
35 {
36 return true;
37 }
38 else if (status == std::future_status::deferred)
39 {
40 // if the task has not been started --> start the task
41 f.wait();
42 return true;
43 }
44 else
45 {
46 return false;
47 }
48 }
49
52 Base(DefaultSkillDescription()), helper(properties, srv)
53 {
54 }
55
57 NavigateTo::init(const Base::SpecializedInitInput& in)
58 {
59 helper.init(in.parameters.navigatingSkillParams,
60 DefaultSkillDescription().skillId.skillName);
61
62 return ::armarx::skills::Skill::InitResult{
64 }
65
67 NavigateTo::main(const Base::SpecializedMainInput& in)
68 {
69 const Eigen::Isometry3f globalTarget(in.parameters.targetPose);
70
71 ARMARX_INFO << "moving to target " << VAROUT(globalTarget.matrix());
72
73 // execute
74 ARMARX_INFO << "Sending navigation request";
75 helper.getNavigator()->moveTo(globalTarget, core::NavigationFrame::Absolute);
76
77 // Wait until goal is reached
78 ARMARX_INFO << "Waiting until goal is reached.";
79
80 auto future = std::async(std::launch::async,
81 [this]() { return helper.getNavigator()->waitForStop(); });
82 while (not is_ready(future))
83 {
85 {
86 ARMARX_INFO << "Skill was aborted by user " << stopped << ", " << timeoutReached;
87 helper.getNavigator()->stop();
88 break;
89 }
90 }
91
92 auto se = future.get();
93 if (se)
94 {
95 ARMARX_INFO << "Goal `" << Eigen::Isometry3f(in.parameters.targetPose).translation()
96 << "`reached.";
97 }
98 else
99 {
100 if (se.isSafetyStopTriggeredEvent())
101 {
102 ARMARX_ERROR << "Safety stop was triggered!";
103
104 return ::armarx::skills::Skill::MainResult{
106 }
107 if (se.isUserAbortTriggeredEvent())
108 {
109 ARMARX_ERROR << "Aborted by user!";
110
111 return ::armarx::skills::Skill::MainResult{
113 }
114 if (se.isInternalErrorEvent())
115 {
116 ARMARX_ERROR << "Unknown internal error occured! "
117 << se.toInternalErrorEvent().message;
118
119 return ::armarx::skills::Skill::MainResult{
121 }
122 if (se.isGlobalPlanningFailedEvent())
123 {
124 ARMARX_ERROR << "Global planning failed! "
125 << se.toGlobalPlanningFailedEvent().message;
126
127 return ::armarx::skills::Skill::MainResult{
129 }
130
131 ARMARX_ERROR << "Unknown event!";
132 return ::armarx::skills::Skill::MainResult{
134 }
135
136
137 return ::armarx::skills::Skill::MainResult{
139 }
140
141 void
142 NavigateTo::onStopRequested()
143 {
144 if (helper.getNavigator().has_value())
145 {
146 ARMARX_CHECK(helper.getNavigator().has_value());
147 helper.getNavigator()->stop();
148 }
149 }
150
151 armarx::skills::SkillDescription
153 {
154 ParamType defaultParameters;
155 defaultParameters.navigatingSkillParams = NavigatingSkillHelper::DefaultSkillDescription();
156 // TODO(): set parameter defaults
157
159 .skillId = {.skillName = constants::skill_names::NavigateTo},
160 .description = "",
161 .rootProfileDefaults = defaultParameters.toAron(),
163 .parametersType = Params::ToAronType()};
164 }
165
166} // namespace armarx::navigation::skills
#define VAROUT(x)
static Duration Hours(std::int64_t hours)
Constructs a duration in hours.
Definition Duration.cpp:120
::armarx::skills::SimpleSpecializedSkill< Params > Base
Definition NavigateTo.h:41
static armarx::skills::SkillDescription DefaultSkillDescription()
NavigateTo(const NavigatingSkillHelper::Properties &properties, const NavigatingSkillHelper::Services &srv)
std::optional< client::Navigator > & getNavigator()
void init(const arondto::NavigatingSkillParams &params, const std::string &id)
static arondto::NavigatingSkillParams DefaultSkillDescription()
std::atomic_bool timeoutReached
Definition Skill.h:387
bool shouldSkillTerminate() const override
Returns whether the skill should terminate as soon as possible.
Definition Skill.cpp:469
std::atomic_bool stopped
Definition Skill.h:386
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
bool is_ready(std::future< R > const &f)
A result struct for skill initialization.
Definition Skill.h:50
A result struct for th main method of a skill.
Definition Skill.h:62