SimplePeriodicSpecializedSkill.h
Go to the documentation of this file.
1#pragma once
2
4
6
7#include "PeriodicSkill.h"
9
10namespace armarx
11{
12 namespace skills
13 {
14 template <class AronT>
16 {
17
18 public:
20 using ParamType = AronT;
21
22 using Base::Base;
23
25
28 Base(skillDescription), frequency(frequency)
29 {
30 }
31
32 protected:
33 /// Do not use anymore
35 main(const typename Base::SpecializedMainInput& in) final
36 {
38
39 while (true)
40 {
42
43 const auto res = step(in);
44 switch (res.status)
45 {
47 // nothing to do here. break switch
48 break;
52 return Skill::MakeSucceededResult(res.data);
55 }
56
57 const auto sleepDuration = metronome.waitForNextTick();
58 if (not sleepDuration.isPositive())
59 {
60 ARMARX_INFO << deactivateSpam() << __PRETTY_FUNCTION__
61 << ": execution took too long (" << -sleepDuration
62 << " too long. Expected " << frequency.toCycleDuration() << ")";
63 }
64 }
65
66 // never happens
67 throw skills::error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
68 }
69
70 /// Override this method with your own step function
71 virtual StepResult
72 step(const typename Base::SpecializedMainInput& in)
73 {
74 ARMARX_IMPORTANT << "Dummy executing once skill '" << this->description.skillId
75 << "'. Please overwrite this method!";
77 }
78
79 protected:
81 };
82 } // namespace skills
83} // namespace armarx
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:99
Represents a frequency.
Definition Frequency.h:17
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition Metronome.h:57
Duration waitForNextTick() const
Wait and block until the target period is met.
Definition Metronome.cpp:27
Skill::MainResult main(const typename Base::SpecializedMainInput &in) final
Do not use anymore.
SimplePeriodicSpecializedSkill(const SkillDescription &skillDescription, const armarx::Frequency &frequency)
virtual StepResult step(const typename Base::SpecializedMainInput &in)
Override this method with your own step function.
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:413
static MainResult MakeAbortedResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:431
SkillDescription description
Definition Skill.h:372
void throwIfSkillShouldTerminate(const std::string &abortedMessage="") const
Definition Skill.cpp:389
static MainResult MakeFailedResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:422
A base class for skill exceptions.
Definition Exception.h:35
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
A result struct for th main method of a skill.
Definition Skill.h:62