NavigateToNamedLocation.cpp
Go to the documentation of this file.
2 
3 #include <SimoxUtility/algorithm/string/fuzzy_multi_match.hpp>
4 
6 
7 #include <armarx/navigation/core/aron/Location.aron.generated.h>
11 
13 {
14 
17  {
18  ParamType defaultParameters;
19 
20  defaultParameters.navigateToLocation.fromAron(
21  NavigateToLocation::DefaultSkillDescription().rootProfileDefaults);
22  defaultParameters.navigateToLocation.location = "<Resolved according to 'locationName'>";
23 
24  std::stringstream description;
25  description << "Resolve a named location and navigate to it."
26  << "\n\n`locationName`: The location's human-readable name."
27  << "\n\n`minMatchRatio`: Minimum match ratio required to accept a match "
28  "between a location's name and `locationName`."
29  << "\n\nThe parameters `navigateToLocation` are passed to the sub skill "
30  "`NavigateToLocation`, except for `navigateToLocation.location`, which is "
31  "set to the location that `locationName` is resolved to.";
32 
35  .description = description.str(),
36  .rootProfileDefaults = defaultParameters.toAron(),
38  .parametersType = Params::ToAronType(),
39  };
40  }
41 
44  {
45  }
46 
48  const Services& services) :
49  Base(GetSkillDescription()), services(services), properties(properties)
50  {
51  }
52 
54  NavigateToNamedLocation::main(const Base::SpecializedMainInput& in)
55  {
57 
58  // Resolve location name
59  armarx::armem::MemoryID locationId;
60  {
61  std::stringstream log;
62  auto matchResult = services.locationReader.resolveLocationName(
63  in.parameters.locationName, in.parameters.minMatchRatio, &log);
64 
65  ARMARX_INFO << log.str();
66  ARMARX_CHECK(matchResult.resolved.has_value() xor matchResult.errorMessage.has_value());
67 
68  if (matchResult.errorMessage.has_value())
69  {
70  std::stringstream msg;
71  msg << "Failed to resolve location name '" << in.parameters.locationName
72  << "'. Reason: " << matchResult.errorMessage.value();
73  throw armarx::skills::error::SkillFailedException(__PRETTY_FUNCTION__, msg.str());
74  }
75 
76  ARMARX_CHECK(matchResult.resolved.has_value());
77  locationId = matchResult.resolved->locationId;
78  }
79 
80  ARMARX_IMPORTANT << "Navigating to location '" << locationId << "'.";
81 
83 
84  // Navigate to location
85  {
86  arondto::NavigateToLocationParams parameters = in.parameters.navigateToLocation;
87  parameters.location = locationId.providerSegmentName + "/" + locationId.entityName;
88 
90  if (not(update.has_value() and update->hasBeenSucceeded()))
91  {
92  return MakeFailedResult();
93  }
94  }
95 
97 
98  return MakeSucceededResult();
99  }
100 
101 } // namespace armarx::navigation::skills
armarx::navigation::skills::NavigateToNamedLocation::Properties::SubSkillIds::SubSkillIds
SubSkillIds()
Definition: NavigateToNamedLocation.cpp:42
armarx::navigation::memory::client::graph::Reader::resolveLocationName
ResolveLocationNameResult resolveLocationName(const std::string &locationName, double minMatchRatio, std::ostream *log=nullptr)
Resolve a location by human-readable name.
Definition: Reader.cpp:200
armarx::navigation::skills::NavigateToNamedLocation::Services::locationReader
armarx::navigation::memory::client::graph::Reader locationReader
Definition: NavigateToNamedLocation.h:53
armarx::skills::SimpleSpecializedSkill< arondto::NavigateToNamedLocationParams >::ParamType
arondto::NavigateToNamedLocationParams ParamType
Definition: SimpleSpecializedSkill.h:14
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
SpecializedSkillProxy.h
armarx::skills::Skill::parameters
armarx::aron::data::DictPtr parameters
Definition: Skill.h:333
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
NavigateToNamedLocation.h
armarx::navigation::skills::NavigateToNamedLocation::Services
Definition: NavigateToNamedLocation.h:51
armarx::skills::error::SkillFailedException
Definition: Exception.h:76
armarx::skills::Skill::callSubskill
std::optional< TerminatedSkillStatusUpdate > callSubskill(const skills::SkillProxy &proxy)
Call a subskill with default parameters and block until the subskill terminates.
Definition: Skill.cpp:22
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
constants.h
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition: Skill.cpp:324
armarx::core::time::Duration::Hours
static Duration Hours(std::int64_t hours)
Constructs a duration in hours.
Definition: Duration.cpp:139
NavigateToLocation.h
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::navigation::skills::NavigateToNamedLocation::GetSkillDescription
::armarx::skills::SkillDescription GetSkillDescription()
Definition: NavigateToNamedLocation.cpp:16
armarx::navigation::skills::NavigateToLocation::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: NavigateToLocation.cpp:52
skill_ids.h
armarx::skills::Skill::description
SkillDescription description
Definition: Skill.h:336
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:20
armarx::skills::SimpleSpecializedSkill
Definition: SimpleSpecializedSkill.h:10
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition: Skill.cpp:315
armarx::navigation::skills::skill_ids::NavigateToLocation
const armarx::skills::SkillID NavigateToLocation
Definition: skill_ids.cpp:58
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:48
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::skills::SkillDescription::rootProfileDefaults
aron::data::DictPtr rootProfileDefaults
Definition: SkillDescription.h:22
armarx::navigation::skills::NavigateToNamedLocation::Properties::subSkillIDs
SubSkillIds subSkillIDs
Definition: NavigateToNamedLocation.h:65
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::skills::SimpleSpecializedSkill< arondto::NavigateToNamedLocationParams >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::navigation::skills::NavigateToNamedLocation::Properties::SubSkillIds::navigateToLocation
armarx::skills::SkillID navigateToLocation
Definition: NavigateToNamedLocation.h:62
armarx::navigation::skills::NavigateToNamedLocation::Properties
Definition: NavigateToNamedLocation.h:56
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition: Skill.cpp:291
armarx::navigation::skills
Definition: constants.cpp:25
armarx::navigation::skills::NavigateToNamedLocation::NavigateToNamedLocation
NavigateToNamedLocation(const Properties &properties, const Services &services)
Definition: NavigateToNamedLocation.cpp:47
armarx::navigation::skills::skill_ids::NavigateToNamedLocation
const armarx::skills::SkillID NavigateToNamedLocation
Definition: skill_ids.cpp:63