From b9ddf3069c27cbf852431c03f47cae207800ffc8 Mon Sep 17 00:00:00 2001
From: Christoph Pohl <christoph.pohl@kit.edu>
Date: Wed, 29 Nov 2023 11:08:13 +0100
Subject: [PATCH] Add Property to disable the observer publishing thread

In context of https://git.h2t.iar.kit.edu/sw/armarx-integration/robots/armar7/documentation/-/issues/85
---
 .../RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp | 6 +++++-
 .../RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h   | 6 ++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp
index a98d34947..4b9a12a21 100644
--- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp
+++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp
@@ -476,6 +476,7 @@ namespace armarx::RobotUnitModule
             getProperty<std::string>("DebugDrawerUpdatesTopicName").getValue();
         debugObserverTopicName = getProperty<std::string>("DebugObserverTopicName").getValue();
 
+        observerEnablePublishing = getProperty<bool>("ObserverEnablePublishing").getValue();
         observerPublishSensorValues = getProperty<bool>("ObserverPublishSensorValues").getValue();
         observerPublishControlTargets =
             getProperty<bool>("ObserverPublishControlTargets").getValue();
@@ -575,7 +576,10 @@ namespace armarx::RobotUnitModule
             [&] { publish({}); }, publishPeriodMs, false, getName() + "_PublisherTask");
         ARMARX_INFO << "starting publisher with timestep " << publishPeriodMs;
         publisherTask->setDelayWarningTolerance(10 * publishPeriodMs);
-        publisherTask->start();
+        if (observerEnablePublishing)
+        {
+            publisherTask->start();
+        }
     }
 
     void
diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h
index 9f061fd02..ffa451eb4 100644
--- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h
+++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h
@@ -58,6 +58,10 @@ namespace armarx::RobotUnitModule
             defineOptionalProperty<std::size_t>(
                 "PublishPeriodMs", 10, "Milliseconds between each publish");
 
+            defineOptionalProperty<bool>("ObserverEnablePublishing",
+                                         true,
+                                         "Whether the publishing thread is started or not",
+                                         PropertyDefinitionBase::eModifiable);
             defineOptionalProperty<bool>("ObserverPublishSensorValues",
                                          true,
                                          "Whether sensor values are send to the observer",
@@ -271,6 +275,8 @@ namespace armarx::RobotUnitModule
 
         /// @brief Whether \ref SensorValueBase "SensorValues" should be published to the observers
         std::atomic_bool observerPublishSensorValues;
+        /// @brief Whether the publishing thread should be started or not
+        std::atomic_bool observerEnablePublishing;
         /// @brief Whether \ref ControlTargetBase "ControlTargets" should be published to the observers
         std::atomic_bool observerPublishControlTargets;
         /// @brief Whether \ref Timing information should be published to the observers
-- 
GitLab