NavigateRelativeSkill.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <future>
5#include <optional>
6#include <string>
7
11
16
24
26{
27
28 // abstract base class of a relative movement skill
29 template <class AronT>
31 {
32
33 public:
35
37
41 Base(desc), helper(properties, srv)
42 {
43 }
44
45 virtual ~NavigateRelativeSkill() = default;
46
47 private:
48 // implemented by children returning the relative movement to execute
49 virtual Eigen::Isometry3f relativeTarget(const typename Base::SpecializedMainInput& in) = 0;
50
52 init(const typename Base::SpecializedInitInput& in) override
53 {
54 helper.init(in.parameters.navigatingSkillParams, Base::getSkillId().skillName);
55
56 return ::armarx::skills::Skill::InitResult{
58 }
59
61 main(const typename Base::SpecializedMainInput& in) override
62 {
63 const Eigen::Isometry3f relativeTarget = this->relativeTarget(in);
64
65 ARMARX_INFO << "Moving to relative target " << VAROUT(relativeTarget.matrix());
66
67 // excecute
68 ARMARX_INFO << "Sending navigation request";
69 // Wait until goal is reached, re-planning while the retry budget lasts. The
70 // relative target stays valid across retries: a planning failure leaves the robot
71 // in place.
72 auto se = helper.moveAndWaitForStop(
73 [&]
74 {
75 helper.getNavigator()->moveTo(relativeTarget,
77 },
78 [this] { return Base::shouldSkillTerminate(); });
79 if (se)
80 {
81 ARMARX_INFO << "Goal " << QUOTED(relativeTarget.matrix()) << "reached.";
82 }
83 else
84 {
85 if (se.isSafetyStopTriggeredEvent())
86 {
87 ARMARX_ERROR << "Safety stop was triggered!";
88
91 }
92 if (se.isUserAbortTriggeredEvent())
93 {
94 ARMARX_ERROR << "Aborted by user!";
95
96 return armarx::skills::Skill::MainResult{
98 }
99 if (se.isInternalErrorEvent())
100 {
101 ARMARX_ERROR << "Unknown internal error occured! "
102 << se.toInternalErrorEvent().message;
103
104 return armarx::skills::Skill::MainResult{
106 }
107 if (se.isGlobalPlanningFailedEvent())
108 {
109 ARMARX_ERROR << "Global planning failed! "
110 << se.toGlobalPlanningFailedEvent().message;
111
112 return ::armarx::skills::Skill::MainResult{
114 }
115
116 ARMARX_ERROR << "Unknown event!";
117 return ::armarx::skills::Skill::MainResult{
119 }
120
121 return armarx::skills::Skill::MainResult{
123 }
124
125 void
126 onStopRequested() override
127 {
128 if (helper.getNavigator().has_value())
129 {
130 ARMARX_CHECK(helper.getNavigator().has_value());
131 helper.getNavigator()->stop();
132 }
133 }
134
135
136 private:
137 NavigatingSkillHelper helper;
138 };
139
140} // namespace armarx::navigation::skills
#define VAROUT(x)
#define QUOTED(x)
NavigateRelativeSkill(const NavigatingSkillHelper::Properties &properties, const NavigatingSkillHelper::Services &srv, const armarx::skills::SkillDescription &desc)
armarx::skills::SimpleSpecializedSkill< arondto::MoveRelativePlanarParams > Base
std::optional< client::Navigator > & getNavigator()
client::StopEvent moveAndWaitForStop(IssueNavigationCommandT &&issueNavigationCommand, ShouldTerminateT &&shouldTerminate)
Issues the navigation command and waits for the navigator to stop, polling shouldTerminate meanwhile.
Skill::MainResult main() final
Override this method with the actual implementation.
Skill::InitResult init() final
Override this method with the actual implementation.
SkillID getSkillId() const
Get the id of the skill.
Definition Skill.cpp:587
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:179
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:194
A result struct for skill initialization.
Definition Skill.h:50
A result struct for th main method of a skill.
Definition Skill.h:62