Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sw/armarx/robot-api
  • uwkce_singer/robot-api
  • untcg_hofmann/robot-api
  • ulqba_korosakov/RobotAPI
4 results
Show changes
Commits on Source (90)
Showing
with 982 additions and 2 deletions
<?xml version="1.0" encoding="utf-8"?>
<scenario name="FamiliarObjectDetectionExample" creation="1970-01-01.01:00:00" globalConfigName="./config/global.cfg" package="RobotAPI" nodeName="NodeMain">
<application name="FamiliarObjectDetectionExample" instance="" package="RobotAPI" nodeName="" enabled="true"/>
</scenario>
# ==================================================================
# FamiliarObjectDetectionExample properties
# ==================================================================
# ArmarX.AdditionalPackages: List of additional ArmarX packages which should be in the list of default packages. If you have custom packages, which should be found by the gui or other apps, specify them here. Comma separated List.
# Attributes:
# - Default: Default value not mapped.
# - Case sensitivity: yes
# - Required: no
# ArmarX.AdditionalPackages = Default value not mapped.
# ArmarX.ApplicationName: Application name
# Attributes:
# - Default: ""
# - Case sensitivity: yes
# - Required: no
# ArmarX.ApplicationName = ""
# ArmarX.AutodiscoverPackages: If enabled, will discover all ArmarX packages based on the environment variables. Otherwise, the `DefaultPackages` and `AdditionalPackages` properties are used.
# Attributes:
# - Default: true
# - Case sensitivity: yes
# - Required: no
# - Possible values: {0, 1, false, no, true, yes}
# ArmarX.AutodiscoverPackages = true
# ArmarX.CachePath: Path for cache files. If relative path AND env. variable ARMARX_CONFIG_DIR is set, the cache path will be made relative to ARMARX_CONFIG_DIR. Otherwise if relative it will be relative to the default ArmarX config dir (${ARMARX_WORKSPACE}/armarx_config)
# Attributes:
# - Default: mongo/.cache
# - Case sensitivity: yes
# - Required: no
# ArmarX.CachePath = mongo/.cache
# ArmarX.Config: Comma-separated list of configuration files
# Attributes:
# - Default: ""
# - Case sensitivity: yes
# - Required: no
# ArmarX.Config = ""
# ArmarX.DataPath: Semicolon-separated search list for data files
# Attributes:
# - Default: ""
# - Case sensitivity: yes
# - Required: no
# ArmarX.DataPath = ""
# ArmarX.DefaultPackages: List of ArmarX packages which are accessible by default. Comma separated List. If you want to add your own packages and use all default ArmarX packages, use the property 'AdditionalPackages'.
# Attributes:
# - Default: Default value not mapped.
# - Case sensitivity: yes
# - Required: no
# ArmarX.DefaultPackages = Default value not mapped.
# ArmarX.DependenciesConfig: Path to the (usually generated) config file containing all data paths of all dependent projects. This property usually does not need to be edited.
# Attributes:
# - Default: ./config/dependencies.cfg
# - Case sensitivity: yes
# - Required: no
# ArmarX.DependenciesConfig = ./config/dependencies.cfg
# ArmarX.DisableLogging: Turn logging off in whole application
# Attributes:
# - Default: false
# - Case sensitivity: yes
# - Required: no
# - Possible values: {0, 1, false, no, true, yes}
# ArmarX.DisableLogging = false
# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application
# Attributes:
# - Default: false
# - Case sensitivity: yes
# - Required: no
# - Possible values: {0, 1, false, no, true, yes}
# ArmarX.EnableProfiling = false
# ArmarX.FamiliarObjectDetectionExample.EnableProfiling: enable profiler which is used for logging performance events
# Attributes:
# - Default: false
# - Case sensitivity: yes
# - Required: no
# - Possible values: {0, 1, false, no, true, yes}
# ArmarX.FamiliarObjectDetectionExample.EnableProfiling = false
# ArmarX.FamiliarObjectDetectionExample.MinimumLoggingLevel: Local logging level only for this component
# Attributes:
# - Default: Undefined
# - Case sensitivity: yes
# - Required: no
# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning}
# ArmarX.FamiliarObjectDetectionExample.MinimumLoggingLevel = Undefined
# ArmarX.FamiliarObjectDetectionExample.ObjectName: Name of IceGrid well-known object
# Attributes:
# - Default: ""
# - Case sensitivity: yes
# - Required: no
# ArmarX.FamiliarObjectDetectionExample.ObjectName = ""
# ArmarX.FamiliarObjectDetectionExample.cmp.FamiliarObjectPoseStorage: Ice object name of the `FamiliarObjectPoseStorage` component.
# Attributes:
# - Default: ObjectMemory
# - Case sensitivity: yes
# - Required: no
# ArmarX.FamiliarObjectDetectionExample.cmp.FamiliarObjectPoseStorage = ObjectMemory
# ArmarX.FamiliarObjectDetectionExample.mns.MemoryNameSystemEnabled: Whether to use (and depend on) the Memory Name System (MNS).
# Set to false to use this memory as a stand-alone.
# Attributes:
# - Default: true
# - Case sensitivity: yes
# - Required: no
# - Possible values: {0, 1, false, no, true, yes}
# ArmarX.FamiliarObjectDetectionExample.mns.MemoryNameSystemEnabled = true
# ArmarX.FamiliarObjectDetectionExample.mns.MemoryNameSystemName: Name of the Memory Name System (MNS) component.
# Attributes:
# - Default: MemoryNameSystem
# - Case sensitivity: yes
# - Required: no
# ArmarX.FamiliarObjectDetectionExample.mns.MemoryNameSystemName = MemoryNameSystem
# ArmarX.FamiliarObjectDetectionExample.p.robotName:
# Attributes:
# - Case sensitivity: yes
# - Required: yes
ArmarX.FamiliarObjectDetectionExample.p.robotName = ArmarDE
# ArmarX.LoadLibraries: Libraries to load at start up of the application. Must be enabled by the Application with enableLibLoading(). Format: PackageName:LibraryName;... or /absolute/path/to/library;...
# Attributes:
# - Default: ""
# - Case sensitivity: yes
# - Required: no
# ArmarX.LoadLibraries = ""
# ArmarX.LoggingGroup: The logging group is transmitted with every ArmarX log message over Ice in order to group the message in the GUI.
# Attributes:
# - Default: ""
# - Case sensitivity: yes
# - Required: no
# ArmarX.LoggingGroup = ""
# ArmarX.RedirectStdout: Redirect std::cout and std::cerr to ArmarXLog
# Attributes:
# - Default: true
# - Case sensitivity: yes
# - Required: no
# - Possible values: {0, 1, false, no, true, yes}
# ArmarX.RedirectStdout = true
# ArmarX.RemoteHandlesDeletionTimeout: The timeout (in ms) before a remote handle deletes the managed object after the use count reached 0. This time can be used by a client to increment the count again (may be required when transmitting remote handles)
# Attributes:
# - Default: 3000
# - Case sensitivity: yes
# - Required: no
# ArmarX.RemoteHandlesDeletionTimeout = 3000
# ArmarX.SecondsStartupDelay: The startup will be delayed by this number of seconds (useful for debugging)
# Attributes:
# - Default: 0
# - Case sensitivity: yes
# - Required: no
# ArmarX.SecondsStartupDelay = 0
# ArmarX.StartDebuggerOnCrash: If this application crashes (segmentation fault) qtcreator will attach to this process and start the debugger.
# Attributes:
# - Default: false
# - Case sensitivity: yes
# - Required: no
# - Possible values: {0, 1, false, no, true, yes}
# ArmarX.StartDebuggerOnCrash = false
# ArmarX.ThreadPoolSize: Size of the ArmarX ThreadPool that is always running.
# Attributes:
# - Default: 1
# - Case sensitivity: yes
# - Required: no
# ArmarX.ThreadPoolSize = 1
# ArmarX.TopicSuffix: Suffix appended to all topic names for outgoing topics. This is mainly used to direct all topics to another name for TopicReplaying purposes.
# Attributes:
# - Default: ""
# - Case sensitivity: yes
# - Required: no
# ArmarX.TopicSuffix = ""
# ArmarX.UseTimeServer: Enable using a global Timeserver (e.g. from ArmarXSimulator)
# Attributes:
# - Default: false
# - Case sensitivity: yes
# - Required: no
# - Possible values: {0, 1, false, no, true, yes}
# ArmarX.UseTimeServer = false
# ArmarX.Verbosity: Global logging level for whole application
# Attributes:
# - Default: Info
# - Case sensitivity: yes
# - Required: no
# - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning}
# ArmarX.Verbosity = Info
# ==================================================================
# Global Config from Scenario FamiliarObjectDetectionExample
# ==================================================================
......@@ -5,6 +5,7 @@ add_subdirectory(skills)
add_subdirectory(AronComponentConfigExample)
add_subdirectory(ArticulatedObjectLocalizerExample)
add_subdirectory(FamiliarObjectDetectionExample)
add_subdirectory(ArViz)
add_subdirectory(CyberGloveObserver)
......
set(LIB_NAME FamiliarObjectDetectionExample)
armarx_component_set_name("${LIB_NAME}")
armarx_set_target("Library: ${LIB_NAME}")
find_package(OpenCV QUIET)
armarx_build_if(OpenCV_FOUND "OpenCV not available")
# Add the component
armarx_add_component(
COMPONENT_LIBS
ArmarXCore
armem_objects
RobotAPIArmarXObjects
SOURCES
FamiliarObjectDetectionExample.cpp
HEADERS
FamiliarObjectDetectionExample.h
)
# Generate the application
armarx_generate_and_add_component_executable(
# If your component is not defined in ::armarx, specify its namespace here:
COMPONENT_NAMESPACE "armarx::familiar_objects"
)
/*
* 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 Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2024
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "FamiliarObjectDetectionExample.h"
#include <Eigen/Geometry>
#include <pcl/point_types.h>
#include <opencv2/core/mat.hpp>
#include <IceUtil/Time.h>
#include <SimoxUtility/math/pose/pose.h>
#include <VirtualRobot/Robot.h>
#include <VirtualRobot/VirtualRobot.h>
#include <VirtualRobot/XML/RobotIO.h>
#include "ArmarXCore/core/time/Clock.h"
#include <ArmarXCore/core/PackagePath.h>
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <ArmarXCore/core/services/tasks/PeriodicTask.h>
#include <ArmarXCore/core/time/CycleUtil.h>
#include "RobotAPI/libraries/ArmarXObjects/ObjectID.h"
#include <RobotAPI/libraries/armem/core/Time.h>
#include <RobotAPI/libraries/armem_objects/aron/FamiliarObjectInstance.aron.generated.h>
#include <RobotAPI/libraries/armem_objects/types.h>
// #include <RobotAPI/libraries/armem_objects/aron_conversions.h>
// #include <RobotAPI/libraries/armem/core/aron_conversions.h>
#include <RobotAPI/libraries/ArmarXObjects/aron_conversions.h>
namespace armarx::familiar_objects
{
FamiliarObjectDetectionExample::FamiliarObjectDetectionExample()
{
addPlugin(familiarObjectInstanceReaderPlugin);
}
armarx::PropertyDefinitionsPtr
FamiliarObjectDetectionExample::createPropertyDefinitions()
{
armarx::PropertyDefinitionsPtr defs =
new ComponentPropertyDefinitions(getConfigIdentifier());
defs->required(p.robotName, "p.robotName");
defs->component(familiarObjectPoseStoragePrx, "ObjectMemory");
return defs;
}
std::string
FamiliarObjectDetectionExample::getDefaultName() const
{
return "FamiliarObjectDetectionExample";
}
void
FamiliarObjectDetectionExample::onInitComponent()
{
exemplaryFamiliarObjectID.dataset = "myDataset";
exemplaryFamiliarObjectID.className = "sphere";
exemplaryFamiliarObjectID.instanceName = "0";
}
void
FamiliarObjectDetectionExample::onConnectComponent()
{
//
// First, we create a familiar object and send it to the memory.
//
ARMARX_IMPORTANT << "Storing exemplary familiar object in memory";
storeExemplaryFamiliarObjectInMemory();
//
// Then, we read the familiar object from the memory.
//
ARMARX_IMPORTANT << "Reading familiar object from memory";
readExemplaryFamiliarObjectFromMemory();
}
void
FamiliarObjectDetectionExample::storeExemplaryFamiliarObjectInMemory() const
{
::armarx::objpose::ProvidedFamiliarObjectPoseSeq data;
armem::arondto::FamiliarObjectInstance familiarObject;
familiarObject.timestamp = armarx::Clock::Now();
familiarObject.poseSensFrame.pose =
Eigen::Isometry3f{Eigen::Translation3f{0, 0, 1000}}.matrix();
familiarObject.poseSensFrame.header.frame = "DepthCameraSim";
familiarObject.poseSensFrame.header.agent = p.robotName;
// familiarObject.poseSensFrame.header.frame = "AzureKinect_RGB";
familiarObject.objectID = exemplaryFamiliarObjectID;
familiarObject.confidence = 1.0;
// familiarObject.bounding_box =
// familiarObject.depth_image_patch = cv::Mat1f(cv::Size(20, 20));
// familiarObject.rgb_image_patch = cv::Mat3b(cv::Size(20, 20));
const int numPoints = 100;
// x in red
for (int i = 0; i < numPoints; i++)
{
pcl::PointXYZRGBA point;
point.x = static_cast<float>(i) - numPoints / 2;
point.y = 0;
point.z = 0;
point.r = 255;
point.g = 0;
point.b = 0;
familiarObject.points.points.push_back(point);
}
// y in green
for (int i = 0; i < numPoints; i++)
{
pcl::PointXYZRGBA point;
point.x = 0;
point.y = static_cast<float>(i) - numPoints / 2;
point.z = 0;
point.r = 0;
point.g = 255;
point.b = 0;
familiarObject.points.points.push_back(point);
}
// z in blue
for (int i = 0; i < numPoints; i++)
{
pcl::PointXYZRGBA point;
point.y = 0;
point.y = 0;
point.z = static_cast<float>(i) - numPoints / 2;
point.r = 0;
point.g = 0;
point.b = 255;
familiarObject.points.points.push_back(point);
}
familiarObject.points.header.frame_id = "DepthCameraSim";
familiarObject.points.is_dense = true;
familiarObject.points.width = familiarObject.points.points.size();
familiarObject.points.height = 1;
familiarObject.bounding_box.center.setZero();
familiarObject.bounding_box.extents.setConstant(numPoints);
data.push_back(familiarObject.toAronDTO());
ARMARX_INFO << "Sending " << data.size() << " familiar object to the memory";
familiarObjectPoseStoragePrx->reportFamiliarObjectPoses(getName(), data);
}
void
FamiliarObjectDetectionExample::readExemplaryFamiliarObjectFromMemory() const
{
ARMARX_CHECK_NOT_NULL(familiarObjectInstanceReaderPlugin);
const armem::obj::familiar_object_instance::Reader& familiarObjectInstanceReader =
familiarObjectInstanceReaderPlugin->get();
//
// 1. Read from all providers
//
ARMARX_IMPORTANT << "Reading from all providers";
{
const auto allFamiliarObjectInstances =
familiarObjectInstanceReader.queryAllLatestFamiliarObjectInstances();
// print
for (const auto& [providerName, instances] : allFamiliarObjectInstances)
{
ARMARX_INFO << "Provider name: " << providerName;
for (const auto& instance : instances)
{
ARMARX_INFO << "- Instance: " << instance.objectID.dataset << "/"
<< instance.objectID.className << "/"
<< instance.objectID.instanceName;
}
}
}
//
// 2. Read from a specific provider
//
ARMARX_IMPORTANT << "Reading from a specific provider";
{
const std::map<std::string, std::vector<armem::arondto::FamiliarObjectInstance>>
familiarObjectInstances =
familiarObjectInstanceReader.queryAllLatestFamiliarObjectInstances(getName());
ARMARX_INFO << "Provider name: " << getName();
ARMARX_CHECK_EQUAL(familiarObjectInstances.size(), 1);
ARMARX_CHECK_EQUAL(familiarObjectInstances.begin()->first, getName());
const auto& thisFamiliarObjectInstances = familiarObjectInstances.begin()->second;
// print
for (const auto& instance : thisFamiliarObjectInstances)
{
ARMARX_INFO << "- Instance: " << instance.objectID.dataset << "/"
<< instance.objectID.className << "/" << instance.objectID.instanceName;
}
}
//
// 3. Read all instances of a specific class
//
ARMARX_IMPORTANT << "Reading all instances of a specific class";
{
armarx::ObjectID objectId;
fromAron(exemplaryFamiliarObjectID, objectId);
const auto instances =
familiarObjectInstanceReader.queryLatestFamiliarObjectInstancesFromClass(
objectId.getClassID());
for (const auto& [instanceName, instancesForProvider] : instances)
{
for (const auto& instance : instancesForProvider)
{
ARMARX_INFO << "- Instance: " << instance.objectID.dataset << "/"
<< instance.objectID.className << "/"
<< instance.objectID.instanceName;
}
}
}
//
// 4. Read a specific instance
//
ARMARX_IMPORTANT << "Reading a specific instance";
{
armarx::ObjectID objectId;
fromAron(exemplaryFamiliarObjectID, objectId);
const std::optional<std::map<std::string, armem::arondto::FamiliarObjectInstance>>
instances =
familiarObjectInstanceReader.queryLatestFamiliarObjectInstance(objectId);
ARMARX_CHECK(instances.has_value());
for (const auto& [instanceName, instance] : instances.value())
{
ARMARX_INFO << "- Instance: " << instance.objectID.dataset << "/"
<< instance.objectID.className << "/" << instance.objectID.instanceName;
}
}
}
void
FamiliarObjectDetectionExample::onDisconnectComponent()
{
// task->stop();
}
void
FamiliarObjectDetectionExample::onExitComponent()
{
}
} // namespace armarx::familiar_objects
#pragma once
#include <experimental/memory>
#include <VirtualRobot/VirtualRobot.h>
#include <ArmarXCore/core/Component.h>
#include <ArmarXCore/core/services/tasks/PeriodicTask.h>
#include <ArmarXCore/interface/observers/ObserverInterface.h>
#include <ArmarXCore/util/tasks.h>
#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h>
#include "RobotAPI/libraries/armem/client/plugins/ReaderWriterPlugin.h"
#include "RobotAPI/libraries/armem_objects/client/familiar_object_instance/ObjectReader.h"
#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h>
#include <RobotAPI/interface/armem/server/MemoryInterface.h>
#include <RobotAPI/interface/objectpose/FamiliarObjectPoseStorageInterface.h>
#include <RobotAPI/libraries/armem/client/plugins.h>
#include <RobotAPI/libraries/armem/core/Time.h>
#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h>
#include <RobotAPI/libraries/armem_objects/client/articulated_object/ArticulatedObjectReader.h>
#include <RobotAPI/libraries/armem_objects/client/articulated_object/ArticulatedObjectWriter.h>
namespace armarx::familiar_objects
{
/**
* @defgroup Component-ExampleClient ExampleClient
* @ingroup RobotAPI-Components
* A description of the component ExampleClient.
*
* @class ExampleClient
* @ingroup Component-ExampleClient
* @brief Brief description of class ExampleClient.
*
* Detailed description of class ExampleClient.
*/
class FamiliarObjectDetectionExample :
virtual public armarx::Component,
virtual public armarx::armem::client::ComponentPluginUser
{
public:
FamiliarObjectDetectionExample();
/// @see armarx::ManagedIceObject::getDefaultName()
std::string getDefaultName() const override;
protected:
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override;
void onInitComponent() override;
void onConnectComponent() override;
void onDisconnectComponent() override;
void onExitComponent() override;
void run();
void storeExemplaryFamiliarObjectInMemory() const;
void readExemplaryFamiliarObjectFromMemory() const;
private:
struct Properties
{
std::string robotName;
} p;
// Writing familiar object instances to memory
objpose::FamiliarObjectPoseStorageInterfacePrx familiarObjectPoseStoragePrx;
// Reading familiar object instances from memory
std::experimental::observer_ptr<armem::client::plugins::ReaderWriterPlugin<
armarx::armem::obj::familiar_object_instance::Reader>>
familiarObjectInstanceReaderPlugin;
armarx::arondto::ObjectID exemplaryFamiliarObjectID;
};
} // namespace armarx::familiar_objects
......@@ -24,6 +24,7 @@
#include <VirtualRobot/VirtualRobot.h>
#include "ArmarXCore/core/time/Clock.h"
#include <ArmarXCore/core/ManagedIceObject.h>
#include <ArmarXCore/core/ice_conversions/ice_conversions_templates.h>
#include <ArmarXCore/core/time/ice_conversions.h>
......@@ -48,6 +49,7 @@ namespace armarx::armem::server::obj
classSegment.defineProperties(defs, prefix + "cls.");
instance::SegmentAdapter::defineProperties(defs, prefix + "inst.");
familiar_object_instance::SegmentAdapter::defineProperties(defs, prefix + "fam_obj_inst.");
attachmentSegment.defineProperties(defs, prefix + "attachments.");
......@@ -75,6 +77,7 @@ namespace armarx::armem::server::obj
ObjectMemory::ObjectMemory() :
instance::SegmentAdapter(iceAdapter()),
familiar_object_instance::SegmentAdapter(iceAdapter()),
classSegment(iceAdapter()),
attachmentSegment(iceAdapter()), virtualRobotReaderPlugin(nullptr)
{
......@@ -123,6 +126,7 @@ namespace armarx::armem::server::obj
});
instance::SegmentAdapter::init();
familiar_object_instance::SegmentAdapter::init();
initSegmentWithCatch("attachment", [&]()
{
......@@ -155,6 +159,13 @@ namespace armarx::armem::server::obj
ArVizComponentPluginUser::getArvizClient(),
debugObserver
);
familiar_object_instance::SegmentAdapter::connect(
std::experimental::make_observer(&virtualRobotReaderPlugin->get()),
ArVizComponentPluginUser::getArvizClient(),
debugObserver
);
classSegment.connect(
ArVizComponentPluginUser::getArvizClient()
);
......
......@@ -26,6 +26,7 @@
#include <RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotReader.h>
#include <RobotAPI/libraries/armem_objects/server/class/Segment.h>
#include <RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.h>
#include <RobotAPI/libraries/armem_objects/server/familiar_object_instance/SegmentAdapter.h>
#include <RobotAPI/libraries/armem_objects/server/attachments/Segment.h>
#include <RobotAPI/libraries/armem/server/plugins/ReadWritePluginUser.h>
......@@ -63,6 +64,7 @@ namespace armarx::armem::server::obj
, virtual public armarx::armem::server::ObjectMemoryInterface
, virtual public armarx::armem::server::ReadWritePluginUser
, virtual public armarx::armem::server::obj::instance::SegmentAdapter
, virtual public armarx::armem::server::obj::familiar_object_instance::SegmentAdapter
, virtual public armarx::LightweightRemoteGuiComponentPluginUser
, virtual public armarx::ArVizComponentPluginUser
{
......
......@@ -188,6 +188,7 @@ namespace armarx::armem::server::robot_state
startRobotUnitStream();
}
}
void
......
#include "BusyWaiting.h"
#include <chrono>
#include <thread>
namespace armarx::skills::provider
{
BusyWaitingSkill::BusyWaitingSkill() : SimpleSkill(GetSkillDescription())
{
}
SkillDescription
BusyWaitingSkill::GetSkillDescription()
{
return SkillDescription{.skillId = SkillID{.skillName = "BusyWaiting"},
.description = "This skill takes two seconds",
.timeout = armarx::core::time::Duration::MilliSeconds(10000)};
}
Skill::MainResult
BusyWaitingSkill::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 BusyWaitingSkill : public SimpleSkill
{
public:
BusyWaitingSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main(const MainInput&) final;
};
} // namespace armarx::skills::provider
......@@ -19,6 +19,10 @@ set(SOURCES
Callback.cpp
Timeout.cpp
Segfault.cpp
RandomChaining.cpp
InstantKill.cpp
BusyWaiting.cpp
Recursive.cpp
)
set(HEADERS
......@@ -29,6 +33,10 @@ set(HEADERS
Callback.h
Timeout.h
Segfault.h
RandomChaining.h
InstantKill.h
BusyWaiting.h
Recursive.h
)
armarx_add_component("${SOURCES}" "${HEADERS}")
......@@ -38,6 +46,7 @@ armarx_enable_aron_file_generation_for_target(
${ARMARX_COMPONENT_NAME}
ARON_FILES
aron/HelloWorldAcceptedType.xml
aron/RecursiveSkillParams.xml
)
#generate the application
......
......@@ -12,7 +12,7 @@ namespace armarx::skills::provider
SkillDescription
ChainingSkill::GetSkillDescription()
{
return SkillDescription{.skillId = armarx::skills::SkillID{.skillName = "ChainingSkill"},
return SkillDescription{.skillId = armarx::skills::SkillID{.skillName = "Chaining"},
.description =
"This skill calls the Timeout skill three times. The last "
"execution is aborted due to a timeout of this skill.",
......
......@@ -17,7 +17,7 @@ namespace armarx::skills::provider
IncompleteSkill::GetSkillDescription()
{
auto d = HelloWorldSkill::GetSkillDescription();
return SkillDescription{.skillId = {.skillName = "IncompleteSkill"},
return SkillDescription{.skillId = {.skillName = "Incomplete"},
.description = d.description,
.timeout = d.timeout + armarx::core::time::Duration::Seconds(2),
.parametersType = d.parametersType};
......
#include <cstdlib>
#include "InstantKill.h"
#include <thread>
#include <chrono>
namespace armarx::skills::provider
{
InstantKillSkill::InstantKillSkill() : SimpleSkill(GetSkillDescription())
{
}
SkillDescription
InstantKillSkill::GetSkillDescription()
{
return SkillDescription{.skillId = armarx::skills::SkillID{.skillName = "InstantKill"},
.description =
"This skill calls Timeout and instantly aboirts it.",
.timeout = armarx::core::time::Duration::MilliSeconds(50000)};
}
Skill::MainResult
InstantKillSkill::main(const MainInput& in)
{
this->throwIfSkillShouldTerminate();
SkillProxy prx(
manager,
skills::SkillID{.providerId = *getSkillId().providerId, .skillName = "Chaining"});
for (unsigned int i = 0; i < 10; ++i)
{
auto id = callSubskillAsync(prx);
prx.abortSkillAsync(id);
}
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 Fabian Ternava ( fabian dot ternava 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 InstantKillSkill : public SimpleSkill
{
public:
InstantKillSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main(const MainInput&) final;
};
} // namespace armarx::skills::provider
#include <cstdlib>
#include "RandomChaining.h"
#include <thread>
#include <chrono>
namespace armarx::skills::provider
{
namespace util
{
int randomgen(int max, int min) //Pass in range
{
srand(time(NULL)); //Changed from rand(). srand() seeds rand for you.
int random = rand() % max + min;
return random;
}
}
RandomChainingSkill::RandomChainingSkill() : SimpleSkill(GetSkillDescription())
{
}
SkillDescription
RandomChainingSkill::GetSkillDescription()
{
return SkillDescription{.skillId = armarx::skills::SkillID{.skillName = "RandomChaining"},
.description =
"This skill calls 100 random subskills from the skillProviderExample excluding the segfault skill.",
.timeout = armarx::core::time::Duration::MilliSeconds(120000)};
}
Skill::MainResult
RandomChainingSkill::main(const MainInput& in)
{
std::vector<std::string> subskillNames = {
"Timeout", "Chaining", "Foo", "HelloWorld",
"Incomplete", "ShowMeCallbacks", "BusyWaiting", "Recursive"
};
ARMARX_CHECK(subskillNames.size() > 0);
for (unsigned int i = 0; i < 100; ++i)
{
this->throwIfSkillShouldTerminate();
auto index = util::randomgen(subskillNames.size() -1, 0);
auto subskillName = subskillNames[index];
SkillProxy prx(
manager,
skills::SkillID{.providerId = *getSkillId().providerId, .skillName = subskillName});
if (util::randomgen(10, 0) < 2)
{
callSubskill(prx);
}
else
{
callSubskillAsync(prx);
auto sleep_milliseconds = util::randomgen(1000, 0);
ARMARX_INFO << "SLEEP FOR " << sleep_milliseconds << "ms";
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_milliseconds));
}
}
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 Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @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 RandomChainingSkill : public SimpleSkill
{
public:
RandomChainingSkill();
static SkillDescription GetSkillDescription();
private:
Skill::MainResult main(const MainInput&) final;
};
} // namespace armarx::skills::provider
#include "Recursive.h"
#include "RobotAPI/libraries/skills/core/SkillDescription.h"
namespace armarx::skills::provider
{
RecursiveSkill::RecursiveSkill() : SimpleSpecializedSkill<skills::Example::RecursiveSkillParams>(GetSkillDescription())
{
}
SkillDescription
RecursiveSkill::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
RecursiveSkill::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