SimplePeriodicSpecializedSkill.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "PeriodicSkill.h"
5 
6 namespace armarx
7 {
8  namespace skills
9  {
10  template <class AronT>
12  {
13 
14  public:
16  using ParamType = AronT;
17 
18  using Base::Base;
19 
21 
24  Base(skillDescription), frequency(frequency)
25  {
26  }
27 
28  protected:
29  /// Do not use anymore
31  main(const typename Base::SpecializedMainInput& in) final
32  {
34 
35  while (true)
36  {
38 
39  const auto res = step(in);
40  switch (res.status)
41  {
43  // nothing to do here. break switch
44  break;
46  return Skill::MakeAbortedResult();
48  return Skill::MakeSucceededResult(res.data);
50  return Skill::MakeFailedResult();
51  }
52 
53  const auto sleepDuration = metronome.waitForNextTick();
54  if (not sleepDuration.isPositive())
55  {
56  ARMARX_INFO << deactivateSpam() << __PRETTY_FUNCTION__
57  << ": execution took too long (" << -sleepDuration
58  << " too long. Expected " << frequency.toCycleDuration() << ")";
59  }
60  }
61 
62  // never happens
63  throw skills::error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
64  }
65 
66  /// Override this method with your own step function
67  virtual StepResult
68  step(const typename Base::SpecializedMainInput& in)
69  {
70  ARMARX_IMPORTANT << "Dummy executing once skill '" << this->description.skillId
71  << "'. Please overwrite this method!";
73  }
74 
75  protected:
77  };
78  } // namespace skills
79 } // namespace armarx
skills
This file is part of ArmarX.
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::skills::ActiveOrTerminatedSkillStatus::Succeeded
@ Succeeded
armarx::skills::ActiveOrTerminatedSkillStatus::Failed
@ Failed
armarx::skills::SimplePeriodicSpecializedSkill< platform_control::arondto::MovePlatformToPoseAcceptedType >::ParamType
platform_control::arondto::MovePlatformToPoseAcceptedType ParamType
Definition: SimplePeriodicSpecializedSkill.h:16
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:17
armarx::skills::SimplePeriodicSpecializedSkill::StepResult
PeriodicSkill::StepResult StepResult
Definition: SimplePeriodicSpecializedSkill.h:20
armarx::skills::SimplePeriodicSpecializedSkill::frequency
const armarx::Frequency frequency
Definition: SimplePeriodicSpecializedSkill.h:76
armarx::skills::SimplePeriodicSpecializedSkill::step
virtual StepResult step(const typename Base::SpecializedMainInput &in)
Override this method with your own step function.
Definition: SimplePeriodicSpecializedSkill.h:68
SimpleSpecializedSkill.h
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition: Skill.cpp:324
armarx::skills::SimplePeriodicSpecializedSkill::SimplePeriodicSpecializedSkill
SimplePeriodicSpecializedSkill(const SkillDescription &skillDescription, const armarx::Frequency &frequency)
Definition: SimplePeriodicSpecializedSkill.h:22
armarx::core::time::Frequency::toCycleDuration
Duration toCycleDuration() const
Definition: Frequency.cpp:67
armarx::skills::Skill::description
SkillDescription description
Definition: Skill.h:336
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:20
armarx::skills::SimpleSpecializedSkill
Definition: SimpleSpecializedSkill.h:10
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::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::SimplePeriodicSpecializedSkill
Definition: SimplePeriodicSpecializedSkill.h:11
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::skills::SimpleSpecializedSkill::Base
SpecializedSkill< AronT > Base
Definition: SimpleSpecializedSkill.h:13
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
PeriodicSkill.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::skills::SimplePeriodicSpecializedSkill::main
Skill::MainResult main(const typename Base::SpecializedMainInput &in) final
Do not use anymore.
Definition: SimplePeriodicSpecializedSkill.h:31
armarx::skills::PeriodicSkill::StepResult
Definition: PeriodicSkill.h:36