NavigateToNamedLocation.cpp
Go to the documentation of this file.
1
#include "
NavigateToNamedLocation.h
"
2
3
#include <sstream>
4
5
#include <
ArmarXCore/core/exceptions/local/ExpressionException.h
>
6
#include <
ArmarXCore/core/logging/Logging.h
>
7
#include <
ArmarXCore/core/time/Duration.h
>
8
#include <
ArmarXCore/util/CPPUtility/trace.h
>
9
10
#include <
RobotAPI/libraries/armem/core/MemoryID.h
>
11
#include <
RobotAPI/libraries/skills/core/Skill.h
>
12
#include <
RobotAPI/libraries/skills/core/SkillDescription.h
>
13
#include <
RobotAPI/libraries/skills/core/error/Exception.h
>
14
15
#include <
armarx/navigation/skills/NavigateToLocation.h
>
16
#include <armarx/navigation/skills/aron/NavigateToLocation.aron.generated.h>
17
#include <
armarx/navigation/skills/skill_ids.h
>
18
19
namespace
armarx::navigation::skills
20
{
21
22
armarx::skills::SkillDescription
23
NavigateToNamedLocation::GetSkillDescription
()
24
{
25
ParamType
defaultParameters;
26
27
defaultParameters.navigateToLocation.fromAron(
28
NavigateToLocation::DefaultSkillDescription
().rootProfileDefaults);
29
defaultParameters.navigateToLocation.location =
"<Resolved according to 'locationName'>"
;
30
31
std::stringstream
description
;
32
description
<<
"Resolve a named location and navigate to it."
33
<<
"\n\n`locationName`: The location's human-readable name."
34
<<
"\n\n`minMatchRatio`: Minimum match ratio required to accept a match "
35
"between a location's name and `locationName`."
36
<<
"\n\nThe parameters `navigateToLocation` are passed to the sub skill "
37
"`NavigateToLocation`, except for `navigateToLocation.location`, which is "
38
"set to the location that `locationName` is resolved to."
;
39
40
return
armarx::skills::SkillDescription
{
41
.
skillId
=
skill_ids::NavigateToNamedLocation
,
42
.description =
description
.str(),
43
.
rootProfileDefaults
= defaultParameters.toAron(),
44
.timeout =
armarx::core::time::Duration::Hours
(1),
45
.parametersType = Params::ToAronType(),
46
};
47
}
48
49
NavigateToNamedLocation::Properties::SubSkillIds::SubSkillIds
() :
50
navigateToLocation{
armarx::navigation::skills::skill_ids::NavigateToLocation
}
51
{
52
}
53
54
NavigateToNamedLocation::NavigateToNamedLocation
(
const
Properties
& properties,
55
const
Services
& services) :
56
Base
(
GetSkillDescription
()), services(services), properties(properties)
57
{
58
}
59
60
::armarx::skills::Skill::MainResult
61
NavigateToNamedLocation::main
(
const
Base::SpecializedMainInput& in)
62
{
63
ARMARX_TRACE
;
64
65
// Resolve location name
66
armarx::armem::MemoryID
locationId;
67
{
68
std::stringstream log;
69
auto
matchResult = services.
locationReader
.
resolveLocationName
(
70
in.parameters.locationName, in.parameters.minMatchRatio, &log);
71
72
ARMARX_INFO
<< log.str();
73
ARMARX_CHECK
(matchResult.resolved.has_value() xor matchResult.errorMessage.has_value());
74
75
if
(matchResult.errorMessage.has_value())
76
{
77
std::stringstream msg;
78
msg <<
"Failed to resolve location name '"
<< in.parameters.locationName
79
<<
"'. Reason: "
<< matchResult.errorMessage.value();
80
throw
armarx::skills::error::SkillFailedException
(__PRETTY_FUNCTION__, msg.str());
81
}
82
83
ARMARX_CHECK
(matchResult.resolved.has_value());
84
locationId = matchResult.resolved->locationId;
85
}
86
87
ARMARX_IMPORTANT
<<
"Navigating to location '"
<< locationId <<
"'."
;
88
89
throwIfSkillShouldTerminate
();
90
91
// Navigate to location
92
{
93
arondto::NavigateToLocationParams
parameters
= in.parameters.navigateToLocation;
94
parameters
.location = locationId.providerSegmentName +
"/"
+ locationId.entityName;
95
96
auto
update
=
callSubskill
(properties.
subSkillIDs
.
navigateToLocation
,
parameters
);
97
if
(not(
update
.has_value() and
update
->hasBeenSucceeded()))
98
{
99
return
MakeFailedResult
();
100
}
101
}
102
103
throwIfSkillShouldTerminate
();
104
105
return
MakeSucceededResult
();
106
}
107
108
}
// namespace armarx::navigation::skills
armarx::navigation::skills::NavigateToNamedLocation::Properties::SubSkillIds::SubSkillIds
SubSkillIds()
Definition:
NavigateToNamedLocation.cpp:49
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:213
Exception.h
armarx::navigation::skills::NavigateToNamedLocation::Services::locationReader
armarx::navigation::memory::client::graph::Reader locationReader
Definition:
NavigateToNamedLocation.h:55
armarx::skills::SimpleSpecializedSkill< arondto::NavigateToNamedLocationParams >::ParamType
arondto::NavigateToNamedLocationParams ParamType
Definition:
SimpleSpecializedSkill.h:14
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition:
Logging.h:190
armarx::skills::Skill::parameters
armarx::aron::data::DictPtr parameters
Definition:
Skill.h:297
armarx::skills::SkillDescription
Definition:
SkillDescription.h:17
MemoryID.h
NavigateToNamedLocation.h
trace.h
Duration.h
armarx::navigation::skills::NavigateToNamedLocation::Services
Definition:
NavigateToNamedLocation.h:53
armarx::skills::error::SkillFailedException
Definition:
Exception.h:61
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:32
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition:
ExpressionException.h:82
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition:
Skill.cpp:338
armarx::core::time::Duration::Hours
static Duration Hours(std::int64_t hours)
Constructs a duration in hours.
Definition:
Duration.cpp:120
NavigateToLocation.h
ARMARX_TRACE
#define ARMARX_TRACE
Definition:
trace.h:77
armarx::armem::MemoryID
A memory ID.
Definition:
MemoryID.h:47
armarx::navigation::skills::NavigateToNamedLocation::GetSkillDescription
::armarx::skills::SkillDescription GetSkillDescription()
Definition:
NavigateToNamedLocation.cpp:23
Skill.h
armarx::navigation::skills::NavigateToLocation::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition:
NavigateToLocation.cpp:60
armarx::skills::Skill::description
SkillDescription description
Definition:
Skill.h:300
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition:
SkillDescription.h:19
armarx::skills::SimpleSpecializedSkill
Definition:
SimpleSpecializedSkill.h:10
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition:
Skill.cpp:329
armarx::navigation::skills::skill_ids::NavigateToLocation
const armarx::skills::SkillID NavigateToLocation
Definition:
skill_ids.cpp:61
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition:
Skill.h:39
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition:
mongodb.cpp:68
armarx::skills::SkillDescription::rootProfileDefaults
aron::data::DictPtr rootProfileDefaults
Definition:
SkillDescription.h:21
armarx::navigation::skills::NavigateToNamedLocation::Properties::subSkillIDs
SubSkillIds subSkillIDs
Definition:
NavigateToNamedLocation.h:67
ExpressionException.h
ARMARX_INFO
#define ARMARX_INFO
Definition:
Logging.h:181
armarx::skills::SimpleSpecializedSkill< arondto::NavigateToNamedLocationParams >::main
Skill::MainResult main() final
Definition:
SimpleSpecializedSkill.h:71
skill_ids.h
armarx::navigation::skills::NavigateToNamedLocation::Properties::SubSkillIds::navigateToLocation
armarx::skills::SkillID navigateToLocation
Definition:
NavigateToNamedLocation.h:64
armarx::navigation::skills::NavigateToNamedLocation::Properties
Definition:
NavigateToNamedLocation.h:58
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition:
Skill.cpp:305
Logging.h
armarx::navigation::skills
Definition:
constants.cpp:25
armarx::navigation::skills::NavigateToNamedLocation::NavigateToNamedLocation
NavigateToNamedLocation(const Properties &properties, const Services &services)
Definition:
NavigateToNamedLocation.cpp:54
armarx::navigation::skills::skill_ids::NavigateToNamedLocation
const armarx::skills::SkillID NavigateToNamedLocation
Definition:
skill_ids.cpp:66
SkillDescription.h
armarx
navigation
skills
NavigateToNamedLocation.cpp
Generated on Sat Mar 29 2025 09:17:35 for armarx_documentation by
1.8.17