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 
33 namespace armarx::skills
34 {
35  template <class AronT>
37  {
38  public:
40 
41  using Skill::description;
42  using Skill::getSkillId;
43 
45 
46  PeriodicSpecializedSkill() = delete;
47 
48  PeriodicSpecializedSkill(const SkillDescription& skillDescription,
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;
72  return Skill::MakeAbortedResult();
74  return Skill::MakeSucceededResult(res.data);
76  return Skill::MakeFailedResult();
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
93  step()
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
armarx::skills::PeriodicSpecializedSkill::StepResult
PeriodicSkill::StepResult StepResult
Definition: PeriodicSpecializedSkill.h:44
armarx::skills::SpecializedSkill
Definition: SpecializedSkill.h:9
Exception.h
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::skills::PeriodicSpecializedSkill::step
virtual StepResult step()
Override this method with your own step function.
Definition: PeriodicSpecializedSkill.h:93
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:17
Frequency.h
armarx::skills::PeriodicSpecializedSkill::frequency
const armarx::Frequency frequency
Definition: PeriodicSpecializedSkill.h:101
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:16
armarx::skills::PeriodicSpecializedSkill::PeriodicSpecializedSkill
PeriodicSpecializedSkill(const SkillDescription &skillDescription, const armarx::Frequency &frequency)
Definition: PeriodicSpecializedSkill.h:48
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition: Skill.cpp:338
armarx::core::time::Frequency::toCycleDuration
Duration toCycleDuration() const
Definition: Frequency.cpp:60
armarx::skills::PeriodicSpecializedSkill
Definition: PeriodicSpecializedSkill.h:36
Skill.h
armarx::skills::Skill::description
SkillDescription description
Definition: Skill.h:300
armarx::skills::ActiveOrTerminatedSkillStatus::Aborted
@ Aborted
Metronome.h
armarx::skills::error::SkillException
A base class for skill exceptions.
Definition: Exception.h:34
armarx::skills::Skill::MakeAbortedResult
static MainResult MakeAbortedResult()
Definition: Skill.cpp:347
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition: Skill.cpp:329
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:39
armarx::skills::ActiveOrTerminatedSkillStatus::Running
@ Running
armarx::core::time::Metronome::waitForNextTick
Duration waitForNextTick()
Wait and block until the target period is met.
Definition: Metronome.cpp:27
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::core::time::Metronome
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition: Metronome.h:34
armarx::skills::PeriodicSpecializedSkill::main
Skill::MainResult main() final
Do not use anymore.
Definition: PeriodicSpecializedSkill.h:57
SpecializedSkill.h
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:99
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition: Skill.cpp:305
PeriodicSkill.h
armarx::skills::Skill::getSkillId
SkillID getSkillId() const
Get the id of the skill.
Definition: Skill.cpp:497
armarx::skills::PeriodicSpecializedSkill::PeriodicSpecializedSkill
PeriodicSpecializedSkill()=delete
armarx::skills::PeriodicSkill::StepResult
Definition: PeriodicSkill.h:36