From e54d6881be1cea0196d7f18dd62ced83bd5fc76d Mon Sep 17 00:00:00 2001 From: Simon Ottenhaus <simon.ottenhaus@kit.edu> Date: Thu, 9 Mar 2017 12:01:45 +0100 Subject: [PATCH] added GamepadUnit --- scenarios/GamepadUnit/GamepadUnit.scx | 6 + .../GamepadUnit/config/GamepadUnitApp.cfg | 164 +++++++++++++++ .../config/GamepadUnitObserverApp.cfg | 196 ++++++++++++++++++ scenarios/GamepadUnit/config/global.cfg | 7 + source/RobotAPI/applications/CMakeLists.txt | 4 +- .../applications/GamepadUnit/CMakeLists.txt | 20 ++ .../applications/GamepadUnit/main.cpp | 32 +++ .../GamepadUnitObserver/CMakeLists.txt | 20 ++ .../applications/GamepadUnitObserver/main.cpp | 32 +++ .../RobotAPI/components/units/CMakeLists.txt | 2 + .../components/units/GamepadUnitObserver.cpp | 93 +++++++++ .../components/units/GamepadUnitObserver.h | 91 ++++++++ source/RobotAPI/drivers/CMakeLists.txt | 1 + .../drivers/GamepadUnit/CMakeLists.txt | 26 +++ .../drivers/GamepadUnit/GamepadUnit.cpp | 78 +++++++ .../drivers/GamepadUnit/GamepadUnit.h | 108 ++++++++++ .../drivers/GamepadUnit/test/CMakeLists.txt | 5 + .../GamepadUnit/test/GamepadUnitTest.cpp | 37 ++++ source/RobotAPI/interface/CMakeLists.txt | 1 + .../RobotAPI/interface/units/GamepadUnit.ice | 66 ++++++ 20 files changed, 988 insertions(+), 1 deletion(-) create mode 100644 scenarios/GamepadUnit/GamepadUnit.scx create mode 100644 scenarios/GamepadUnit/config/GamepadUnitApp.cfg create mode 100644 scenarios/GamepadUnit/config/GamepadUnitObserverApp.cfg create mode 100644 scenarios/GamepadUnit/config/global.cfg create mode 100644 source/RobotAPI/applications/GamepadUnit/CMakeLists.txt create mode 100644 source/RobotAPI/applications/GamepadUnit/main.cpp create mode 100644 source/RobotAPI/applications/GamepadUnitObserver/CMakeLists.txt create mode 100644 source/RobotAPI/applications/GamepadUnitObserver/main.cpp create mode 100644 source/RobotAPI/components/units/GamepadUnitObserver.cpp create mode 100644 source/RobotAPI/components/units/GamepadUnitObserver.h create mode 100644 source/RobotAPI/drivers/GamepadUnit/CMakeLists.txt create mode 100644 source/RobotAPI/drivers/GamepadUnit/GamepadUnit.cpp create mode 100644 source/RobotAPI/drivers/GamepadUnit/GamepadUnit.h create mode 100644 source/RobotAPI/drivers/GamepadUnit/test/CMakeLists.txt create mode 100644 source/RobotAPI/drivers/GamepadUnit/test/GamepadUnitTest.cpp create mode 100644 source/RobotAPI/interface/units/GamepadUnit.ice diff --git a/scenarios/GamepadUnit/GamepadUnit.scx b/scenarios/GamepadUnit/GamepadUnit.scx new file mode 100644 index 000000000..baf2e16f6 --- /dev/null +++ b/scenarios/GamepadUnit/GamepadUnit.scx @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<scenario name="GamepadUnit" lastChange="2017-03-09.11:59:19" creation="2017-03-09.11:59:13" globalConfigName="./config/global.cfg" package="RobotAPI"> + <application name="GamepadUnitApp" instance="" package="RobotAPI"/> + <application name="GamepadUnitObserverApp" instance="" package="RobotAPI"/> +</scenario> + diff --git a/scenarios/GamepadUnit/config/GamepadUnitApp.cfg b/scenarios/GamepadUnit/config/GamepadUnitApp.cfg new file mode 100644 index 000000000..b302f691a --- /dev/null +++ b/scenarios/GamepadUnit/config/GamepadUnitApp.cfg @@ -0,0 +1,164 @@ +# ================================================================== +# GamepadUnitApp 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: no +# - Required: no +# ArmarX.AdditionalPackages = Default value not mapped. + + +# ArmarX.ApplicationName: Application name +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.ApplicationName = "" + + +# ArmarX.CachePath: Path for cache files +# Attributes: +# - Default: ${HOME}/.armarx/mongo/.cache +# - Case sensitivity: no +# - Required: no +# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache + + +# ArmarX.Config: Comma-separated list of configuration files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.Config = "" + + +# ArmarX.DataPath: Semicolon-separated search list for data files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - 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: no +# - 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: no +# - Required: no +# ArmarX.DependenciesConfig = ./config/dependencies.cfg + + +# ArmarX.DisableLogging: Turn logging off in whole application +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.DisableLogging = 0 + + +# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.EnableProfiling = 0 + + +# ArmarX.GamepadUnit.EnableProfiling: enable profiler which is used for logging performance events +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnit.EnableProfiling = 0 + + +# ArmarX.GamepadUnit.GamepadTopicName: Name of the Gamepad Topic +# Attributes: +# - Default: GamepadValues +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnit.GamepadTopicName = GamepadValues + + +# ArmarX.GamepadUnit.MinimumLoggingLevel: Local logging level only for this component +# Attributes: +# - Default: Undefined +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnit.MinimumLoggingLevel = Undefined + + +# ArmarX.GamepadUnit.ObjectName: Name of IceGrid well-known object +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnit.ObjectName = "" + + +# ArmarX.RedirectStdout: Redirect std::cout and std::cerr to ArmarXLog +# Attributes: +# - Default: 1 +# - Case sensitivity: no +# - Required: no +# ArmarX.RedirectStdout = 1 + + +# 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: no +# - Required: no +# ArmarX.RemoteHandlesDeletionTimeout = 3000 + + +# ArmarX.StartDebuggerOnCrash: If this application crashes (segmentation fault) qtcreator will attach to this process and start the debugger. +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.StartDebuggerOnCrash = 0 + + +# 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: no +# - Required: no +# ArmarX.TopicSuffix = "" + + +# ArmarX.UseTimeServer: Enable using a global Timeserver (e.g. from ArmarXSimulator) +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.UseTimeServer = 0 + + +# ArmarX.Verbosity: Global logging level for whole application +# Attributes: +# - Default: Info +# - Case sensitivity: no +# - Required: no +# ArmarX.Verbosity = Info + + +# Ice.Config: Custom Property +# Attributes: +# - Default: ::NOT_DEFINED:: +# - Case sensitivity: no +# - Required: no +# Ice.Config = ::NOT_DEFINED:: + + diff --git a/scenarios/GamepadUnit/config/GamepadUnitObserverApp.cfg b/scenarios/GamepadUnit/config/GamepadUnitObserverApp.cfg new file mode 100644 index 000000000..9c0055a60 --- /dev/null +++ b/scenarios/GamepadUnit/config/GamepadUnitObserverApp.cfg @@ -0,0 +1,196 @@ +# ================================================================== +# GamepadUnitObserverApp 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: no +# - Required: no +# ArmarX.AdditionalPackages = Default value not mapped. + + +# ArmarX.ApplicationName: Application name +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.ApplicationName = "" + + +# ArmarX.CachePath: Path for cache files +# Attributes: +# - Default: ${HOME}/.armarx/mongo/.cache +# - Case sensitivity: no +# - Required: no +# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache + + +# ArmarX.Config: Comma-separated list of configuration files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.Config = "" + + +# ArmarX.DataPath: Semicolon-separated search list for data files +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - 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: no +# - 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: no +# - Required: no +# ArmarX.DependenciesConfig = ./config/dependencies.cfg + + +# ArmarX.DisableLogging: Turn logging off in whole application +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.DisableLogging = 0 + + +# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.EnableProfiling = 0 + + +# ArmarX.GamepadUnitObserver.CreateUpdateFrequenciesChannel: If true, an additional channel is created that shows the update frequency of every other channel in that observer. +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnitObserver.CreateUpdateFrequenciesChannel = 0 + + +# ArmarX.GamepadUnitObserver.DebugDrawerTopic: Name of the DebugDrawerTopic +# Attributes: +# - Default: DebugDrawerUpdates +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnitObserver.DebugDrawerTopic = DebugDrawerUpdates + + +# ArmarX.GamepadUnitObserver.EnableProfiling: enable profiler which is used for logging performance events +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnitObserver.EnableProfiling = 0 + + +# ArmarX.GamepadUnitObserver.GamepadTopicName: Name of the Gamepad Topic +# Attributes: +# - Default: GamepadValues +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnitObserver.GamepadTopicName = GamepadValues + + +# ArmarX.GamepadUnitObserver.MaxHistoryRecordFrequency: The Observer history is written with this maximum frequency. Everything faster is being skipped. +# Attributes: +# - Default: 50 +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnitObserver.MaxHistoryRecordFrequency = 50 + + +# ArmarX.GamepadUnitObserver.MaxHistorySize: Maximum number of entries in the Observer history +# Attributes: +# - Default: 5000 +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnitObserver.MaxHistorySize = 5000 + + +# ArmarX.GamepadUnitObserver.MinimumLoggingLevel: Local logging level only for this component +# Attributes: +# - Default: Undefined +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnitObserver.MinimumLoggingLevel = Undefined + + +# ArmarX.GamepadUnitObserver.ObjectName: Name of IceGrid well-known object +# Attributes: +# - Default: "" +# - Case sensitivity: no +# - Required: no +# ArmarX.GamepadUnitObserver.ObjectName = "" + + +# ArmarX.RedirectStdout: Redirect std::cout and std::cerr to ArmarXLog +# Attributes: +# - Default: 1 +# - Case sensitivity: no +# - Required: no +# ArmarX.RedirectStdout = 1 + + +# 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: no +# - Required: no +# ArmarX.RemoteHandlesDeletionTimeout = 3000 + + +# ArmarX.StartDebuggerOnCrash: If this application crashes (segmentation fault) qtcreator will attach to this process and start the debugger. +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.StartDebuggerOnCrash = 0 + + +# 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: no +# - Required: no +# ArmarX.TopicSuffix = "" + + +# ArmarX.UseTimeServer: Enable using a global Timeserver (e.g. from ArmarXSimulator) +# Attributes: +# - Default: 0 +# - Case sensitivity: no +# - Required: no +# ArmarX.UseTimeServer = 0 + + +# ArmarX.Verbosity: Global logging level for whole application +# Attributes: +# - Default: Info +# - Case sensitivity: no +# - Required: no +# ArmarX.Verbosity = Info + + +# Ice.Config: Custom Property +# Attributes: +# - Default: ::NOT_DEFINED:: +# - Case sensitivity: no +# - Required: no +# Ice.Config = ::NOT_DEFINED:: + + diff --git a/scenarios/GamepadUnit/config/global.cfg b/scenarios/GamepadUnit/config/global.cfg new file mode 100644 index 000000000..887b1b11a --- /dev/null +++ b/scenarios/GamepadUnit/config/global.cfg @@ -0,0 +1,7 @@ +# ================================================================== +# Global Config from Scenario GamepadUnit +# ================================================================== + + + + diff --git a/source/RobotAPI/applications/CMakeLists.txt b/source/RobotAPI/applications/CMakeLists.txt index b2d194d93..4bc3a6d5f 100644 --- a/source/RobotAPI/applications/CMakeLists.txt +++ b/source/RobotAPI/applications/CMakeLists.txt @@ -26,4 +26,6 @@ add_subdirectory(OrientedTactileSensorUnit) add_subdirectory(OrientedTactileSensorUnitObserver) add_subdirectory(OptoForceUnit) -add_subdirectory(OptoForceUnitObserver) \ No newline at end of file +add_subdirectory(OptoForceUnitObserver) +add_subdirectory(GamepadUnit) +add_subdirectory(GamepadUnitObserver) \ No newline at end of file diff --git a/source/RobotAPI/applications/GamepadUnit/CMakeLists.txt b/source/RobotAPI/applications/GamepadUnit/CMakeLists.txt new file mode 100644 index 000000000..872a8d4bf --- /dev/null +++ b/source/RobotAPI/applications/GamepadUnit/CMakeLists.txt @@ -0,0 +1,20 @@ +armarx_component_set_name("GamepadUnitApp") + +#find_package(MyLib QUIET) +#armarx_build_if(MyLib_FOUND "MyLib not available") +# +# all include_directories must be guarded by if(Xyz_FOUND) +# for multiple libraries write: if(X_FOUND AND Y_FOUND).... +#if(MyLib_FOUND) +# include_directories(${MyLib_INCLUDE_DIRS}) +#endif() + +set(COMPONENT_LIBS + ArmarXCoreInterfaces + ArmarXCore + GamepadUnit +) + +set(EXE_SOURCE main.cpp) + +armarx_add_component_executable("${EXE_SOURCE}") diff --git a/source/RobotAPI/applications/GamepadUnit/main.cpp b/source/RobotAPI/applications/GamepadUnit/main.cpp new file mode 100644 index 000000000..ec81535eb --- /dev/null +++ b/source/RobotAPI/applications/GamepadUnit/main.cpp @@ -0,0 +1,32 @@ +/* + * 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/>. + * + * @package RobotAPI::application::GamepadUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include <RobotAPI/drivers/GamepadUnit/GamepadUnit.h> + +#include <ArmarXCore/core/application/Application.h> +#include <ArmarXCore/core/Component.h> +#include <ArmarXCore/core/logging/Logging.h> + +int main(int argc, char* argv[]) +{ + return armarx::runSimpleComponentApp < armarx::GamepadUnit > (argc, argv, "GamepadUnit"); +} diff --git a/source/RobotAPI/applications/GamepadUnitObserver/CMakeLists.txt b/source/RobotAPI/applications/GamepadUnitObserver/CMakeLists.txt new file mode 100644 index 000000000..4054e9053 --- /dev/null +++ b/source/RobotAPI/applications/GamepadUnitObserver/CMakeLists.txt @@ -0,0 +1,20 @@ +armarx_component_set_name("GamepadUnitObserverApp") + +#find_package(MyLib QUIET) +#armarx_build_if(MyLib_FOUND "MyLib not available") +# +# all include_directories must be guarded by if(Xyz_FOUND) +# for multiple libraries write: if(X_FOUND AND Y_FOUND).... +#if(MyLib_FOUND) +# include_directories(${MyLib_INCLUDE_DIRS}) +#endif() + +set(COMPONENT_LIBS + ArmarXCoreInterfaces + ArmarXCore + RobotAPIUnits +) + +set(EXE_SOURCE main.cpp) + +armarx_add_component_executable("${EXE_SOURCE}") diff --git a/source/RobotAPI/applications/GamepadUnitObserver/main.cpp b/source/RobotAPI/applications/GamepadUnitObserver/main.cpp new file mode 100644 index 000000000..3cf8db15d --- /dev/null +++ b/source/RobotAPI/applications/GamepadUnitObserver/main.cpp @@ -0,0 +1,32 @@ +/* + * 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/>. + * + * @package RobotAPI::application::GamepadUnitObserver + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include <RobotAPI/components/units/GamepadUnitObserver.h> + +#include <ArmarXCore/core/application/Application.h> +#include <ArmarXCore/core/Component.h> +#include <ArmarXCore/core/logging/Logging.h> + +int main(int argc, char* argv[]) +{ + return armarx::runSimpleComponentApp < armarx::GamepadUnitObserver > (argc, argv, "GamepadUnitObserver"); +} diff --git a/source/RobotAPI/components/units/CMakeLists.txt b/source/RobotAPI/components/units/CMakeLists.txt index e3453b178..094894ff3 100644 --- a/source/RobotAPI/components/units/CMakeLists.txt +++ b/source/RobotAPI/components/units/CMakeLists.txt @@ -34,6 +34,7 @@ set(LIB_HEADERS InertialMeasurementUnitObserver.h OptoForceUnitObserver.h OrientedTactileSensorUnitObserver.h + GamepadUnitObserver.h TCPControlUnit.h TCPControlUnitObserver.h @@ -61,6 +62,7 @@ set(LIB_FILES InertialMeasurementUnitObserver.cpp OptoForceUnitObserver.cpp OrientedTactileSensorUnitObserver.cpp + GamepadUnitObserver.cpp TCPControlUnit.cpp TCPControlUnitObserver.cpp diff --git a/source/RobotAPI/components/units/GamepadUnitObserver.cpp b/source/RobotAPI/components/units/GamepadUnitObserver.cpp new file mode 100644 index 000000000..b22c0dbb5 --- /dev/null +++ b/source/RobotAPI/components/units/GamepadUnitObserver.cpp @@ -0,0 +1,93 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * 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/>. + * + * @package + * @author + * @date + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ +#include "GamepadUnitObserver.h" + + +#include <ArmarXCore/observers/checks/ConditionCheckEquals.h> +#include <ArmarXCore/observers/checks/ConditionCheckLarger.h> +#include <ArmarXCore/observers/checks/ConditionCheckSmaller.h> +#include <ArmarXCore/observers/checks/ConditionCheckUpdated.h> + +#include <RobotAPI/libraries/core/Pose.h> + +#include <ArmarXCore/observers/variant/TimestampVariant.h> + + + +using namespace armarx; + + +void GamepadUnitObserver::onInitObserver() +{ + usingTopic(getProperty<std::string>("GamepadTopicName").getValue()); + + offerConditionCheck("updated", new ConditionCheckUpdated()); + offerConditionCheck("larger", new ConditionCheckLarger()); + offerConditionCheck("equals", new ConditionCheckEquals()); + offerConditionCheck("smaller", new ConditionCheckSmaller()); + + offeringTopic(getProperty<std::string>("DebugDrawerTopic").getValue()); +} + + + +void GamepadUnitObserver::onConnectObserver() +{ + debugDrawerPrx = getTopic<DebugDrawerInterfacePrx>(getProperty<std::string>("DebugDrawerTopic").getValue()); +} + + +void GamepadUnitObserver::onExitObserver() +{ + debugDrawerPrx->removePoseVisu("IMU", "orientation"); + debugDrawerPrx->removeLineVisu("IMU", "acceleration"); +} + +void GamepadUnitObserver::reportAnalogSticks(const std::string& device, const std::string& name, const AnalogStickData& values, const TimestampBasePtr& timestamp, const Ice::Current& c) +{ + ScopedLock lock(dataMutex); + + TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp); + + if (!existsChannel(device)) + { + offerChannel(device, "Gamepad data"); + } + + offerOrUpdateDataField(device, "analog_x", Variant(values.x), "X value of the analog sticks"); + offerOrUpdateDataField(device, "analog_y", Variant(values.y), "Y value of the analog sticks"); + offerOrUpdateDataField(device, "analog_z", Variant(values.z), "Z value of the analog sticks"); + offerOrUpdateDataField(device, "analog_a", Variant(values.a), "A value of the analog sticks"); + + updateChannel(device); + +} + + +PropertyDefinitionsPtr GamepadUnitObserver::createPropertyDefinitions() +{ + return PropertyDefinitionsPtr(new GamepadUnitObserverPropertyDefinitions(getConfigIdentifier())); +} + + diff --git a/source/RobotAPI/components/units/GamepadUnitObserver.h b/source/RobotAPI/components/units/GamepadUnitObserver.h new file mode 100644 index 000000000..b246d1a78 --- /dev/null +++ b/source/RobotAPI/components/units/GamepadUnitObserver.h @@ -0,0 +1,91 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * 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/>. + * + * @package RobotAPI::units + * @author David Schiebener <schiebener at kit dot edu> + * @date 2014 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#ifndef _ARMARX_ROBOTAPI_GAMEPAD_OBSERVER_H +#define _ARMARX_ROBOTAPI_GAMEPAD_OBSERVER_H + +#include <RobotAPI/interface/units/GamepadUnit.h> +#include <ArmarXCore/observers/Observer.h> +#include <RobotAPI/interface/visualization/DebugDrawerInterface.h> +#include <RobotAPI/libraries/core/Pose.h> + + +namespace armarx +{ + /** + * \class GamepadUnitObserverPropertyDefinitions + * \brief + */ + class GamepadUnitObserverPropertyDefinitions: + public ObserverPropertyDefinitions + { + public: + GamepadUnitObserverPropertyDefinitions(std::string prefix): + ObserverPropertyDefinitions(prefix) + { + defineOptionalProperty<std::string>("GamepadTopicName", "GamepadValues", "Name of the Gamepad Topic"); + defineOptionalProperty<std::string>("DebugDrawerTopic", "DebugDrawerUpdates", "Name of the DebugDrawerTopic"); + } + }; + + + /** + * \class GamepadUnitObserver + * \ingroup RobotAPI-SensorActorUnits-observers + * \brief Observer monitoring @IMU sensor values + * + * The GamepadUnitObserver monitors @IMU sensor values published by GamepadUnit-implementations and offers condition checks on these values. + * Available condition checks are: *updated*, *larger*, *equals* and *smaller*. + */ + class GamepadUnitObserver : + virtual public Observer, + virtual public GamepadUnitObserverInterface + { + public: + GamepadUnitObserver() {} + + virtual std::string getDefaultName() const + { + return "GamepadUnitObserver"; + } + virtual void onInitObserver(); + virtual void onConnectObserver(); + virtual void onExitObserver(); + + void reportAnalogSticks(const std::string& device, const std::string& name, const AnalogStickData& values, const TimestampBasePtr& timestamp, const Ice::Current& c = ::Ice::Current()); + + /** + * @see PropertyUser::createPropertyDefinitions() + */ + virtual PropertyDefinitionsPtr createPropertyDefinitions(); + + + private: + Mutex dataMutex; + DebugDrawerInterfacePrx debugDrawerPrx; + + }; +} + +#endif diff --git a/source/RobotAPI/drivers/CMakeLists.txt b/source/RobotAPI/drivers/CMakeLists.txt index 8270167be..888f65874 100644 --- a/source/RobotAPI/drivers/CMakeLists.txt +++ b/source/RobotAPI/drivers/CMakeLists.txt @@ -2,4 +2,5 @@ add_subdirectory(WeissHapticSensor) add_subdirectory(XsensIMU) add_subdirectory(OptoForceUnit) add_subdirectory(OrientedTactileSensor) +add_subdirectory(GamepadUnit) diff --git a/source/RobotAPI/drivers/GamepadUnit/CMakeLists.txt b/source/RobotAPI/drivers/GamepadUnit/CMakeLists.txt new file mode 100644 index 000000000..6539aeb74 --- /dev/null +++ b/source/RobotAPI/drivers/GamepadUnit/CMakeLists.txt @@ -0,0 +1,26 @@ +armarx_component_set_name("GamepadUnit") + +#find_package(MyLib QUIET) +#armarx_build_if(MyLib_FOUND "MyLib not available") +# +# all include_directories must be guarded by if(Xyz_FOUND) +# for multiple libraries write: if(X_FOUND AND Y_FOUND).... +#if(MyLib_FOUND) +# include_directories(${MyLib_INCLUDE_DIRS}) +#endif() + +set(COMPONENT_LIBS ArmarXCoreInterfaces ArmarXCore ArmarXCoreEigen3Variants RobotAPIInterfaces) + +set(SOURCES +./GamepadUnit.cpp +#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.cpp +) +set(HEADERS +./GamepadUnit.h +#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.h +) + +armarx_add_component("${SOURCES}" "${HEADERS}") + +# add unit tests +add_subdirectory(test) diff --git a/source/RobotAPI/drivers/GamepadUnit/GamepadUnit.cpp b/source/RobotAPI/drivers/GamepadUnit/GamepadUnit.cpp new file mode 100644 index 000000000..98b2e0b11 --- /dev/null +++ b/source/RobotAPI/drivers/GamepadUnit/GamepadUnit.cpp @@ -0,0 +1,78 @@ +/* + * 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/>. + * + * @package RobotAPI::ArmarXObjects::GamepadUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "GamepadUnit.h" + +#include <ArmarXCore/observers/variant/TimestampVariant.h> + + +using namespace armarx; + + +void GamepadUnit::onInitComponent() +{ + offeringTopic(getProperty<std::string>("GamepadTopicName").getValue()); + readTask = new RunningTask<GamepadUnit>(this, &GamepadUnit::run, "GamepadUnit"); +} + + +void GamepadUnit::onConnectComponent() +{ + topicPrx = getTopic<GamepadUnitListenerPrx>(getProperty<std::string>("GamepadTopicName").getValue()); + readTask->start(); +} + +void GamepadUnit::run() +{ + while(readTask->isRunning()) + { + IceUtil::Time now = IceUtil::Time::now(); + TimestampVariantPtr nowTimestamp = new TimestampVariant(now); + AnalogStickData data; + data.x = std::cos(now.toSecondsDouble()); + data.y = std::sin(now.toSecondsDouble()); + data.z = 0; + data.a = 0; + topicPrx->reportAnalogSticks("DeviceNameHere", "NameHere", data, nowTimestamp); + + usleep(10000); // 10ms + } +} + + +void GamepadUnit::onDisconnectComponent() +{ + +} + + +void GamepadUnit::onExitComponent() +{ + +} + +armarx::PropertyDefinitionsPtr GamepadUnit::createPropertyDefinitions() +{ + return armarx::PropertyDefinitionsPtr(new GamepadUnitPropertyDefinitions( + getConfigIdentifier())); +} + diff --git a/source/RobotAPI/drivers/GamepadUnit/GamepadUnit.h b/source/RobotAPI/drivers/GamepadUnit/GamepadUnit.h new file mode 100644 index 000000000..caf8bde93 --- /dev/null +++ b/source/RobotAPI/drivers/GamepadUnit/GamepadUnit.h @@ -0,0 +1,108 @@ +/* + * 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/>. + * + * @package RobotAPI::ArmarXObjects::GamepadUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#ifndef _ARMARX_COMPONENT_RobotAPI_GamepadUnit_H +#define _ARMARX_COMPONENT_RobotAPI_GamepadUnit_H + + +#include <ArmarXCore/core/Component.h> + +#include <ArmarXCore/core/services/tasks/RunningTask.h> + +#include <RobotAPI/interface/units/GamepadUnit.h> + +namespace armarx +{ + /** + * @class GamepadUnitPropertyDefinitions + * @brief + */ + class GamepadUnitPropertyDefinitions: + public armarx::ComponentPropertyDefinitions + { + public: + GamepadUnitPropertyDefinitions(std::string prefix): + armarx::ComponentPropertyDefinitions(prefix) + { + //defineRequiredProperty<std::string>("PropertyName", "Description"); + //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description"); + defineOptionalProperty<std::string>("GamepadTopicName", "GamepadValues", "Name of the Gamepad Topic"); + } + }; + + /** + * @defgroup Component-GamepadUnit GamepadUnit + * @ingroup RobotAPI-Components + * A description of the component GamepadUnit. + * + * @class GamepadUnit + * @ingroup Component-GamepadUnit + * @brief Brief description of class GamepadUnit. + * + * Detailed description of class GamepadUnit. + */ + class GamepadUnit : + virtual public armarx::Component + { + public: + /** + * @see armarx::ManagedIceObject::getDefaultName() + */ + virtual std::string getDefaultName() const + { + return "GamepadUnit"; + } + + protected: + /** + * @see armarx::ManagedIceObject::onInitComponent() + */ + virtual void onInitComponent(); + + /** + * @see armarx::ManagedIceObject::onConnectComponent() + */ + virtual void onConnectComponent(); + + /** + * @see armarx::ManagedIceObject::onDisconnectComponent() + */ + virtual void onDisconnectComponent(); + + /** + * @see armarx::ManagedIceObject::onExitComponent() + */ + virtual void onExitComponent(); + + /** + * @see PropertyUser::createPropertyDefinitions() + */ + virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions(); + + private: + GamepadUnitListenerPrx topicPrx; + RunningTask<GamepadUnit>::pointer_type readTask; + void run(); + }; +} + +#endif diff --git a/source/RobotAPI/drivers/GamepadUnit/test/CMakeLists.txt b/source/RobotAPI/drivers/GamepadUnit/test/CMakeLists.txt new file mode 100644 index 000000000..239bfad99 --- /dev/null +++ b/source/RobotAPI/drivers/GamepadUnit/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore GamepadUnit) + +armarx_add_test(GamepadUnitTest GamepadUnitTest.cpp "${LIBS}") \ No newline at end of file diff --git a/source/RobotAPI/drivers/GamepadUnit/test/GamepadUnitTest.cpp b/source/RobotAPI/drivers/GamepadUnit/test/GamepadUnitTest.cpp new file mode 100644 index 000000000..488590d87 --- /dev/null +++ b/source/RobotAPI/drivers/GamepadUnit/test/GamepadUnitTest.cpp @@ -0,0 +1,37 @@ +/* + * 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/>. + * + * @package RobotAPI::ArmarXObjects::GamepadUnit + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2017 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::GamepadUnit + +#define ARMARX_BOOST_TEST + +#include <RobotAPI/Test.h> +#include <RobotAPI/drivers/GamepadUnit/GamepadUnit.h> + +#include <iostream> + +BOOST_AUTO_TEST_CASE(testExample) +{ + armarx::GamepadUnit instance; + + BOOST_CHECK_EQUAL(true, true); +} diff --git a/source/RobotAPI/interface/CMakeLists.txt b/source/RobotAPI/interface/CMakeLists.txt index cc2ef9836..568707d1c 100644 --- a/source/RobotAPI/interface/CMakeLists.txt +++ b/source/RobotAPI/interface/CMakeLists.txt @@ -36,6 +36,7 @@ set(SLICE_FILES units/UnitInterface.ice units/ATINetFTUnit.ice units/OrientedTactileSensorUnit.ice + units/GamepadUnit.ice components/ViewSelectionInterface.ice diff --git a/source/RobotAPI/interface/units/GamepadUnit.ice b/source/RobotAPI/interface/units/GamepadUnit.ice new file mode 100644 index 000000000..c55199511 --- /dev/null +++ b/source/RobotAPI/interface/units/GamepadUnit.ice @@ -0,0 +1,66 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * 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/>. + * + * @package RobotAPI + * @author Markus Grotz <markus dot grotz at kit dot edu> + * @date 2015 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#ifndef _ARMARX_ROBOTAPI_UNITS_GAMEPAD_SLICE_ +#define _ARMARX_ROBOTAPI_UNITS_GAMEPAD_SLICE_ + + +#include <RobotAPI/interface/units/UnitInterface.ice> +#include <RobotAPI/interface/core/RobotState.ice> + +#include <ArmarXCore/interface/core/UserException.ice> +#include <ArmarXCore/interface/core/BasicTypes.ice> +#include <ArmarXCore/interface/observers/VariantBase.ice> +#include <ArmarXCore/interface/observers/Matrix.ice> +#include <ArmarXCore/interface/observers/Timestamp.ice> +#include <ArmarXCore/interface/observers/ObserverInterface.ice> + + + +module armarx +{ + struct AnalogStickData { + float x; + float y; + float z; + float a; + }; + interface GamepadUnitInterface extends armarx::SensorActorUnitInterface + { + }; + + interface GamepadUnitListener + { + void reportAnalogSticks(string device, string name, AnalogStickData values, TimestampBase timestamp); + }; + /** + * Implements an interface to an GamepadUnitObserver. + **/ + interface GamepadUnitObserverInterface extends ObserverInterface, GamepadUnitListener + { + }; + +}; + +#endif -- GitLab