Skip to content
Snippets Groups Projects
Commit b9ce4f14 authored by Andre Meixner's avatar Andre Meixner :camera:
Browse files

Added BusyWaiting and Recursive Skill example

parent 05b84416
No related branches found
No related tags found
2 merge requests!475Improvement of Skill Memory and Skill Memory GUI,!474Draft: Improvement of Skill Memory and Skill Memory GUI
Pipeline #20895 passed
Showing
with 189 additions and 1 deletion
#include "BusyWaiting.h"
#include <chrono>
#include <thread>
namespace armarx::skills::provider
{
BusyWaiting::BusyWaiting() : SimpleSkill(GetSkillDescription())
{
}
SkillDescription
BusyWaiting::GetSkillDescription()
{
return SkillDescription{.skillId = SkillID{.skillName = "BusyWaiting"},
.description = "This skill takes two seconds",
.timeout = armarx::core::time::Duration::MilliSeconds(10000)};
}
Skill::MainResult
BusyWaiting::main(const MainInput& in)
{
for (unsigned int i = 0; i < 10; i++)
{
throwIfSkillShouldTerminate();
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
return {TerminatedSkillStatus::Succeeded, nullptr};
}
} // namespace armarx::skills::provider
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Andre Meixner ( andre dot meixner at kit dot edu )
* @date 2024
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
// RobotAPI
#include <RobotAPI/libraries/skills/provider/SimpleSkill.h>
namespace armarx::skills::provider
{
class BusyWaiting : public SimpleSkill
{
public:
BusyWaiting();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main(const MainInput&) final;
};
} // namespace armarx::skills::provider
......@@ -21,6 +21,8 @@ set(SOURCES
Segfault.cpp
RandomChaining.cpp
InstantKill.cpp
BusyWaiting.cpp
Recursive.cpp
)
set(HEADERS
......@@ -33,6 +35,8 @@ set(HEADERS
Segfault.h
RandomChaining.h
InstantKill.h
BusyWaiting.h
Recursive.h
)
armarx_add_component("${SOURCES}" "${HEADERS}")
......@@ -42,6 +46,7 @@ armarx_enable_aron_file_generation_for_target(
${ARMARX_COMPONENT_NAME}
ARON_FILES
aron/HelloWorldAcceptedType.xml
aron/RecursiveSkillParams.xml
)
#generate the application
......
......@@ -33,7 +33,7 @@ namespace armarx::skills::provider
Skill::MainResult
RandomChainingSkill::main(const MainInput& in)
{
std::vector<std::string> subskillNames = {"Timeout", "ChainingSkill", "Foo", "HelloWorld", "IncompleteSkill", "ShowMeCallbacks"};
std::vector<std::string> subskillNames = {"Timeout", "ChainingSkill", "Foo", "HelloWorld", "IncompleteSkill", "ShowMeCallbacks", "BusyWaiting", "Recursive"};
ARMARX_CHECK(subskillNames.size() > 0);
......
#include "Recursive.h"
#include "RobotAPI/libraries/skills/core/SkillDescription.h"
namespace armarx::skills::provider
{
Recursive::Recursive() : SimpleSpecializedSkill<skills::Example::RecursiveSkillParams>(GetSkillDescription())
{
}
SkillDescription
Recursive::GetSkillDescription()
{
armarx::skills::Example::RecursiveSkillParams root_profile_params;
root_profile_params.n = 10;
return SkillDescription{.skillId = skills::SkillID{.skillName = "Recursive"},
.description = "This skill calls itself recursively {n} times",
.rootProfileDefaults = root_profile_params.toAron(),
.timeout = armarx::core::time::Duration::MilliSeconds(10000),
.parametersType =
armarx::skills::Example::RecursiveSkillParams::ToAronType(),
.resultType = armarx::skills::Example::RecursiveSkillParams::ToAronType()};
}
Skill::MainResult
Recursive::main(const SpecializedMainInput& in)
{
const int n = in.parameters.n;
if (n > 0)
{
SkillProxy prx(manager,
skills::SkillID{.providerId = *getSkillId().providerId, .skillName = "Recursive"});
armarx::skills::Example::RecursiveSkillParams params;
params.n = n - 1;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
callSubskill(prx, params.toAron());
}
throwIfSkillShouldTerminate();
return {TerminatedSkillStatus::Succeeded, nullptr};
}
} // namespace armarx::skills::provider
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Andre Meixner ( andre dot meixner at kit dot edu )
* @date 2024
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
// RobotAPI
#include <RobotAPI/libraries/skills/provider/SimpleSpecializedSkill.h>
#include <RobotAPI/components/skills/SkillProviderExample/aron/RecursiveSkillParams.aron.generated.h>
namespace armarx::skills::provider
{
class Recursive : public SimpleSpecializedSkill<skills::Example::RecursiveSkillParams>
{
public:
Recursive();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main(const SpecializedMainInput&) final;
};
} // namespace armarx::skills::provider
......@@ -69,6 +69,12 @@ namespace armarx::skills::provider
// insta kill
ARMARX_INFO << "Adding skill InstaKill";
addSkillFactory<InstantKillSkill>();
ARMARX_INFO << "Adding skill BusyWaiting";
addSkillFactory<BusyWaiting>();
ARMARX_INFO << "Adding skill Recursive";
addSkillFactory<Recursive>();
}
void
......
......@@ -37,6 +37,8 @@
#include "Timeout.h"
#include "RandomChaining.h"
#include "InstantKill.h"
#include "BusyWaiting.h"
#include "Recursive.h"
namespace armarx::skills::provider
{
......
<?xml version="1.0" encoding="UTF-8" ?>
<AronTypeDefinition>
<GenerateTypes>
<Object name='armarx::skills::Example::RecursiveSkillParams'>
<ObjectChild key='n'>
<int32 />
</ObjectChild>
</Object>
</GenerateTypes>
</AronTypeDefinition>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment