Sleep.cpp
Go to the documentation of this file.
1
#include "
Sleep.h
"
2
3
#include <chrono>
4
#include <thread>
5
6
#include <
ArmarXCore/core/time/DateTime.h
>
7
8
namespace
armarx::skills::provider
9
{
10
Sleep::Sleep
() :
11
SimpleSpecializedSkill
<
skills
::Example::SleepAcceptedType>(GetSkillDescription())
12
{
13
}
14
15
SkillDescription
16
Sleep::GetSkillDescription
()
17
{
18
armarx::skills::Example::SleepAcceptedType root_profile_params;
19
root_profile_params.Timeout_ms = 5000;
20
21
return
SkillDescription
{
22
.
skillId
=
skills::SkillID
{.
skillName
=
"Sleep"
},
23
.description =
24
"This skill exits after the provided time (or five minutes, whichever is lower)."
,
25
.rootProfileDefaults = root_profile_params.toAron(),
26
.timeout =
armarx::core::time::Duration::Minutes
(5),
27
.parametersType =
28
armarx::skills::Example::SleepAcceptedType::SleepAcceptedType::ToAronType()};
29
}
30
31
void
32
Sleep::onStopRequested
()
33
{
34
aborted =
true
;
35
}
36
37
Skill::MainResult
38
Sleep::main
(
const
SpecializedMainInput& in)
39
{
40
timeout =
armarx::Duration::MilliSeconds
(in.parameters.Timeout_ms);
41
auto
start =
armarx::DateTime::Now
();
42
for
(;;)
// forever
43
{
44
if
(aborted)
45
{
46
ARMARX_INFO
<<
"Skill has been woken up by abort."
;
47
return
Skill::MakeAbortedResult
();
48
}
49
50
// check if the time is over
51
auto
now =
armarx::DateTime::Now
();
52
auto
diff = now - start;
53
if
(diff >= timeout)
54
{
55
ARMARX_INFO
<<
"Skill has woken up by timeout."
;
56
return
Skill::MakeSucceededResult
();
57
}
58
else
59
{
60
std::this_thread::sleep_for(std::chrono::milliseconds(100));
61
}
62
}
63
64
return
{
TerminatedSkillStatus::Succeeded
, in.parameters.toAron()};
65
}
66
67
68
}
// namespace armarx::skills::provider
Sleep.h
armarx::skills::TerminatedSkillStatus::Succeeded
@ Succeeded
skills
This file is part of ArmarX.
armarx::skills::SkillID::skillName
std::string skillName
Definition:
SkillID.h:41
armarx::skills::SkillDescription
Definition:
SkillDescription.h:17
armarx::core::time::DateTime::Now
static DateTime Now()
Definition:
DateTime.cpp:51
DateTime.h
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition:
SkillDescription.h:19
armarx::skills::SimpleSpecializedSkill
Definition:
SimpleSpecializedSkill.h:10
armarx::skills::provider::Sleep::onStopRequested
void onStopRequested() override
Definition:
Sleep.cpp:32
armarx::skills::Skill::MakeAbortedResult
static MainResult MakeAbortedResult()
Definition:
Skill.cpp:347
armarx::core::time::Duration::Minutes
static Duration Minutes(std::int64_t minutes)
Constructs a duration in minutes.
Definition:
Duration.cpp:96
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition:
Skill.cpp:329
armarx::skills::provider
Definition:
BusyWaiting.cpp:6
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition:
Skill.h:39
armarx::skills::provider::Sleep::Sleep
Sleep()
Definition:
Sleep.cpp:10
ARMARX_INFO
#define ARMARX_INFO
Definition:
Logging.h:181
armarx::skills::SimpleSpecializedSkill< armarx::skills::Example::SleepAcceptedType >::main
Skill::MainResult main() final
Definition:
SimpleSpecializedSkill.h:71
armarx::skills::provider::Sleep::GetSkillDescription
static SkillDescription GetSkillDescription()
Definition:
Sleep.cpp:16
armarx::skills::SkillID
Definition:
SkillID.h:14
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition:
Duration.cpp:48
RobotAPI
components
skills
SkillProviderExample
Sleep.cpp
Generated on Sat Mar 29 2025 09:17:26 for armarx_documentation by
1.8.17