From 078e698c6e444a072e982c9d8a5c87c132428fe6 Mon Sep 17 00:00:00 2001
From: Fabian Reister <fabian.reister@kit.edu>
Date: Wed, 8 Jun 2022 14:48:28 +0200
Subject: [PATCH] cleaning up example

---
 .../components/example_client/Component.cpp   | 32 +++++++------------
 .../components/example_client/Component.h     |  4 ++-
 2 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/examples/components/example_client/Component.cpp b/examples/components/example_client/Component.cpp
index 56404a58..84f1485b 100644
--- a/examples/components/example_client/Component.cpp
+++ b/examples/components/example_client/Component.cpp
@@ -46,9 +46,9 @@
 namespace armarx::navigation::components::example_client
 {
 
-    Component::Component() : virtualRobotReader(memoryNameSystem())
+    Component::Component()
     {
-        // pass
+        addPlugin(virtualRobotReaderPlugin);
     }
 
 
@@ -68,8 +68,6 @@ namespace armarx::navigation::components::example_client
     void
     Component::onConnectComponent()
     {
-        virtualRobotReader.connect();
-
         task = new armarx::RunningTask<Component>(this, &Component::exampleNavigationPointToPoint);
         task->start();
     }
@@ -100,8 +98,6 @@ namespace armarx::navigation::components::example_client
     void
     Component::exampleNavigation()
     {
-        using namespace std::chrono_literals;
-
         // Import relevant namespaces.
         using namespace armarx::navigation;
 
@@ -120,7 +116,7 @@ namespace armarx::navigation::components::example_client
         // Example of registering a method as callback.
         getNavigator().onGoalReached([this] { goalReached(); });
 
-        std::this_thread::sleep_for(1s);
+        Clock::WaitFor(Duration::Seconds(1));
 
         ARMARX_INFO << "Moving to goal pose";
         // Start moving to goal position using above config.
@@ -129,7 +125,7 @@ namespace armarx::navigation::components::example_client
 
         getNavigator().moveTo(goal, core::NavigationFrame::Absolute);
 
-        std::this_thread::sleep_for(15s);
+        Clock::WaitFor(Duration::Seconds(15));
 
         // Wait until goal is reached
         armarx::navigation::client::StopEvent se = getNavigator().waitForStop();
@@ -157,7 +153,7 @@ namespace armarx::navigation::components::example_client
         goal.translation() << -1500, 1000, 0;
         getNavigator().moveTo(goal, core::NavigationFrame::Absolute);
 
-        std::this_thread::sleep_for(15s);
+        Clock::WaitFor(Duration::Seconds(15));
 
         // Wait until goal is reached
         se = getNavigator().waitForStop();
@@ -184,7 +180,7 @@ namespace armarx::navigation::components::example_client
             ARMARX_ERROR << "Could not reach goal 3!";
         }
 
-        std::this_thread::sleep_for(15s);
+        Clock::WaitFor(Duration::Seconds(15));
 
         // TODO example with waypoints
 
@@ -192,7 +188,7 @@ namespace armarx::navigation::components::example_client
         // Start moving towards a direction
         getNavigator().moveTowards(core::Direction(100, 100, 0), core::NavigationFrame::Relative);
 
-        std::this_thread::sleep_for(3s);
+        Clock::WaitFor(Duration::Seconds(3));
 
         ARMARX_INFO << "Pausing movement.";
         getNavigator().pause();
@@ -203,8 +199,6 @@ namespace armarx::navigation::components::example_client
     {
         ARMARX_INFO << "Demonstrating complex navigation";
 
-        using namespace std::chrono_literals;
-
         // Import relevant namespaces.
         using namespace armarx::navigation;
 
@@ -223,7 +217,7 @@ namespace armarx::navigation::components::example_client
         // Example of registering a method as callback.
         getNavigator().onGoalReached([this] { goalReached(); });
 
-        std::this_thread::sleep_for(1s);
+        Clock::WaitFor(Duration::Seconds(1));
 
         ARMARX_INFO << "Moving to goal pose";
         // Start moving to goal position using above config.
@@ -246,8 +240,6 @@ namespace armarx::navigation::components::example_client
         ARMARX_INFO << "Starting execution";
         getNavigator().moveTo(pathBuilder, core::NavigationFrame::Absolute);
 
-        std::this_thread::sleep_for(25s); // TODO(fabian.reister): remove in the future
-
         // Wait until goal is reached
         armarx::navigation::client::StopEvent se = getNavigator().waitForStop();
         if (se)
@@ -295,12 +287,13 @@ namespace armarx::navigation::components::example_client
                 .globalPlanner(global_planning::Point2PointParams())
                 .trajectoryController(traj_ctrl::TrajectoryFollowingControllerParams()));
 
-
-        std::this_thread::sleep_for(1s);
+        Clock::WaitFor(Duration::Seconds(1));
 
         ARMARX_INFO << "Moving to goal pose";
         // Start moving to goal position using above config.
 
+        auto& virtualRobotReader = virtualRobotReaderPlugin->get(); 
+
         auto robot =
             virtualRobotReader.getSynchronizedRobot(properties.robotName, armarx::Clock::Now());
         ARMARX_CHECK_NOT_NULL(robot);
@@ -376,9 +369,6 @@ namespace armarx::navigation::components::example_client
                       "relativeMovement",
                       "The distance between two target poses [mm]");
 
-        virtualRobotReader.registerPropertyDefinitions(def);
-
-
         return def;
     }
 
diff --git a/examples/components/example_client/Component.h b/examples/components/example_client/Component.h
index aaa62999..0fb9bd4c 100644
--- a/examples/components/example_client/Component.h
+++ b/examples/components/example_client/Component.h
@@ -27,6 +27,7 @@
 #include <ArmarXCore/util/tasks.h>
 
 #include <armarx/navigation/client.h>
+#include "RobotAPI/libraries/armem/client/plugins/ReaderWriterPlugin.h"
 #include "RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotReader.h"
 #include <RobotAPI/libraries/armem/client/plugins.h>
 
@@ -100,7 +101,8 @@ namespace armarx::navigation::components::example_client
 
         armarx::RunningTask<Component>::pointer_type task;
 
-        armem::robot_state::VirtualRobotReader virtualRobotReader;
+        armem::client::plugins::ReaderWriterPlugin<armem::robot_state::VirtualRobotReader>* virtualRobotReaderPlugin = nullptr;
+
 
     };
 
-- 
GitLab