11#include <Ice/LocalException.h>
20#include <RobotAPI/interface/skills/SkillManagerInterface.h>
51 std::scoped_lock l(conditionCallbacksMutex);
52 conditionCallbacks.push_back({f, cb});
63 metronome.waitForNextTick();
72 std::optional<TerminatedSkillStatusUpdate>
75 auto parameters = proxy->getRootProfileParameters();
79 std::optional<TerminatedSkillStatusUpdate>
84 auto ret = handle->join();
107 auto eid = prx->executeSkillAsync(executorHistory, params);
109 std::unique_lock l(subskillsMutex);
113 prx->abortSkillAsync(eid);
115 this->subskills.push_back(eid);
117 return std::make_unique<SkillExecutionHandle>(std::move(prx), eid);
120 std::optional<TerminatedSkillStatusUpdate>
126 std::optional<TerminatedSkillStatusUpdate>
132 std::optional<TerminatedSkillStatusUpdate>
153 SkillProxyPtr proxy = std::make_unique<SkillProxy>(
manager, skillId);
169 SkillProxyPtr proxy = std::make_unique<SkillProxy>(
manager, skillId);
180 std::optional<TerminatedSkillStatusUpdate>
182 const ::armarx::skills::SkillID& skillID,
188 return callSubskill(std::move(proxy), parametersFunction(parameter_defaults));
195 if (this->parameters ==
nullptr)
198 this->parameters = d;
203 this->parameters->mergeAndReplaceCopy(d);
217 this->parameters = d;
223 return this->parameters;
244 conditionCheckingThread = std::thread(
252 std::scoped_lock l(conditionCallbacksMutex);
253 for (
auto& p : conditionCallbacks)
264 const auto sleepDuration = metronome.waitForNextTick();
265 if (not sleepDuration.isPositive())
268 <<
"ConditionCheckingThread: execution took too long ("
269 << -sleepDuration <<
" vs "
270 << conditionCheckingThreadFrequency.toCycleDuration()
331 if (conditionCheckingThread.joinable())
333 conditionCheckingThread.join();
346 auto _res = this->_init();
347 auto res = this->
init();
355 auto _res = this->_prepare();
364 auto _res = this->_main();
365 auto res = this->
main();
374 auto res = this->
exit();
375 auto _res = this->_exit();
381 const std::string& abortedMessage)
const
395 std::string message =
396 std::string(
"The skill '" +
getSkillId().toString() +
"' was asked to stop.");
397 message += abortedMessage.empty() ?
"" :
" Additional message: " + abortedMessage;
405 std::string message =
406 std::string(
"The skill '" +
getSkillId().toString() +
"' reached timeout.");
407 message += abortedMessage.empty() ?
"" :
" Additional message: " + abortedMessage;
449 std::scoped_lock l(subskillsMutex);
464 std::scoped_lock l(subskillsMutex);
478 Skill::_onTimeoutReached()
487 for (
const auto& execId : subskills)
491 manager->abortSkillAsync(execId.toManagerIce());
493 catch (
const Ice::LocalException& e)
496 <<
"': " << e.what();
502 Skill::_onStopRequested()
511 for (
const auto& execId : subskills)
515 manager->abortSkillAsync(execId.toManagerIce());
517 catch (
const Ice::LocalException& e)
520 <<
"': " << e.what();
564 <<
"'. Please overwrite this method.";
618 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.