NavigateToNamedLocation.cpp
Go to the documentation of this file.
2
3#include <optional>
4#include <string>
5
10
17
22#include <armarx/navigation/skills/aron/NavigateToLocation.aron.generated.h>
24
25
27{
28
29 armarx::skills::SkillDescription
31 {
32 ParamType defaultParameters;
33
34 defaultParameters.useObjectLocations = true;
35
36 defaultParameters.navigateToLocation.fromAron(
38 defaultParameters.navigateToLocation.location = "<Resolved according to 'locationName'>";
39
40 std::stringstream description;
41 description << "Resolve a named location and navigate to it."
42 << "\n\n`locationName`: The location's human-readable name."
43 << "\n\n`minMatchRatio`: Minimum match ratio required to accept a match "
44 "between a location's name and `locationName`."
45 << "\n\nThe parameters `navigateToLocation` are passed to the sub skill "
46 "`NavigateToLocation`, except for `navigateToLocation.location`, which is "
47 "set to the location that `locationName` is resolved to.";
48
51 .description = description.str(),
52 .rootProfileDefaults = defaultParameters.toAron(),
54 .parametersType = Params::ToAronType(),
55 };
56 }
57
62
64 const Services& services) :
65 Base(GetSkillDescription()), services(services), properties(properties)
66 {
67 ARMARX_CHECK_NOT_NULL(services.locationReader);
68 ARMARX_CHECK_NOT_NULL(services.objectClassReader);
69 }
70
72 NavigateToNamedLocation::main(const Base::SpecializedMainInput& in)
73 {
75
76 const std::optional<ResolvedLocation> resolvedLocation =
77 resolveLocationName(in.parameters.locationName,
79 .locationReader = services.locationReader,
80 .objectPoseClient = services.objectPoseClient,
81 .objectClassReader = services.objectClassReader,
82 },
83 in.parameters.minMatchRatio,
84 in.parameters.useObjectLocations);
85
86 if (not resolvedLocation.has_value())
87 {
88 ARMARX_ERROR << "Could not resolve location name '" << in.parameters.locationName
89 << "' to any location.";
90 return MakeFailedResult();
91 }
92
93 ARMARX_IMPORTANT << "Navigating to location "
94 << QUOTED(resolvedLocation->provider + "::" + resolvedLocation->name)
95 << ".";
96
98
99 // Navigate to location
100 {
101 using ParamsT = arondto::NavigateToLocationParams;
102
103 // pedantic check
104 ARMARX_CHECK(resolvedLocation.has_value());
105
107 [&resolvedLocation, &in](ParamsT& parameters) noexcept
108 {
109 // override the parameters completely
110 parameters = in.parameters.navigateToLocation;
111
112 parameters.location = resolvedLocation->name;
113 parameters.locationProvider =
114 resolvedLocation->provider;
115 });
117 {
118 return MakeFailedResult();
119 }
120 }
121
123
124 return MakeSucceededResult();
125 }
126
127} // namespace armarx::navigation::skills
#define QUOTED(x)
static Duration Hours(std::int64_t hours)
Constructs a duration in hours.
Definition Duration.cpp:120
static armarx::skills::SkillDescription DefaultSkillDescription()
::armarx::skills::SimpleSpecializedSkill< Params > Base
NavigateToNamedLocation(const Properties &properties, const Services &services)
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
armarx::aron::data::DictPtr parameters
Definition Skill.h:369
SkillDescription description
Definition Skill.h:372
void throwIfSkillShouldTerminate(const std::string &abortedMessage="") const
Definition Skill.cpp:389
static MainResult MakeFailedResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:422
#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_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:188
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:194
const armarx::skills::SkillID NavigateToNamedLocation
Definition skill_ids.cpp:66
std::optional< ResolvedLocation > resolveLocationName(const std::string &locationName, const LocationNameResolverServices &services, const double minMatchRatio, const bool useObjectLocations)
Resolve a human-readable place onto a location, the way NavigateToNamedLocation does.
bool skillExecutionFailed(const std::optional< armarx::skills::TerminatedSkillStatusUpdate > &update)
This file offers overloads of toIce() and fromIce() functions for STL container types.
This file is part of ArmarX.
This file is part of ArmarX.
Everything needed to turn a spoken place into a location.
A result struct for th main method of a skill.
Definition Skill.h:62
#define ARMARX_TRACE
Definition trace.h:75