From 36d158746903fb245ac2f3bbe703fca251d85e84 Mon Sep 17 00:00:00 2001
From: Johann Mantel <j-mantel@gmx.net>
Date: Fri, 2 Jul 2021 12:43:46 +0200
Subject: [PATCH] make Parameters optional by providing default values

---
 etc/cmake/Findsick_scan_base.cmake            |   6 +-
 .../config/SickLaserUnit.cfg                  | 122 +++++++++++++++++-
 .../drivers/SickLaserUnit/CMakeLists.txt      |  10 ++
 .../drivers/SickLaserUnit/SickLaserUnit.cpp   |  19 +--
 .../drivers/SickLaserUnit/SickLaserUnit.h     |  20 ++-
 5 files changed, 149 insertions(+), 28 deletions(-)

diff --git a/etc/cmake/Findsick_scan_base.cmake b/etc/cmake/Findsick_scan_base.cmake
index a4723e39e..36714c613 100644
--- a/etc/cmake/Findsick_scan_base.cmake
+++ b/etc/cmake/Findsick_scan_base.cmake
@@ -31,9 +31,11 @@ find_path(sick_scan_base_INCLUDE_DIR_2 NAMES tinystr.h PATHS ${HEADER_SEARCH_PAT
 find_path(sick_scan_base_INCLUDE_DIR_3 NAMES sick_scan/SickScanConfig.h PATHS ${HEADER_SEARCH_PATHS} NO_DEFAULT_PATH)
 find_path(sick_scan_base_INCLUDE_DIR_4 NAMES dynamic_reconfigure/config_tools.h PATHS ${HEADER_SEARCH_PATHS} NO_DEFAULT_PATH)
 find_path(sick_scan_base_INCLUDE_DIR_5 NAMES sick_scan/SickScanConfig.h PATHS ${HEADER_SEARCH_PATHS} NO_DEFAULT_PATH)
+find_path(sick_scan_base_INCLUDE_DIR_6 NAMES sick_scan/rosconsole_simu.hpp PATHS ${HEADER_SEARCH_PATHS} NO_DEFAULT_PATH)
 
-if(sick_scan_base_INCLUDE_DIR_0 AND sick_scan_base_INCLUDE_DIR_1 AND sick_scan_base_INCLUDE_DIR_2 AND sick_scan_base_INCLUDE_DIR_3 AND sick_scan_base_INCLUDE_DIR_4 AND sick_scan_base_INCLUDE_DIR_4)
-    set(sick_scan_base_INCLUDE_DIRS ${sick_scan_base_INCLUDE_DIR_0} ${sick_scan_base_INCLUDE_DIR_1} ${sick_scan_base_INCLUDE_DIR_2} ${sick_scan_base_INCLUDE_DIR_3} ${sick_scan_base_INCLUDE_DIR_4} ${sick_scan_base_INCLUDE_DIR_5})
+
+if(sick_scan_base_INCLUDE_DIR_0 AND sick_scan_base_INCLUDE_DIR_1 AND sick_scan_base_INCLUDE_DIR_2 AND sick_scan_base_INCLUDE_DIR_3 AND sick_scan_base_INCLUDE_DIR_4 AND sick_scan_base_INCLUDE_DIR_5 AND sick_scan_base_INCLUDE_DIR_6)
+    set(sick_scan_base_INCLUDE_DIRS ${sick_scan_base_INCLUDE_DIR_0} ${sick_scan_base_INCLUDE_DIR_1} ${sick_scan_base_INCLUDE_DIR_2} ${sick_scan_base_INCLUDE_DIR_3} ${sick_scan_base_INCLUDE_DIR_4} ${sick_scan_base_INCLUDE_DIR_5} ${sick_scan_base_INCLUDE_DIR_6})
 endif()
 message(STATUS "sick_scan_base_INCLUDE_DIRS:${sick_scan_base_INCLUDE_DIRS}")
 
diff --git a/scenarios/SickLaserUnitTest/config/SickLaserUnit.cfg b/scenarios/SickLaserUnitTest/config/SickLaserUnit.cfg
index 8274f384d..19f03edb0 100644
--- a/scenarios/SickLaserUnitTest/config/SickLaserUnit.cfg
+++ b/scenarios/SickLaserUnitTest/config/SickLaserUnit.cfg
@@ -143,7 +143,7 @@
 # ArmarX.SickLaserUnit.ObjectName = ""
 
 
-# ArmarX.SickLaserUnit.angleOffset:  Offset to the LaserScanner Angle
+# ArmarX.SickLaserUnit.angleOffset:  offset to the scanning angle
 #  Attributes:
 #  - Default:            0
 #  - Case sensitivity:   yes
@@ -151,26 +151,134 @@
 ArmarX.SickLaserUnit.angleOffset = 0.0
 
 
-# ArmarX.SickLaserUnit.devices:  List of Device Names
+# ArmarX.SickLaserUnit.deviceNumber:  number of the LaserScanner Device
 #  Attributes:
-#  - Default:            Device1; Scanner2
+#  - Default:            0
 #  - Case sensitivity:   yes
 #  - Required:           no
+# ArmarX.SickLaserUnit.deviceNumber = 0
+
+
+# ArmarX.SickLaserUnit.devices:  No Description
+#  Attributes:
+#  - Default:            Device1; Scanner2
+#  - Case sensitivity:   no
+#  - Required:           no
 ArmarX.SickLaserUnit.devices = Device1; Scanner2
 
 
-# ArmarX.SickLaserUnit.laserScannerTopicName:  Name of the published Topic
+# ArmarX.SickLaserUnit.emulateSensor:  overwrite the default Settings and don't connect to Scanner
 #  Attributes:
+#  - Default:            false
 #  - Case sensitivity:   yes
-#  - Required:           yes
+#  - Required:           no
+#  - Possible values: {0, 1, false, no, true, yes}
+# ArmarX.SickLaserUnit.emulateSensor = false
+
+
+# ArmarX.SickLaserUnit.hostname:  Hostname of the LaserScanner
+#  Attributes:
+#  - Default:            192.168.8.133
+#  - Case sensitivity:   yes
+#  - Required:           no
+# ArmarX.SickLaserUnit.hostname = 192.168.8.133
+
+
+# ArmarX.SickLaserUnit.laserScannerTopicName:  No Description
+#  Attributes:
+#  - Default:            "SickTopic"
+#  - Case sensitivity:   no
+#  - Required:           no
 ArmarX.SickLaserUnit.laserScannerTopicName = "SickTopic"
 
 
-# ArmarX.SickLaserUnit.updatePeriod:  Update every ? ms
+# ArmarX.SickLaserUnit.newIpAddress:  New IP address for the LaserScanner
 #  Attributes:
-#  - Default:            1
+#  - Default:            ""
+#  - Case sensitivity:   yes
+#  - Required:           no
+# ArmarX.SickLaserUnit.newIpAddress = ""
+
+
+# ArmarX.SickLaserUnit.port:  port to use on the LaserScanner
+#  Attributes:
+#  - Default:            2112
 #  - Case sensitivity:   yes
 #  - Required:           no
+ArmarX.SickLaserUnit.port = 2112
+
+
+# ArmarX.SickLaserUnit.protocol:  Either use ASCII or Binary protocol
+#  Attributes:
+#  - Default:            ASCII
+#  - Case sensitivity:   yes
+#  - Required:           no
+#  - Possible values: {ASCII, Binary}
+ArmarX.SickLaserUnit.protocol = ASCII
+
+
+# ArmarX.SickLaserUnit.rangeMax:  maximum Range of the Scanner
+#  Attributes:
+#  - Default:            10
+#  - Case sensitivity:   yes
+#  - Required:           no
+ArmarX.SickLaserUnit.rangeMax = 10.00
+
+
+# ArmarX.SickLaserUnit.rangeMin:  minimum Range of the Scanner
+#  Attributes:
+#  - Default:            0
+#  - Case sensitivity:   yes
+#  - Required:           no
+ArmarX.SickLaserUnit.rangeMin = 0.01
+
+
+# ArmarX.SickLaserUnit.scannerType:  Name of the LaserScanner
+#  Attributes:
+#  - Case sensitivity:   yes
+#  - Required:           yes
+ArmarX.SickLaserUnit.scannerType = sick_tim_5xx
+
+
+# ArmarX.SickLaserUnit.sopasProtocolType:  Automatically set to true if the Scanner does not support ASCII communication
+#  Attributes:
+#  - Default:            false
+#  - Case sensitivity:   yes
+#  - Required:           no
+#  - Possible values: {0, 1, false, no, true, yes}
+# ArmarX.SickLaserUnit.sopasProtocolType = false
+
+
+# ArmarX.SickLaserUnit.subscribeDatagram:  subscribe to Datagram in communication or not
+#  Attributes:
+#  - Default:            false
+#  - Case sensitivity:   yes
+#  - Required:           no
+#  - Possible values: {0, 1, false, no, true, yes}
+# ArmarX.SickLaserUnit.subscribeDatagram = false
+
+
+# ArmarX.SickLaserUnit.timeIncrement:  timeIncrement??
+#  Attributes:
+#  - Default:            0.10000000000000001
+#  - Case sensitivity:   yes
+#  - Required:           no
+ArmarX.SickLaserUnit.timeIncrement = 0.1
+
+
+# ArmarX.SickLaserUnit.timelimit:  timelimit for communication
+#  Attributes:
+#  - Default:            5
+#  - Case sensitivity:   yes
+#  - Required:           no
+# ArmarX.SickLaserUnit.timelimit = 5
+
+
+# ArmarX.SickLaserUnit.updatePeriod:  No Description
+#  Attributes:
+#  - Default:            1
+#  - Case sensitivity:   no
+#  - Required:           no
 ArmarX.SickLaserUnit.updatePeriod = 1
 
 
diff --git a/source/RobotAPI/drivers/SickLaserUnit/CMakeLists.txt b/source/RobotAPI/drivers/SickLaserUnit/CMakeLists.txt
index d123908c6..24f8769f4 100644
--- a/source/RobotAPI/drivers/SickLaserUnit/CMakeLists.txt
+++ b/source/RobotAPI/drivers/SickLaserUnit/CMakeLists.txt
@@ -17,7 +17,10 @@ armarx_set_target("Library: ${LIB_NAME}")
 
 find_package(sick_scan_base)
 armarx_build_if(sick_scan_base_FOUND "sick_scan_base not available")
+add_definitions(-DROSSIMU)
 
+find_package(Boost COMPONENTS system filesystem thread REQUIRED)
+armarx_build_if(Boost_FOUND "Boost not available")
 
 # Add the component
 armarx_add_component(
@@ -38,12 +41,15 @@ armarx_add_component(
 	## SickLaserUnitInterfaces  # If you defined a component ice interface above.
 
 	${sick_scan_base_LIBRARIES}
+	${Boost_LIBRARY_DIRS}
 
     SOURCES
         SickLaserUnit.cpp
+		#SickScanAdapter.cpp
 
     HEADERS
         SickLaserUnit.h
+		#SickScanAdapter.h
 )
 
 
@@ -53,6 +59,10 @@ if(sick_scan_base_FOUND)
     target_compile_definitions(${LIB_NAME} PUBLIC "-Dlinux")
 endif()
 
+if(Boost_FOUND)
+    target_include_directories(${LIB_NAME} PUBLIC ${Boost_INCLUDE_DIR})
+endif()
+
 # All target_include_directories must be guarded by if(Xyz_FOUND)
 # For multiple libraries write: if(X_FOUND AND Y_FOUND) ...
 #if(MyLib_FOUND)
diff --git a/source/RobotAPI/drivers/SickLaserUnit/SickLaserUnit.cpp b/source/RobotAPI/drivers/SickLaserUnit/SickLaserUnit.cpp
index 248e57adb..c706c5162 100644
--- a/source/RobotAPI/drivers/SickLaserUnit/SickLaserUnit.cpp
+++ b/source/RobotAPI/drivers/SickLaserUnit/SickLaserUnit.cpp
@@ -62,6 +62,7 @@ namespace armarx
                     {
                         ARMARX_INFO_S << "looping";
                         result = scanner->loopOnce();
+                        ARMARX_INFO_S << "finished looping";
                     }
                     else
                     {
@@ -86,6 +87,7 @@ namespace armarx
         delete this->scanner; // disconnect scanner
         if (this->useTcp)
         {
+            //this->scanner = new SickScanAdapter(this->ip, this->port, this->timelimit, this->parser, this->colaDialectId);
             this->scanner = new sick_scan::SickScanCommonTcp(this->ip, this->port, this->timelimit, this->parser, this->colaDialectId);
         }
         else
@@ -100,6 +102,7 @@ namespace armarx
         }
         result = this->scanner->init();
         this->isSensorInitialized = true;
+        ARMARX_INFO_S << "Scanner initialized.";
 
         if (result == sick_scan::ExitSuccess) // OK -> loop again
         {
@@ -146,13 +149,12 @@ namespace armarx
         //Scanner parameters
         def->required(properties.scannerType, "scannerType", "Name of the LaserScanner");
         def->optional(properties.deviceNumber, "deviceNumber", "number of the LaserScanner Device");
-        def->optional(properties.angleOffset, "angelOffset", "offset to the scanning angle");
-        def->required(properties.rangeMin, "rangeMin", "minimum Range of the Scanner");
-        def->required(properties.rangeMax, "rangeMax", "maximum Range of the Scanner");
+        def->optional(properties.angleOffset, "angleOffset", "offset to the scanning angle");
+        def->optional(properties.rangeMin, "rangeMin", "minimum Range of the Scanner");
+        def->optional(properties.rangeMax, "rangeMax", "maximum Range of the Scanner");
         def->optional(properties.timeIncrement, "timeIncrement", "timeIncrement??");
         //Additional configuration
         def->optional(properties.emulSensor, "emulateSensor", "overwrite the default Settings and don't connect to Scanner");
-
         return def;
     }
 
@@ -164,7 +166,7 @@ namespace armarx
         // (Requies the armarx::DebugObserverComponentPluginUser.)
         // setDebugObserverBatchModeEnabled(true);
 
-        ARMARX_INFO_S << "SickLaserUnit sagt Hallo Welt!";
+        ARMARX_INFO_S << "initializing SickLaserUnit.";
 
         scanDevice.isSensorInitialized = false;
         if (properties.hostname != "")
@@ -217,12 +219,12 @@ namespace armarx
                 }
                 else
                 {
-                    ARMARX_INFO_S << "ASCII protocol activated";
+                    ARMARX_INFO_S << "ASCII protocol activated.";
                     scanDevice.protocol = ScanProtocol::ASCII;
                 }
                 break;
             case ScanProtocol::Binary:
-                ARMARX_INFO_S << "Binary protocol activated";
+                ARMARX_INFO_S << "Binary protocol activated.";
                 scanDevice.protocol = ScanProtocol::Binary;
                 break;
             default:
@@ -240,11 +242,12 @@ namespace armarx
             scanDevice.parser->getCurrentParamPtr()->setUseBinaryProtocol(true);
             scanDevice.colaDialectId = 'B';
         }
-        ARMARX_INFO_S << "SickLaserUnit fertig initialisiert.";
+        ARMARX_INFO_S << "SickLaserUnit initialisation complete.";
     }
 
     void SickLaserUnit::onConnectComponent()
     {
+        ARMARX_INFO_S << "Connecting.";
         //start the laser scanner
         if (scanDevice.task)
         {
diff --git a/source/RobotAPI/drivers/SickLaserUnit/SickLaserUnit.h b/source/RobotAPI/drivers/SickLaserUnit/SickLaserUnit.h
index b70185321..e9a038959 100644
--- a/source/RobotAPI/drivers/SickLaserUnit/SickLaserUnit.h
+++ b/source/RobotAPI/drivers/SickLaserUnit/SickLaserUnit.h
@@ -26,20 +26,17 @@
 
 #include <ArmarXCore/core/Component.h>
 #include <ArmarXCore/core/services/tasks/RunningTask.h>
-// #include
-// <ArmarXCore/libraries/ArmarXCoreComponentPlugins/DebugObserverComponentPlugin.h>
+// #include <ArmarXCore/libraries/ArmarXCoreComponentPlugins/DebugObserverComponentPlugin.h>
 
-// #include
-// <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h>
+// #include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h>
 
 // #include <RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h>
 
 #include <vector>
 
-//#include "thirdparty/sick_scan_base/include/sick_scan/sick_scan_common.h"
-
-#include <sick_scan/sick_scan_common_tcp.h>
+//#include "SickScanAdapter.h"
 #include <sick_scan/sick_scan_common.h>
+#include <sick_scan/sick_scan_common_tcp.h>
 #include <sick_scan/sick_generic_laser.h>
 
 namespace armarx
@@ -63,6 +60,7 @@ namespace armarx
         //scanner parameters
         std::string scannerType = "sick_tim_5xx";
         int deviceNumber = 0;
+        double angleOffset = 0.0;
         double rangeMin;
         double rangeMax;
         double timeIncrement;
@@ -70,7 +68,6 @@ namespace armarx
         std::string ip;
         std::string newIpAddress = "";
         std::string port;
-        double angleOffset = 0.0;
         int timelimit = 5;
         bool subscribeDatagram = false;
         ScanProtocol protocol = ScanProtocol::ASCII;
@@ -84,6 +81,7 @@ namespace armarx
         RunState runState = RunState::scannerFinalize;
         RunningTask<SickLaserScanDevice>::pointer_type task;
         sick_scan::SickScanConfig cfg;
+        //SickScanAdapter* scanner;
         sick_scan::SickScanCommonTcp* scanner;
         sick_scan::SickGenericParser* parser;
         int result = sick_scan::ExitError;
@@ -168,9 +166,9 @@ namespace armarx
             std::string scannerType = "sick_tim_5xx";
             int deviceNumber = 0;
             double angleOffset = 0.0;
-            double rangeMin;
-            double rangeMax;
-            double timeIncrement;
+            double rangeMin  = 0.0;
+            double rangeMax = 10.0;
+            double timeIncrement = 0.1;
             //additional parameters
             bool emulSensor = false;
         };
-- 
GitLab