18#include <RobotAPI/interface/skills/SkillManagerInterface.h>
49 std::scoped_lock l(conditionCallbacksMutex);
50 conditionCallbacks.push_back({f, cb});
61 metronome.waitForNextTick();
70 std::optional<TerminatedSkillStatusUpdate>
73 auto parameters = proxy->getRootProfileParameters();
77 std::optional<TerminatedSkillStatusUpdate>
82 auto ret = handle->join();
105 auto eid = prx->executeSkillAsync(executorHistory, params);
107 std::unique_lock l(subskillsMutex);
111 prx->abortSkillAsync(eid);
113 this->subskills.push_back(eid);
115 return std::make_unique<SkillExecutionHandle>(std::move(prx), eid);
118 std::optional<TerminatedSkillStatusUpdate>
124 std::optional<TerminatedSkillStatusUpdate>
130 std::optional<TerminatedSkillStatusUpdate>
151 SkillProxyPtr proxy = std::make_unique<SkillProxy>(
manager, skillId);
167 SkillProxyPtr proxy = std::make_unique<SkillProxy>(
manager, skillId);
178 std::optional<TerminatedSkillStatusUpdate>
180 const ::armarx::skills::SkillID& skillID,
186 return callSubskill(std::move(proxy), parametersFunction(parameter_defaults));
193 if (this->parameters ==
nullptr)
196 this->parameters = d;
201 this->parameters->mergeAndReplaceCopy(d);
215 this->parameters = d;
221 return this->parameters;
242 conditionCheckingThread = std::thread(
250 std::scoped_lock l(conditionCallbacksMutex);
251 for (
auto& p : conditionCallbacks)
262 const auto sleepDuration = metronome.waitForNextTick();
263 if (not sleepDuration.isPositive())
266 <<
"ConditionCheckingThread: execution took too long ("
267 << -sleepDuration <<
" vs "
268 << conditionCheckingThreadFrequency.toCycleDuration()
329 if (conditionCheckingThread.joinable())
331 conditionCheckingThread.join();
344 auto _res = this->_init();
345 auto res = this->
init();
353 auto _res = this->_prepare();
362 auto _res = this->_main();
363 auto res = this->
main();
372 auto res = this->
exit();
373 auto _res = this->_exit();
379 const std::string& abortedMessage)
const
393 std::string message =
394 std::string(
"The skill '" +
getSkillId().toString() +
"' was asked to stop.");
395 message += abortedMessage.empty() ?
"" :
" Additional message: " + abortedMessage;
403 std::string message =
404 std::string(
"The skill '" +
getSkillId().toString() +
"' reached timeout.");
405 message += abortedMessage.empty() ?
"" :
" Additional message: " + abortedMessage;
447 std::scoped_lock l(subskillsMutex);
462 std::scoped_lock l(subskillsMutex);
476 Skill::_onTimeoutReached()
485 for (
const auto& execId : subskills)
487 manager->abortSkillAsync(execId.toManagerIce());
492 Skill::_onStopRequested()
501 for (
const auto& execId : subskills)
503 manager->abortSkillAsync(execId.toManagerIce());
546 <<
"'. Please overwrite this method.";
600 SkillProxyPtr proxy = std::make_unique<SkillProxy>(
manager, skillId);
static void WaitFor(const Duration &duration)
Wait for a certain duration on the virtual clock.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
void setTag(const LogTag &tag)
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
std::string toString() const
virtual PrepareResult prepare()
Override this method with the actual implementation.
void installConditionWithCallback(std::function< bool()> &&f, std::function< void()> &&cb)
install a condition which is frequently checked from the conditionCheckingThread
armarx::core::time::DateTime started
void notifyTimeoutReached()
armarx::core::time::DateTime exited
std::optional< TerminatedSkillStatusUpdate > callSubskill(const SkillID &skillId)
Call a subskill with the given ID and its default parameters.
std::atomic_bool finished
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
void setManager(const manager::dti::SkillManagerInterfacePrx &manager)
manager::dti::SkillManagerInterfacePrx manager
InitResult initSkill()
Initialization of a skill.
virtual InitResult init()
Override this method with the actual implementation.
static MainResult MakeAbortedResult(aron::data::DictPtr data=nullptr)
armarx::aron::data::DictPtr parameters
ExitResult exitSkill()
Exit method of a skill.
std::atomic_bool constructing
void notifySkillToStop()
Notify the skill from extern to stop.
PrepareResult prepareSkill()
Prepare a skill once.
std::atomic_bool timeoutReached
SkillDescription description
std::mutex parametersMutex
virtual void onStopRequested()
bool shouldSkillTerminate() const override
Returns whether the skill should terminate as soon as possible.
virtual MainResult main()
Override this method with the actual implementation.
void throwIfSkillShouldTerminate(const std::string &abortedMessage="") const
SkillID getSkillId() const
Get the id of the skill.
virtual ExitResult exit()
Override this method with the actual implementation.
void setCallback(const CallbackT &callback)
~Skill() override
Virtual destructor of a skill.
MainResult mainOfSkill()
Main method of a skill.
aron::data::DictPtr getParameters() const
Get the parameters of a skill that have been set so far.
SkillExecutionHandlePtr callSubskillAsync(const SkillID &skillId, std::function< void(aron::data::DictPtr &)> parametersFunction)
void setParameters(const aron::data::DictPtr &d)
Hard set the parameters, ignoring everything that has been set or merged before.
std::atomic_bool initializing
void updateSubSkillStatus(const skills::SkillStatusUpdate &statusUpdate)
SkillDescription getSkillDescription() const
Get the description of a skill.
Skill()=delete
We completely remove the default constructor!
virtual void onTimeoutReached()
Override these methods if you want to do something special when notification comes.
static MainResult MakeFailedResult(aron::data::DictPtr data=nullptr)
void updateParameters(const aron::data::DictPtr &d)
Merge parameters to the local parameters of the skill.
void setProviderId(const skills::ProviderID &pid)
Set the provider id of the description of the skill.
void waitFor(const armarx::Duration &duration, const armarx::Duration &interval=armarx::Duration::MilliSeconds(200)) const override
void setExecutorName(const std::string &executorName)
std::function< void(const SkillStatus s, const armarx::aron::data::DictPtr &)> CallbackT
std::atomic_bool preparing
#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...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< Dict > DictPtr
aron::data::DictPtr make_dict(_Args &&... args)
std::unique_ptr< class SkillExecutionHandle > SkillExecutionHandlePtr
std::unique_ptr< class SkillProxy > SkillProxyPtr
SkillUpdateManager GlobalSkillUpdateManager
TerminatedSkillStatus mergeSkillStatuseses(const TerminatedSkillStatus t1, const TerminatedSkillStatus t2)
This file offers overloads of toIce() and fromIce() functions for STL container types.
Interval< T > interval(T lo, T hi)
This file is part of ArmarX.
aron::data::DictPtr rootProfileDefaults
aron::type::ObjectPtr parametersType
armarx::core::time::Duration timeout
A result struct for skill exit function.
A result struct for skill initialization.
A result struct for th main method of a skill.
A result struct for skill preparing.