SimplePeriodicSkill.cpp
Go to the documentation of this file.
1 #include "SimplePeriodicSkill.h"
2 
3 namespace armarx::skills
4 {
6  const armarx::Frequency& frequency) :
7  SimpleSkill(skillDescription), frequency(frequency)
8  {
9  }
10 
13  {
15 
16  while (true)
17  {
19 
20  const auto res = step(in);
21  switch (res.status)
22  {
24  // nothing to do here. break switch
25  break;
27  return MakeAbortedResult();
29  return MakeSucceededResult(res.data);
31  return MakeFailedResult();
32  }
33 
34  const auto sleepDuration = metronome.waitForNextTick();
35  if (not sleepDuration.isPositive())
36  {
37  ARMARX_INFO << deactivateSpam() << __PRETTY_FUNCTION__
38  << ": execution took too long (" << -sleepDuration
39  << " too long. Expected " << frequency.toCycleDuration() << ")";
40  }
41  }
42 
43  // never happens
44  throw skills::error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
45  }
46 
49  {
50  ARMARX_IMPORTANT << "Dummy executing once skill '" << description.skillId
51  << "'. Please overwrite this method!";
53  }
54 } // namespace armarx::skills
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::skills::ActiveOrTerminatedSkillStatus::Succeeded
@ Succeeded
armarx::skills::ActiveOrTerminatedSkillStatus::Failed
@ Failed
armarx::skills
This file is part of ArmarX.
Definition: PeriodicUpdateWidget.cpp:11
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
armarx::skills::SimpleSkill::MainInput
Definition: SimpleSkill.h:22
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:17
armarx::skills::SimplePeriodicSkill::frequency
const armarx::Frequency frequency
Definition: SimplePeriodicSkill.h:30
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition: Skill.cpp:324
armarx::core::time::Frequency::toCycleDuration
Duration toCycleDuration() const
Definition: Frequency.cpp:67
armarx::skills::Skill::description
SkillDescription description
Definition: Skill.h:336
armarx::skills::SimplePeriodicSkill::SimplePeriodicSkill
SimplePeriodicSkill(const SkillDescription &skillDescription, const armarx::Frequency &frequency)
Definition: SimplePeriodicSkill.cpp:5
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:20
armarx::skills::ActiveOrTerminatedSkillStatus::Aborted
@ Aborted
armarx::skills::error::SkillException
A base class for skill exceptions.
Definition: Exception.h:40
armarx::skills::Skill::MakeAbortedResult
static MainResult MakeAbortedResult()
Definition: Skill.cpp:333
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition: Skill.cpp:315
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:48
armarx::skills::SimpleSkill
Definition: SimpleSkill.h:9
armarx::skills::ActiveOrTerminatedSkillStatus::Running
@ Running
armarx::core::time::Metronome::waitForNextTick
Duration waitForNextTick()
Wait and block until the target period is met.
Definition: Metronome.cpp:31
armarx::skills::SimpleSkill::main
MainResult main() final
Override this method with the actual implementation. The callback is for status updates to the callin...
Definition: SimpleSkill.cpp:15
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::core::time::Metronome
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition: Metronome.h:35
armarx::Logging::deactivateSpam
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.
Definition: Logging.cpp:92
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition: Skill.cpp:291
armarx::skills::SimplePeriodicSkill::step
virtual StepResult step(const MainInput &in)
Override this method with your own step function.
Definition: SimplePeriodicSkill.cpp:48
SimplePeriodicSkill.h
armarx::skills::PeriodicSkill::StepResult
Definition: PeriodicSkill.h:36