PeriodicSkill.cpp
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#include "PeriodicSkill.h"
23
28
31
32namespace armarx::skills
33{
36 Skill(skillDescription), frequency(frequency)
37 {
38 }
39
42 {
44
45 while (true)
46 {
48
49 const auto res = step();
50 switch (res.status)
51 {
53 // nothing to do here
54 break;
56 return MakeAbortedResult();
58 return MakeSucceededResult(res.data);
60 return MakeFailedResult();
61 }
62
63 const auto sleepDuration = metronome.waitForNextTick();
64 if (not sleepDuration.isPositive())
65 {
66 ARMARX_INFO << deactivateSpam() << __PRETTY_FUNCTION__
67 << ": execution took too long (" << -sleepDuration
68 << " too long. Expected " << frequency.toCycleDuration() << ")";
69 }
70 }
71
72 // never happens
73 throw skills::error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
74 }
75
78 {
79 ARMARX_IMPORTANT << "Dummy executing once skill '" << description.skillId
80 << "'. Please overwrite this method!";
82 }
83
84} // 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
virtual StepResult step()
Override this method with your own step function.
Skill::MainResult main() final
Do not use anymore.
const armarx::Frequency frequency
PeriodicSkill(const SkillDescription &skillDescription, const armarx::Frequency &frequency)
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
Skill()=delete
We completely remove the default constructor!
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