From 8a16b1f88fc140c84af11fb74fb1cd22c788a44a Mon Sep 17 00:00:00 2001
From: Simon Ottenhaus <simon.ottenhaus@kit.edu>
Date: Fri, 10 Mar 2017 11:32:39 +0100
Subject: [PATCH] added GamepadControlUnit

---
 .../GamepadControlUnit/GamepadControlUnit.scx |   5 +
 .../config/GamepadControlUnitApp.cfg          | 172 ++++++++++++++++++
 .../GamepadControlUnit/config/global.cfg      |   7 +
 source/RobotAPI/applications/CMakeLists.txt   |   3 +-
 .../GamepadControlUnit/CMakeLists.txt         |  20 ++
 .../applications/GamepadControlUnit/main.cpp  |  32 ++++
 source/RobotAPI/components/CMakeLists.txt     |   2 +
 .../GamepadControlUnit/CMakeLists.txt         |  26 +++
 .../GamepadControlUnit/GamepadControlUnit.cpp |  62 +++++++
 .../GamepadControlUnit/GamepadControlUnit.h   | 110 +++++++++++
 .../GamepadControlUnit/test/CMakeLists.txt    |   5 +
 .../test/GamepadControlUnitTest.cpp           |  37 ++++
 12 files changed, 480 insertions(+), 1 deletion(-)
 create mode 100644 scenarios/GamepadControlUnit/GamepadControlUnit.scx
 create mode 100644 scenarios/GamepadControlUnit/config/GamepadControlUnitApp.cfg
 create mode 100644 scenarios/GamepadControlUnit/config/global.cfg
 create mode 100644 source/RobotAPI/applications/GamepadControlUnit/CMakeLists.txt
 create mode 100644 source/RobotAPI/applications/GamepadControlUnit/main.cpp
 create mode 100644 source/RobotAPI/components/GamepadControlUnit/CMakeLists.txt
 create mode 100644 source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.cpp
 create mode 100644 source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h
 create mode 100644 source/RobotAPI/components/GamepadControlUnit/test/CMakeLists.txt
 create mode 100644 source/RobotAPI/components/GamepadControlUnit/test/GamepadControlUnitTest.cpp

diff --git a/scenarios/GamepadControlUnit/GamepadControlUnit.scx b/scenarios/GamepadControlUnit/GamepadControlUnit.scx
new file mode 100644
index 000000000..65fb5e957
--- /dev/null
+++ b/scenarios/GamepadControlUnit/GamepadControlUnit.scx
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<scenario name="GamepadControlUnit" lastChange="2017-03-10.11:31:35" creation="2017-03-10.11:31:30" globalConfigName="./config/global.cfg" package="RobotAPI">
+	<application name="GamepadControlUnitApp" instance="" package="RobotAPI"/>
+</scenario>
+
diff --git a/scenarios/GamepadControlUnit/config/GamepadControlUnitApp.cfg b/scenarios/GamepadControlUnit/config/GamepadControlUnitApp.cfg
new file mode 100644
index 000000000..3b8084595
--- /dev/null
+++ b/scenarios/GamepadControlUnit/config/GamepadControlUnitApp.cfg
@@ -0,0 +1,172 @@
+# ==================================================================
+# GamepadControlUnitApp 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.GamepadControlUnit.EnableProfiling:  enable profiler which is used for logging performance events
+#  Attributes:
+#  - Default:            0
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.GamepadControlUnit.EnableProfiling = 0
+
+
+# ArmarX.GamepadControlUnit.GamepadTopicName:  Name of the Gamepad Topic
+#  Attributes:
+#  - Default:            GamepadValues
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.GamepadControlUnit.GamepadTopicName = GamepadValues
+
+
+# ArmarX.GamepadControlUnit.MinimumLoggingLevel:  Local logging level only for this component
+#  Attributes:
+#  - Default:            Undefined
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.GamepadControlUnit.MinimumLoggingLevel = Undefined
+
+
+# ArmarX.GamepadControlUnit.ObjectName:  Name of IceGrid well-known object
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.GamepadControlUnit.ObjectName = ""
+
+
+# ArmarX.GamepadControlUnit.PlatformUnitName:  Name of the platform unit to use
+#  Attributes:
+#  - Default:            Armar6IcePlatformUnit
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.GamepadControlUnit.PlatformUnitName = Armar6IcePlatformUnit
+
+
+# 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/GamepadControlUnit/config/global.cfg b/scenarios/GamepadControlUnit/config/global.cfg
new file mode 100644
index 000000000..63a93840d
--- /dev/null
+++ b/scenarios/GamepadControlUnit/config/global.cfg
@@ -0,0 +1,7 @@
+# ==================================================================
+# Global Config from Scenario GamepadControlUnit
+# ==================================================================
+
+
+
+
diff --git a/source/RobotAPI/applications/CMakeLists.txt b/source/RobotAPI/applications/CMakeLists.txt
index 4bc3a6d5f..057bcd82f 100644
--- a/source/RobotAPI/applications/CMakeLists.txt
+++ b/source/RobotAPI/applications/CMakeLists.txt
@@ -28,4 +28,5 @@ add_subdirectory(OrientedTactileSensorUnitObserver)
 add_subdirectory(OptoForceUnit)
 add_subdirectory(OptoForceUnitObserver)
 add_subdirectory(GamepadUnit)
-add_subdirectory(GamepadUnitObserver)
\ No newline at end of file
+add_subdirectory(GamepadUnitObserver)
+add_subdirectory(GamepadControlUnit)
\ No newline at end of file
diff --git a/source/RobotAPI/applications/GamepadControlUnit/CMakeLists.txt b/source/RobotAPI/applications/GamepadControlUnit/CMakeLists.txt
new file mode 100644
index 000000000..350d81c8d
--- /dev/null
+++ b/source/RobotAPI/applications/GamepadControlUnit/CMakeLists.txt
@@ -0,0 +1,20 @@
+armarx_component_set_name("GamepadControlUnitApp")
+
+#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
+    GamepadControlUnit
+)
+
+set(EXE_SOURCE main.cpp)
+
+armarx_add_component_executable("${EXE_SOURCE}")
diff --git a/source/RobotAPI/applications/GamepadControlUnit/main.cpp b/source/RobotAPI/applications/GamepadControlUnit/main.cpp
new file mode 100644
index 000000000..a2c5a7e42
--- /dev/null
+++ b/source/RobotAPI/applications/GamepadControlUnit/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::GamepadControlUnit
+ * @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/GamepadControlUnit/GamepadControlUnit.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::GamepadControlUnit > (argc, argv, "GamepadControlUnit");
+}
diff --git a/source/RobotAPI/components/CMakeLists.txt b/source/RobotAPI/components/CMakeLists.txt
index 09e360143..34d207212 100644
--- a/source/RobotAPI/components/CMakeLists.txt
+++ b/source/RobotAPI/components/CMakeLists.txt
@@ -4,3 +4,5 @@ add_subdirectory(RobotState)
 add_subdirectory(EarlyVisionGraph)
 add_subdirectory(ViewSelection)
 
+
+add_subdirectory(GamepadControlUnit)
\ No newline at end of file
diff --git a/source/RobotAPI/components/GamepadControlUnit/CMakeLists.txt b/source/RobotAPI/components/GamepadControlUnit/CMakeLists.txt
new file mode 100644
index 000000000..146c18bf6
--- /dev/null
+++ b/source/RobotAPI/components/GamepadControlUnit/CMakeLists.txt
@@ -0,0 +1,26 @@
+armarx_component_set_name("GamepadControlUnit")
+
+#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 RobotAPIInterfaces)
+
+set(SOURCES
+./GamepadControlUnit.cpp
+#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.cpp
+)
+set(HEADERS
+./GamepadControlUnit.h
+#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.h
+)
+
+armarx_add_component("${SOURCES}" "${HEADERS}")
+
+# add unit tests
+add_subdirectory(test)
diff --git a/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.cpp b/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.cpp
new file mode 100644
index 000000000..0ef985b5d
--- /dev/null
+++ b/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.cpp
@@ -0,0 +1,62 @@
+/*
+ * 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::GamepadControlUnit
+ * @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 "GamepadControlUnit.h"
+
+
+using namespace armarx;
+
+
+void GamepadControlUnit::onInitComponent()
+{
+    usingProxy(getProperty<std::string>("PlatformUnitName").getValue());
+}
+
+
+void GamepadControlUnit::onConnectComponent()
+{
+    platformUnitPrx = getTopic<PlatformUnitInterfacePrx>(getProperty<std::string>("PlatformUnitName").getValue());
+}
+
+
+void GamepadControlUnit::onDisconnectComponent()
+{
+
+}
+
+
+void GamepadControlUnit::onExitComponent()
+{
+
+}
+
+armarx::PropertyDefinitionsPtr GamepadControlUnit::createPropertyDefinitions()
+{
+    return armarx::PropertyDefinitionsPtr(new GamepadControlUnitPropertyDefinitions(
+                                              getConfigIdentifier()));
+}
+
+void GamepadControlUnit::reportGamepadState(const std::string& device, const std::string& name, const GamepadData& data, const TimestampBasePtr& timestamp, const Ice::Current& c)
+{
+    platformUnitPrx->move(data.leftStickX, data.leftStickY, data.rightStickX);
+}
+
diff --git a/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h b/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h
new file mode 100644
index 000000000..61f40e572
--- /dev/null
+++ b/source/RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h
@@ -0,0 +1,110 @@
+/*
+ * 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::GamepadControlUnit
+ * @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_GamepadControlUnit_H
+#define _ARMARX_COMPONENT_RobotAPI_GamepadControlUnit_H
+
+
+#include <ArmarXCore/core/Component.h>
+
+#include <RobotAPI/interface/units/GamepadUnit.h>
+
+namespace armarx
+{
+    /**
+     * @class GamepadControlUnitPropertyDefinitions
+     * @brief
+     */
+    class GamepadControlUnitPropertyDefinitions:
+        public armarx::ComponentPropertyDefinitions
+    {
+    public:
+        GamepadControlUnitPropertyDefinitions(std::string prefix):
+            armarx::ComponentPropertyDefinitions(prefix)
+        {
+            //defineRequiredProperty<std::string>("PropertyName", "Description");
+            //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
+            defineOptionalProperty<std::string>("PlatformUnitName", "Armar6IcePlatformUnit", "Name of the platform unit to use");
+            defineOptionalProperty<std::string>("GamepadTopicName", "GamepadValues", "Name of the Gamepad Topic");
+        }
+    };
+
+    /**
+     * @defgroup Component-GamepadControlUnit GamepadControlUnit
+     * @ingroup RobotAPI-Components
+     * A description of the component GamepadControlUnit.
+     * 
+     * @class GamepadControlUnit
+     * @ingroup Component-GamepadControlUnit
+     * @brief Brief description of class GamepadControlUnit.
+     * 
+     * Detailed description of class GamepadControlUnit.
+     */
+    class GamepadControlUnit :
+        virtual public armarx::Component,
+        virtual public GamepadUnitListener
+    {
+    public:
+        /**
+         * @see armarx::ManagedIceObject::getDefaultName()
+         */
+        virtual std::string getDefaultName() const
+        {
+            return "GamepadControlUnit";
+        }
+
+    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:
+        PlatformUnitInterfacePrx platformUnitPrx;
+
+    public:
+        void reportGamepadState(const std::string& device, const std::string& name, const GamepadData& data, const TimestampBasePtr& timestamp, const Ice::Current& c);
+
+    };
+}
+
+#endif
diff --git a/source/RobotAPI/components/GamepadControlUnit/test/CMakeLists.txt b/source/RobotAPI/components/GamepadControlUnit/test/CMakeLists.txt
new file mode 100644
index 000000000..c79f86b6a
--- /dev/null
+++ b/source/RobotAPI/components/GamepadControlUnit/test/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+# Libs required for the tests
+SET(LIBS ${LIBS} ArmarXCore GamepadControlUnit)
+ 
+armarx_add_test(GamepadControlUnitTest GamepadControlUnitTest.cpp "${LIBS}")
\ No newline at end of file
diff --git a/source/RobotAPI/components/GamepadControlUnit/test/GamepadControlUnitTest.cpp b/source/RobotAPI/components/GamepadControlUnit/test/GamepadControlUnitTest.cpp
new file mode 100644
index 000000000..c5a6caa4e
--- /dev/null
+++ b/source/RobotAPI/components/GamepadControlUnit/test/GamepadControlUnitTest.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::GamepadControlUnit
+ * @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::GamepadControlUnit
+
+#define ARMARX_BOOST_TEST
+
+#include <RobotAPI/Test.h>
+#include <RobotAPI/components/GamepadControlUnit/GamepadControlUnit.h>
+
+#include <iostream>
+
+BOOST_AUTO_TEST_CASE(testExample)
+{
+    armarx::GamepadControlUnit instance;
+
+    BOOST_CHECK_EQUAL(true, true);
+}
-- 
GitLab