PeriodicSpecializedSkill.h
Go to the documentation of this file.
1/**
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2022
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
26
29
30#include "PeriodicSkill.h"
31#include "SpecializedSkill.h"
32
33namespace armarx::skills
34{
35 template <class AronT>
37 {
38 public:
40
43
45
47
50 Base(skillDescription), frequency(frequency)
51 {
52 }
53
54 protected:
55 /// Do not use anymore
57 main() final
58 {
60
61 while (true)
62 {
64
65 const auto res = step();
66 switch (res.status)
67 {
69 // nothing to do here. break switch
70 break;
74 return Skill::MakeSucceededResult(res.data);
77 }
78
79 const auto sleepDuration = metronome.waitForNextTick();
80 if (not sleepDuration.isPositive())
81 {
82 ARMARX_INFO << deactivateSpam() << __PRETTY_FUNCTION__
83 << ": execution took too long (" << -sleepDuration
84 << " too long. Expected " << frequency.toCycleDuration() << ")";
85 }
86 }
87
88 throw skills::error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
89 }
90
91 /// Override this method with your own step function
92 virtual StepResult
94 {
95 ARMARX_IMPORTANT << "Dummy executing once skill '" << this->description.skillName
96 << "'. Please overwrite this method!";
98 }
99
100 protected:
102 };
103
104} // namespace armarx::skills
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() final
Do not use anymore.
PeriodicSpecializedSkill(const SkillDescription &skillDescription, const armarx::Frequency &frequency)
virtual StepResult step()
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
SkillID getSkillId() const
Get the id of the skill.
Definition Skill.cpp:587
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.
A result struct for th main method of a skill.
Definition Skill.h:62