3 #include <experimental/memory>
18 #include "../ProviderID.h"
19 #include "../SkillExecutionRequest.h"
20 #include "../SkillID.h"
25 const std::string&
id,
30 executeSkillAsyncFunc,
31 const std::function<std::optional<skills::SkillStatusUpdate>(
35 fluxioSkill(fluxioSkill),
36 abortSkill(abortSkillFunc),
37 executeSkillAsync(executeSkillAsyncFunc),
38 getSkillExecutionStatus(getSkillExecutionStatusFunc)
41 result = std::make_shared<armarx::aron::data::Dict>();
51 result = std::make_shared<armarx::aron::data::Dict>();
57 const auto& type = std::make_shared<armarx::aron::type::Object>();
60 for (
const auto& [key, param] : this->fluxioSkill.
parameters)
62 if (param.type->getShortName() ==
"Object<Event>" || !param.isInput ||
63 this->possibleInputs[this->fluxioSkill.id]->hasElement(key))
69 if (fallBack ==
nullptr)
71 ARMARX_INFO <<
"No fallback value found for parameter " << param.name;
74 ARMARX_INFO <<
"Parameter is not required (MAYBE type). Using nullptr "
75 "(std::nullopt) instead.";
79 ARMARX_INFO <<
"Can't execute skill due to incomplete params.";
88 type->addMemberType(param.name, param.type);
91 const auto& params = std::make_shared<armarx::aron::data::Dict>();
95 const auto& paramIt = this->fluxioSkill.
parameters.find(key);
96 if (paramIt == this->fluxioSkill.
parameters.end())
98 ARMARX_WARNING <<
"Parameter with ID " << key <<
" not found in skill "
99 << this->fluxioSkill.
id;
100 ARMARX_WARNING <<
"Can't execute skill due to incomplete params.";
104 if (
value ==
nullptr && paramIt->second.required)
106 ARMARX_INFO <<
"Value for parameter " << paramIt->second.name <<
" is null.";
109 params->addElement(paramIt->second.name,
value);
113 const auto& isValid = params->fullfillsType(type);
117 ARMARX_WARNING <<
"Parameters do not fullfill the type of the skill";
118 ARMARX_WARNING <<
"Can't execute skill due to incompatible params.";
129 ARMARX_WARNING <<
"Executing skill with the following parameters: "
132 auto eid = executeSkillAsync(req);
134 this->executionId = eid;
149 if (!this->executionId.has_value())
152 ARMARX_WARNING <<
"Execution ID not set. Cannot abort skill (it should not be running "
157 abortSkill(this->executionId.value());
160 std::optional<std::vector<skills::FluxioSkillStatusUpdate>>
163 if (!this->executionId.has_value())
167 return std::vector<skills::FluxioSkillStatusUpdate>(this->
statusUpdates.begin(),
168 this->statusUpdates.end());
171 auto executionId = this->executionId.value();
173 auto status = getSkillExecutionStatus(executionId);
178 ARMARX_WARNING <<
"No status with execution ID " << this->executionId->toString()
189 this->setStatus(
update.status);
192 return std::vector<skills::FluxioSkillStatusUpdate>(this->
statusUpdates.begin(),
193 this->statusUpdates.end());
206 if (!executionId.has_value())
208 ARMARX_WARNING <<
"No execution ID available for skill " << this->skillId;
212 const auto&
s = getSkillExecutionStatus(executionId.value());
213 if (!
s.has_value() ||
s->result ==
nullptr)
215 ARMARX_WARNING <<
"No result available for skill " << this->skillId;
219 for (
const auto& [key,
value] :
s->result->getElements())
222 const auto& params = this->fluxioSkill.
parameters;
224 std::find_if(params.begin(),
226 [&key](
const std::pair<std::string, FluxioParameter>& it)
227 { return !it.second.isInput && it.second.name == key; });
229 if (param == params.end())
231 ARMARX_WARNING <<
"Parameter with name " << key <<
" not found in skill "
238 return this->
result->clone();