NavigateToLocation.cpp
Go to the documentation of this file.
2
3#include <chrono>
4#include <future>
5#include <mutex>
6#include <optional>
7#include <sstream>
8#include <string>
9
10#include <Eigen/Core>
11#include <Eigen/Geometry>
12
18
22
30
32{
33
34 armarx::skills::SkillDescription
36 {
37 ParamType defaultParameters;
38 defaultParameters.location = "";
39 defaultParameters.navigatingSkillParams = NavigatingSkillHelper::DefaultSkillDescription();
40
41
42 std::stringstream description;
44 << "Retrieve the location `location` from the memory and navigate to it."
45 << "\n\nThe `location` is specified by its provider segment name and entity name"
46 " in the format `providerSegmentName/entityName` .";
47
50 .description = description.str(),
51 .rootProfileDefaults = defaultParameters.toAron(),
53 .parametersType = Params::ToAronType(),
54 };
55 }
56
62
64 NavigateToLocation::init(const Base::SpecializedInitInput& in)
65 {
66 helper.init(in.parameters.navigatingSkillParams,
67 DefaultSkillDescription().skillId.skillName);
68
69 return ::armarx::skills::Skill::InitResult{
71 }
72
74 NavigateToLocation::main(const Base::SpecializedMainInput& in)
75 {
76 const std::string& location = in.parameters.location;
77 const std::optional<std::string>& locationProvider = in.parameters.locationProvider;
78
79 ARMARX_INFO << "moving to target " << VAROUT(location);
80
81 // execute
82 ARMARX_INFO << "Sending navigation request";
83
84 // client::PathBuilder builder;
85 // builder.add(location, client::GlobalPlanningStrategy::Free);
86
87 // Wait until goal is reached, re-planning while the retry budget lasts
88 auto se = helper.moveAndWaitForStop(
89 [&] { helper.getNavigator()->moveToLocation(location, locationProvider); },
90 [this] { return shouldSkillTerminate(); });
91 if (se)
92 {
93 ARMARX_INFO << "Goal " << QUOTED(location) << "reached.";
94 return ::armarx::skills::Skill::MainResult{
96 }
97 else
98 {
99 if (se.isSafetyStopTriggeredEvent())
100 {
101 ARMARX_INFO << "Safety stop was triggered!";
102
103 return ::armarx::skills::Skill::MainResult{
105 }
106 if (se.isUserAbortTriggeredEvent())
107 {
108 ARMARX_INFO << "Aborted by user!";
109
110 return ::armarx::skills::Skill::MainResult{
112 }
113 if (se.isInternalErrorEvent())
114 {
115 ARMARX_INFO << "Unknown internal error occured! "
116 << se.toInternalErrorEvent().message;
117
118 return ::armarx::skills::Skill::MainResult{
120 }
121 if (se.isGlobalPlanningFailedEvent())
122 {
123 ARMARX_ERROR << "Global planning failed! "
124 << se.toGlobalPlanningFailedEvent().message;
125
126 return ::armarx::skills::Skill::MainResult{
128 }
129
130 ARMARX_ERROR << "Unknown event!";
131 return ::armarx::skills::Skill::MainResult{
133 }
134
135 return ::armarx::skills::Skill::MainResult{
137 }
138
139 void
140 NavigateToLocation::onStopRequested()
141 {
142 if (helper.getNavigator().has_value())
143 {
144 ARMARX_CHECK(helper.getNavigator().has_value());
145 helper.getNavigator()->stop();
146 }
147 }
148
149} // namespace armarx::navigation::skills
#define VAROUT(x)
#define QUOTED(x)
static Duration Hours(std::int64_t hours)
Constructs a duration in hours.
Definition Duration.cpp:120
::armarx::skills::SimpleSpecializedSkill< Params > Base
static armarx::skills::SkillDescription DefaultSkillDescription()
NavigateToLocation(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()
client::StopEvent moveAndWaitForStop(IssueNavigationCommandT &&issueNavigationCommand, ShouldTerminateT &&shouldTerminate)
Issues the navigation command and waits for the navigator to stop, polling shouldTerminate meanwhile.
SkillDescription description
Definition Skill.h:372
bool shouldSkillTerminate() const override
Returns whether the skill should terminate as soon as possible.
Definition Skill.cpp:469
#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
const armarx::skills::SkillID NavigateToLocation
Definition skill_ids.cpp:61
A result struct for skill initialization.
Definition Skill.h:50
A result struct for th main method of a skill.
Definition Skill.h:62