RandomChaining.cpp
Go to the documentation of this file.
1
2
#include "
RandomChaining.h
"
3
4
#include <chrono>
5
#include <cstdlib>
6
#include <thread>
7
8
namespace
armarx::skills::provider
9
{
10
namespace
util
11
{
12
int
13
randomgen
(
int
max
,
int
min
)
//Pass in range
14
{
15
srand(time(NULL));
//Changed from rand(). srand() seeds rand for you.
16
int
random = rand() %
max
+
min
;
17
return
random;
18
}
19
}
// namespace util
20
21
RandomChainingSkill::RandomChainingSkill
() :
SimpleSkill
(GetSkillDescription())
22
{
23
}
24
25
SkillDescription
26
RandomChainingSkill::GetSkillDescription
()
27
{
28
return
SkillDescription
{.
skillId
=
armarx::skills::SkillID
{.
skillName
=
"RandomChaining"
},
29
.description =
"This skill calls 100 random subskills from the "
30
"skillProviderExample excluding the segfault skill."
,
31
.rootProfileDefaults =
armarx::aron::make_dict
(),
32
.timeout =
armarx::core::time::Duration::MilliSeconds
(120000)};
33
}
34
35
Skill::MainResult
36
RandomChainingSkill::main
(
const
MainInput& in)
37
{
38
std::vector<std::string> subskillNames = {
"Timeout"
,
39
"Chaining"
,
40
"Foo"
,
41
"HelloWorld"
,
42
"Incomplete"
,
43
"ShowMeCallbacks"
,
44
"BusyWaiting"
,
45
"Recursive"
};
46
47
ARMARX_CHECK
(subskillNames.size() > 0);
48
49
for
(
unsigned
int
i = 0; i < 100; ++i)
50
{
51
this->
throwIfSkillShouldTerminate
();
52
53
auto
index
=
util::randomgen
(subskillNames.size() - 1, 0);
54
55
auto
subskillName = subskillNames[
index
];
56
57
SkillProxy
prx(
58
manager
,
59
skills::SkillID
{.
providerId
= *
getSkillId
().
providerId
, .skillName = subskillName});
60
61
if
(
util::randomgen
(10, 0) < 2)
62
{
63
callSubskill
(prx);
64
}
65
else
66
{
67
callSubskillAsync
(prx);
68
69
auto
sleep_milliseconds =
util::randomgen
(1000, 0);
70
71
ARMARX_INFO
<<
"SLEEP FOR "
<< sleep_milliseconds <<
"ms"
;
72
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_milliseconds));
73
}
74
}
75
76
return
{
TerminatedSkillStatus::Succeeded
,
nullptr
};
77
}
78
}
// namespace armarx::skills::provider
armarx::skills::provider::RandomChainingSkill::GetSkillDescription
static SkillDescription GetSkillDescription()
Definition:
RandomChaining.cpp:26
armarx::skills::Skill::manager
manager::dti::SkillManagerInterfacePrx manager
Definition:
Skill.h:291
armarx::skills::TerminatedSkillStatus::Succeeded
@ Succeeded
armarx::aron::make_dict
aron::data::DictPtr make_dict(_Args &&... args)
Definition:
Dict.h:107
index
uint8_t index
Definition:
EtherCATFrame.h:59
armarx::skills::SkillID::skillName
std::string skillName
Definition:
SkillID.h:41
armarx::skills::SkillDescription
Definition:
SkillDescription.h:17
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition:
VectorHelpers.h:297
armarx::skills::SkillID::providerId
std::optional< ProviderID > providerId
Definition:
SkillID.h:40
armarx::skills::Skill::callSubskillAsync
skills::SkillExecutionID callSubskillAsync(const skills::SkillProxy &proxy)
Similar to callSubskill but non-blocking.
Definition:
Skill.cpp:52
armarx::skills::Skill::callSubskill
std::optional< TerminatedSkillStatusUpdate > callSubskill(const skills::SkillProxy &proxy)
Call a subskill with default parameters and block until the subskill terminates.
Definition:
Skill.cpp:32
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition:
ExpressionException.h:82
armarx::skills::SkillProxy
Definition:
SkillProxy.h:13
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition:
SkillDescription.h:19
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::util::randomgen
int randomgen(int max, int min)
Definition:
RandomChaining.cpp:13
armarx::skills::SimpleSkill
Definition:
SimpleSkill.h:9
armarx::skills::SimpleSkill::main
MainResult main() final
Override this method with the actual implementation. The callback is for status updates to the callin...
Definition:
SimpleSkill.cpp:15
ARMARX_INFO
#define ARMARX_INFO
Definition:
Logging.h:181
RandomChaining.h
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition:
VectorHelpers.h:327
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition:
Skill.cpp:305
armarx::skills::provider::RandomChainingSkill::RandomChainingSkill
RandomChainingSkill()
Definition:
RandomChaining.cpp:21
armarx::skills::SkillID
Definition:
SkillID.h:14
armarx::skills::Skill::getSkillId
SkillID getSkillId() const
Get the id of the skill.
Definition:
Skill.cpp:497
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
RandomChaining.cpp
Generated on Sat Mar 29 2025 09:17:26 for armarx_documentation by
1.8.17