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 
28 
29 #include "PeriodicSkill.h"
30 #include "SpecializedSkill.h"
31 
32 namespace armarx::skills
33 {
34  template <class AronT>
36  {
37  public:
39 
40  using Skill::description;
41  using Skill::getSkillId;
42 
44 
45  PeriodicSpecializedSkill() = delete;
46 
47  PeriodicSpecializedSkill(const SkillDescription& skillDescription,
49  Base(skillDescription), frequency(frequency)
50  {
51  }
52 
53  protected:
54  /// Do not use anymore
56  main() final
57  {
59 
60  while (true)
61  {
63 
64  const auto res = step();
65  switch (res.status)
66  {
68  // nothing to do here. break switch
69  break;
71  return Skill::MakeAbortedResult();
73  return Skill::MakeSucceededResult(res.data);
75  return Skill::MakeFailedResult();
76  }
77 
78  const auto sleepDuration = metronome.waitForNextTick();
79  if (not sleepDuration.isPositive())
80  {
81  ARMARX_INFO << deactivateSpam() << __PRETTY_FUNCTION__
82  << ": execution took too long (" << -sleepDuration
83  << " too long. Expected " << frequency.toCycleDuration() << ")";
84  }
85  }
86 
87  throw skills::error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
88  }
89 
90  /// Override this method with your own step function
91  virtual StepResult
92  step()
93  {
94  ARMARX_IMPORTANT << "Dummy executing once skill '" << this->description.skillName
95  << "'. Please overwrite this method!";
97  }
98 
99  protected:
101  };
102 
103 } // namespace armarx::skills
armarx::skills::PeriodicSpecializedSkill::StepResult
PeriodicSkill::StepResult StepResult
Definition: PeriodicSpecializedSkill.h:43
armarx::skills::SpecializedSkill
Definition: SpecializedSkill.h:14
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::skills::PeriodicSpecializedSkill::step
virtual StepResult step()
Override this method with your own step function.
Definition: PeriodicSpecializedSkill.h:92
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:18
Frequency.h
armarx::skills::PeriodicSpecializedSkill::frequency
const armarx::Frequency frequency
Definition: PeriodicSpecializedSkill.h:100
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:17
armarx::skills::PeriodicSpecializedSkill::PeriodicSpecializedSkill
PeriodicSpecializedSkill(const SkillDescription &skillDescription, const armarx::Frequency &frequency)
Definition: PeriodicSpecializedSkill.h:47
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition: Skill.cpp:314
armarx::core::time::Frequency::toCycleDuration
Duration toCycleDuration() const
Definition: Frequency.cpp:67
armarx::skills::PeriodicSpecializedSkill
Definition: PeriodicSpecializedSkill.h:35
Skill.h
armarx::skills::Skill::description
SkillDescription description
Definition: Skill.h:336
armarx::skills::ActiveOrTerminatedSkillStatus::Aborted
@ Aborted
Metronome.h
armarx::skills::error::SkillException
A base class for skill exceptions.
Definition: Exception.h:40
armarx::skills::Skill::MakeAbortedResult
static MainResult MakeAbortedResult()
Definition: Skill.cpp:323
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition: Skill.cpp:305
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_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::PeriodicSpecializedSkill::main
Skill::MainResult main() final
Do not use anymore.
Definition: PeriodicSpecializedSkill.h:56
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:92
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition: Skill.cpp:281
PeriodicSkill.h
armarx::skills::Skill::getSkillId
SkillID getSkillId() const
Get the id of the skill.
Definition: Skill.h:74
armarx::skills::PeriodicSpecializedSkill::PeriodicSpecializedSkill
PeriodicSpecializedSkill()=delete
armarx::skills::PeriodicSkill::StepResult
Definition: PeriodicSkill.h:36