NavigateToAlternatives.cpp
Go to the documentation of this file.
2
3#include <chrono>
4#include <future>
5#include <string>
6
7#include <Eigen/Core>
8#include <Eigen/Geometry>
9
13
16
23
25{
32
34 NavigateToAlternatives::init(const Base::SpecializedInitInput& in)
35 {
36 helper.init(in.parameters.navigatingSkillParams,
37 DefaultSkillDescription().skillId.skillName);
38
39 return ::armarx::skills::Skill::InitResult{
41 }
42
44 NavigateToAlternatives::main(const Base::SpecializedMainInput& in)
45 {
46 std::vector<core::TargetAlternative> targetAlternatives;
47 for (const auto& t : in.parameters.targetAlternatives)
48 {
49 core::TargetAlternative bo;
50 core::fromAron(t, bo);
51 targetAlternatives.emplace_back(bo);
52 }
53
54 ARMARX_INFO << "moving to " << targetAlternatives.size() << " alternatives";
55
56 // execute
57 ARMARX_INFO << "Sending navigation request";
58 // Wait until goal is reached, re-planning while the retry budget lasts
59 auto se = helper.moveAndWaitForStop(
60 [&]
61 {
62 helper.getNavigator()->moveToAlternatives(targetAlternatives,
64 },
65 [this] { return shouldSkillTerminate(); });
66 if (se)
67 {
68 ARMARX_INFO << "Goal reached.";
69 }
70 else
71 {
72 if (se.isSafetyStopTriggeredEvent())
73 {
74 ARMARX_ERROR << "Safety stop was triggered!";
75
76 return ::armarx::skills::Skill::MainResult{
78 }
79 if (se.isUserAbortTriggeredEvent())
80 {
81 ARMARX_ERROR << "Aborted by user!";
82
83 return ::armarx::skills::Skill::MainResult{
85 }
86 if (se.isInternalErrorEvent())
87 {
88 ARMARX_ERROR << "Unknown internal error occured! "
89 << se.toInternalErrorEvent().message;
90
91 return ::armarx::skills::Skill::MainResult{
93 }
94 if (se.isGlobalPlanningFailedEvent())
95 {
96 ARMARX_ERROR << "Global planning failed! "
97 << se.toGlobalPlanningFailedEvent().message;
98
99 return ::armarx::skills::Skill::MainResult{
101 }
102
103 ARMARX_ERROR << "Unknown event!";
104 return ::armarx::skills::Skill::MainResult{
106 }
107
108
109 return ::armarx::skills::Skill::MainResult{
111 }
112
113 void
114 NavigateToAlternatives::onStopRequested()
115 {
116 if (helper.getNavigator().has_value())
117 {
118 ARMARX_CHECK(helper.getNavigator().has_value());
119 helper.getNavigator()->stop();
120 }
121 }
122
123 armarx::skills::SkillDescription
125 {
126 ParamType defaultParameters;
127 defaultParameters.targetAlternatives = {};
128 defaultParameters.navigatingSkillParams = NavigatingSkillHelper::DefaultSkillDescription();
129
131 .skillId = {.skillName = constants::skill_names::NavigateToAlternatives},
132 .description = "Navigate to a list of prioritized target alternatives.",
133 .rootProfileDefaults = defaultParameters.toAron(),
135 .parametersType = Params::ToAronType()};
136 }
137
138} // namespace armarx::navigation::skills
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()
NavigateToAlternatives(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.
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
void fromAron(const arondto::GlobalTrajectoryPoint &dto, GlobalTrajectoryPoint &bo)
A result struct for skill initialization.
Definition Skill.h:50
A result struct for th main method of a skill.
Definition Skill.h:62