SkillReturnDataProcessing.cpp
Go to the documentation of this file.
1
2
4
9
11{
16
19 {
20 armarx::skills::Example::DataPassingParams root_profile_params;
21 root_profile_params.have_success = true;
22
23 std::string des =
24 "This skill calls the ConfigurableExitStatus skill. "
25 "The 'have_success' parameter determines whether the subskill succeeds or fails. "
26 "In both cases, the result data returned by ConfigurableExitStatus is printed to the "
27 "console. "
28 "This data is expected to be an integer with the value 1234.";
29
30 return SkillDescription{
31 .skillId = skills::SkillID{.skillName = "SkillReturnDataProcessing"},
32 .description = des,
33 .rootProfileDefaults = root_profile_params.toAron(),
35 .parametersType = armarx::skills::Example::DataPassingParams::ToAronType(),
36 .resultType = armarx::skills::Example::DataPassingReturn::ToAronType()};
37 }
38
40 SkillReturnDataProcessing::main(const SpecializedMainInput& in)
41 {
42 ARMARX_IMPORTANT << "Hi, from the SkillReturnDataProcessing skill.\n";
43
44 // Prepare ConfigurableExitStatus skill with passed parameter
45 auto configurableExitStatus = [this, in]()
46 {
47 armarx::skills::Example::DataPassingParams params;
48 params.have_success = in.parameters.have_success;
49 ARMARX_IMPORTANT << "Run ConfigurableExitStatus skill with success = "
50 << params.have_success;
51
52 return std::tuple{properties.dataPassingInnerSkillSkillID, params.toAron()};
53 };
54
55
56 auto [inner_skill, inner_skill_params] = configurableExitStatus();
57 ARMARX_IMPORTANT << "call subskill";
58 auto update2 = callSubskill(inner_skill, inner_skill_params);
59 ARMARX_IMPORTANT << "called subskill";
60
61 if (update2.has_value() and not update2->hasBeenSucceeded())
62 {
63 ARMARX_IMPORTANT << "ConfigurableExitStatus skill not successfull.";
64 // Print keys of received dict:
65 ARMARX_IMPORTANT << update2->result->getAllKeysAsString();
66 // Retrieve data value and parse it to the out object. Additional step is needed,
67 // as on failure the skill returns a dict with errorCode, errorMessage and data
68 auto error_dict = aron::data::Dict::DynamicCastAndCheck(update2->result);
69 auto result_dict = error_dict->getElement("data");
70 armarx::skills::Example::DataPassingReturn out;
71 out.fromAron(aron::data::Dict::DynamicCastAndCheck(result_dict));
72 ARMARX_IMPORTANT << "Return value of ConfigurableExitStatus skill: "
73 << out.some_return_int;
74 return {TerminatedSkillStatus::Succeeded, in.parameters.toAron()};
75 }
76
79
80
81 if (update2.has_value() and update2->hasBeenSucceeded())
82 {
83 ARMARX_IMPORTANT << "ConfigurableExitStatus skill successfull";
84 armarx::skills::Example::DataPassingReturn out;
85 // Print keys of received dict:
86 ARMARX_IMPORTANT << update2->result->getAllKeysAsString();
87 // Retrieve data value and parse it to the out object.
88 out.fromAron(update2->result);
89 ARMARX_IMPORTANT << "Return value of ConfigurableExitStatus skill: "
90 << out.some_return_int;
91 }
92
93 return {TerminatedSkillStatus::Succeeded, in.parameters.toAron()};
94 }
95
96
97} // namespace armarx::skills::provider
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
std::optional< TerminatedSkillStatusUpdate > callSubskill(const SkillID &skillId)
Call a subskill with the given ID and its default parameters.
Definition Skill.cpp:119
virtual MainResult main()
Override this method with the actual implementation.
Definition Skill.cpp:542
void throwIfSkillShouldTerminate(const std::string &abortedMessage="") const
Definition Skill.cpp:389
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
This file is part of ArmarX.
A result struct for th main method of a skill.
Definition Skill.h:62
#define ARMARX_TRACE
Definition trace.h:77