From 432f3230b769f1f9aa281f8b81e3d5d5334d7f77 Mon Sep 17 00:00:00 2001
From: Nikolaus Vahrenkamp <vahrenkamp@kit.edu>
Date: Mon, 24 Oct 2016 18:15:35 +0200
Subject: [PATCH] started interface for RobotControlUnit

---
 source/RobotAPI/components/CMakeLists.txt     |   2 +
 .../RobotControlUnit/CMakeLists.txt           |  26 ++++
 .../RobotControlUnit/RobotControlUnit.cpp     |  83 +++++++++++++
 .../RobotControlUnit/RobotControlUnit.h       | 116 ++++++++++++++++++
 .../RobotControlUnit/test/CMakeLists.txt      |   5 +
 .../test/RobotControlUnitTest.cpp             |  37 ++++++
 source/RobotAPI/interface/CMakeLists.txt      |   3 +
 .../control/RobotControlUnitInterface.ice     |  47 +++++++
 .../control/RobotControllerInterface.ice      |  62 ++++++++++
 9 files changed, 381 insertions(+)
 create mode 100644 source/RobotAPI/components/RobotControlUnit/CMakeLists.txt
 create mode 100644 source/RobotAPI/components/RobotControlUnit/RobotControlUnit.cpp
 create mode 100644 source/RobotAPI/components/RobotControlUnit/RobotControlUnit.h
 create mode 100644 source/RobotAPI/components/RobotControlUnit/test/CMakeLists.txt
 create mode 100644 source/RobotAPI/components/RobotControlUnit/test/RobotControlUnitTest.cpp
 create mode 100644 source/RobotAPI/interface/control/RobotControlUnitInterface.ice
 create mode 100644 source/RobotAPI/interface/control/RobotControllerInterface.ice

diff --git a/source/RobotAPI/components/CMakeLists.txt b/source/RobotAPI/components/CMakeLists.txt
index bf391c4c6..3b782791d 100644
--- a/source/RobotAPI/components/CMakeLists.txt
+++ b/source/RobotAPI/components/CMakeLists.txt
@@ -3,3 +3,5 @@ add_subdirectory(DebugDrawer)
 add_subdirectory(RobotState)
 add_subdirectory(EarlyVisionGraph)
 add_subdirectory(ViewSelection)
+
+add_subdirectory(RobotControlUnit)
\ No newline at end of file
diff --git a/source/RobotAPI/components/RobotControlUnit/CMakeLists.txt b/source/RobotAPI/components/RobotControlUnit/CMakeLists.txt
new file mode 100644
index 000000000..f892e9a9c
--- /dev/null
+++ b/source/RobotAPI/components/RobotControlUnit/CMakeLists.txt
@@ -0,0 +1,26 @@
+armarx_component_set_name("RobotControlUnit")
+
+#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
+./RobotControlUnit.cpp
+#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.cpp
+)
+set(HEADERS
+./RobotControlUnit.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/RobotControlUnit/RobotControlUnit.cpp b/source/RobotAPI/components/RobotControlUnit/RobotControlUnit.cpp
new file mode 100644
index 000000000..49d7fa4ed
--- /dev/null
+++ b/source/RobotAPI/components/RobotControlUnit/RobotControlUnit.cpp
@@ -0,0 +1,83 @@
+/*
+ * 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::RobotControlUnit
+ * @author     Nikolaus Vahrenkamp ( vahrenkamp at kit dot edu )
+ * @date       2016
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+
+#include "RobotControlUnit.h"
+
+
+using namespace armarx;
+
+
+void RobotControlUnit::wakeUpControllers()
+{
+    // Wakes up the control loop
+}
+
+void RobotControlUnit::onInitComponent()
+{
+    // Create all controllers using the configuration
+
+}
+
+
+void RobotControlUnit::onConnectComponent()
+{
+    // Register them to ICE"
+
+    // Create a periodic task which executes "executControllers()"
+}
+
+
+void RobotControlUnit::onDisconnectComponent()
+{
+
+}
+
+
+void RobotControlUnit::onExitComponent()
+{
+
+}
+
+void RobotControlUnit::executeControllers()
+{
+    // Execute all controllers
+    //  Order: Priorities
+}
+
+armarx::PropertyDefinitionsPtr RobotControlUnit::createPropertyDefinitions()
+{
+    return armarx::PropertyDefinitionsPtr(new RobotControlUnitPropertyDefinitions(
+                                              getConfigIdentifier()));
+}
+
+StringRobotControllerInterfacePrxMap RobotControlUnit::getAvailableControllers(const Ice::Current &)
+{
+    StringRobotControllerInterfacePrxMap result;
+    return result;
+}
+
+RobotControllerInterfacePrx RobotControlUnit::getController(const std::string &, const Ice::Current &)
+{
+    RobotControllerInterfacePrx result;
+    return result;
+}
+
diff --git a/source/RobotAPI/components/RobotControlUnit/RobotControlUnit.h b/source/RobotAPI/components/RobotControlUnit/RobotControlUnit.h
new file mode 100644
index 000000000..df6b3c5f9
--- /dev/null
+++ b/source/RobotAPI/components/RobotControlUnit/RobotControlUnit.h
@@ -0,0 +1,116 @@
+/*
+ * 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::RobotControlUnit
+ * @author     Nikolaus Vahrenkamp ( vahrenkamp at kit dot edu )
+ * @date       2016
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+
+#ifndef _ARMARX_COMPONENT_RobotAPI_RobotControlUnit_H
+#define _ARMARX_COMPONENT_RobotAPI_RobotControlUnit_H
+
+
+#include <ArmarXCore/core/Component.h>
+#include <RobotAPI/interface/control/RobotControlUnitInterface.h>
+
+namespace armarx
+{
+    /**
+     * @class RobotControlUnitPropertyDefinitions
+     * @brief
+     */
+    class RobotControlUnitPropertyDefinitions:
+        public armarx::ComponentPropertyDefinitions
+    {
+    public:
+        RobotControlUnitPropertyDefinitions(std::string prefix):
+            armarx::ComponentPropertyDefinitions(prefix)
+        {
+            defineRequiredProperty<std::string>("Controllers", "List of the controllers and priorities which are run in the control loop. E. g. KinematicUnit:0,AnkleStabilizer:10");
+            //defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
+        }
+    };
+
+    /**
+     * @defgroup Component-RobotControlUnit RobotControlUnit
+     * @ingroup RobotAPI-Components
+     * A description of the component RobotControlUnit.
+     * 
+     * @class RobotControlUnit
+     * @ingroup Component-RobotControlUnit
+     * @brief Brief description of class RobotControlUnit.
+     * 
+     * Detailed description of class RobotControlUnit.
+     */
+    class RobotControlUnit :
+        virtual public armarx::Component,
+                public armarx::RobotControlUnitInterface
+    {
+    public:
+        /**
+         * @see armarx::ManagedIceObject::getDefaultName()
+         */
+        virtual std::string getDefaultName() const
+        {
+            return "RobotControlUnit";
+        }
+
+        bool requestJoints(const Ice::StringSeq &joints, const std::string &requesterIceId);
+
+        void releaseJoints(const Ice::StringSeq &joints, const std::string &requesterIceId);
+        void releaseJoints(const std::string &requesterIceId);
+
+        Ice::StringSeq getRequestedJoints() const;
+
+        void wakeUpControllers();
+
+    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();
+
+        virtual void executeControllers();
+
+        /**
+         * @see PropertyUser::createPropertyDefinitions()
+         */
+        virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions();
+
+        // RobotControlUnitInterface interface
+    public:
+        StringRobotControllerInterfacePrxMap getAvailableControllers(const Ice::Current &);
+        RobotControllerInterfacePrx getController(const std::string &, const Ice::Current &);
+    };
+}
+
+#endif
diff --git a/source/RobotAPI/components/RobotControlUnit/test/CMakeLists.txt b/source/RobotAPI/components/RobotControlUnit/test/CMakeLists.txt
new file mode 100644
index 000000000..afa216702
--- /dev/null
+++ b/source/RobotAPI/components/RobotControlUnit/test/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+# Libs required for the tests
+SET(LIBS ${LIBS} ArmarXCore RobotControlUnit)
+ 
+armarx_add_test(RobotControlUnitTest RobotControlUnitTest.cpp "${LIBS}")
\ No newline at end of file
diff --git a/source/RobotAPI/components/RobotControlUnit/test/RobotControlUnitTest.cpp b/source/RobotAPI/components/RobotControlUnit/test/RobotControlUnitTest.cpp
new file mode 100644
index 000000000..23f20517a
--- /dev/null
+++ b/source/RobotAPI/components/RobotControlUnit/test/RobotControlUnitTest.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::RobotControlUnit
+ * @author     Nikolaus Vahrenkamp ( vahrenkamp at kit dot edu )
+ * @date       2016
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+
+#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::RobotControlUnit
+
+#define ARMARX_BOOST_TEST
+
+#include <RobotAPI/Test.h>
+#include <RobotAPI/components/RobotControlUnit/RobotControlUnit.h>
+
+#include <iostream>
+
+BOOST_AUTO_TEST_CASE(testExample)
+{
+    //armarx::RobotControlUnit instance;
+
+    BOOST_CHECK_EQUAL(true, true);
+}
diff --git a/source/RobotAPI/interface/CMakeLists.txt b/source/RobotAPI/interface/CMakeLists.txt
index 044aadda5..3184116d4 100644
--- a/source/RobotAPI/interface/CMakeLists.txt
+++ b/source/RobotAPI/interface/CMakeLists.txt
@@ -19,6 +19,9 @@ set(SLICE_FILES
     core/RobotStateObserverInterface.ice
     core/Trajectory.ice
 
+    control/RobotControllerInterface.ice
+    control/RobotControlUnitInterface.ice
+
     selflocalisation/SelfLocalisationProcess.ice
 
     speech/SpeechInterface.ice
diff --git a/source/RobotAPI/interface/control/RobotControlUnitInterface.ice b/source/RobotAPI/interface/control/RobotControlUnitInterface.ice
new file mode 100644
index 000000000..c089d9ec3
--- /dev/null
+++ b/source/RobotAPI/interface/control/RobotControlUnitInterface.ice
@@ -0,0 +1,47 @@
+/*
+ * 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
+ */
+#ifndef ARMARX_CONTROL_ROBOTCONTROLUNIT_SLICE
+#define ARMARX_CONTROL_ROBOTCONTROLUNIT_SLICE
+
+#include <ArmarXCore/interface/core/BasicTypes.ice>
+#include <Ice/BuiltinSequences.ice>
+
+#include <RobotAPI/interface/control/RobotControllerInterface.ice>
+
+module armarx
+{
+    dictionary<string, RobotControllerInterface*> StringRobotControllerInterfacePrxMap;
+    /**
+     * RobotControlUnitInterface
+     */
+    interface RobotControlUnitInterface
+    {
+        StringRobotControllerInterfacePrxMap getAvailableControllers();
+
+        RobotControllerInterface* getController(string name);
+
+    };
+};
+
+#endif
diff --git a/source/RobotAPI/interface/control/RobotControllerInterface.ice b/source/RobotAPI/interface/control/RobotControllerInterface.ice
new file mode 100644
index 000000000..1b1001332
--- /dev/null
+++ b/source/RobotAPI/interface/control/RobotControllerInterface.ice
@@ -0,0 +1,62 @@
+/*
+ * 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
+ */
+#ifndef ARMARX_CONTROL_ROBOTCONTROLLER_SLICE
+#define ARMARX_CONTROL_ROBOTCONTROLLER_SLICE
+
+#include <ArmarXCore/interface/core/BasicTypes.ice>
+#include <Ice/BuiltinSequences.ice>
+
+module armarx
+{
+    module ControllerState
+    {
+        enum State
+        {
+            eDisabled,
+            eEnabled,
+            eFailure
+        };
+    };
+
+
+    /**
+     * RobotControllerInterface
+     */
+    interface RobotControllerInterface
+    {
+
+        bool enable();
+
+        void disable();
+
+        Ice::StringSeq getRequestedJoints();
+
+        ControllerState::State getState();
+
+        int getPriority();
+
+    };
+};
+
+#endif
-- 
GitLab