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