From 4f4212e5f9b7d08976ef87620843f53d58719f54 Mon Sep 17 00:00:00 2001 From: Christoph Pohl <christoph.pohl@kit.edu> Date: Tue, 26 Oct 2021 11:09:46 +0200 Subject: [PATCH] Refactors ComponentPlugin to be self-sufficient --- .../navigation/client/ComponentPlugin.cpp | 26 ++++++------ .../navigation/client/ComponentPlugin.h | 40 +++++++++---------- .../components/example_client/Component.cpp | 30 +++++++------- 3 files changed, 46 insertions(+), 50 deletions(-) diff --git a/source/armarx/navigation/client/ComponentPlugin.cpp b/source/armarx/navigation/client/ComponentPlugin.cpp index 3578b695..07cb43c0 100644 --- a/source/armarx/navigation/client/ComponentPlugin.cpp +++ b/source/armarx/navigation/client/ComponentPlugin.cpp @@ -36,16 +36,23 @@ armarx::navigation::client::ComponentPlugin::preOnConnectComponent() ARMARX_TRACE; const std::string componentName = parent().getName(); - IceNavigator& srv = parent<armarx::navigation::client::ComponentPluginUser>().iceNavigator; ARMARX_CHECK_NOT_NULL(navigatorPrx) << "Navigator proxy is null!"; - srv.setNavigatorComponent(navigatorPrx); + iceNavigator.setNavigatorComponent(navigatorPrx); +} + +void +armarx::navigation::client::ComponentPlugin::configureNavigator( + const client::NavigationStackConfig& stackConfig, + const std::string& configId) +{ + ARMARX_TRACE; + iceNavigator.createConfig(stackConfig, configId); } // ComponentPluginUser -armarx::navigation::client::ComponentPluginUser::ComponentPluginUser() : - navigator{navigatorServices} +armarx::navigation::client::ComponentPluginUser::ComponentPluginUser() { ARMARX_TRACE; addPlugin(plugin); @@ -55,15 +62,8 @@ void armarx::navigation::client::ComponentPluginUser::configureNavigator( const client::NavigationStackConfig& stackConfig) { - configureNavigator(stackConfig, getName()); -} - -void -armarx::navigation::client::ComponentPluginUser::configureNavigator( - const client::NavigationStackConfig& stackConfig, - const std::string& configId) -{ - iceNavigator.createConfig(stackConfig, configId); + ARMARX_TRACE; + plugin->configureNavigator(stackConfig, getName()); } armarx::navigation::client::ComponentPluginUser::~ComponentPluginUser() = default; diff --git a/source/armarx/navigation/client/ComponentPlugin.h b/source/armarx/navigation/client/ComponentPlugin.h index f64ce55b..ce6c5ad8 100644 --- a/source/armarx/navigation/client/ComponentPlugin.h +++ b/source/armarx/navigation/client/ComponentPlugin.h @@ -14,11 +14,13 @@ namespace armarx::navigation::client { - class ComponentPlugin : virtual public armarx::ComponentPlugin + class ComponentPlugin : public armarx::ComponentPlugin { public: - using armarx::ComponentPlugin::ComponentPlugin; + ComponentPlugin(ManagedIceObject& parent, const std::string& prefix) : + armarx::ComponentPlugin(parent, prefix), navigator(navigatorServices){}; +// using armarx::ComponentPlugin::ComponentPlugin; ~ComponentPlugin() override; @@ -28,10 +30,21 @@ namespace armarx::navigation::client void preOnConnectComponent() override; + void configureNavigator(const client::NavigationStackConfig& stackConfig, + const std::string& configId); + private: static constexpr const char* PROPERTY_NAME = "nav.NavigatorName"; client::NavigatorInterfacePrx navigatorPrx; + IceNavigator iceNavigator; + // MemorySubscriber memorySubscriber; + SimpleEventHandler memorySubscriber; // FIXME + Navigator::InjectedServices navigatorServices{.navigator = &iceNavigator, + .subscriber = &memorySubscriber}; + + public: + Navigator navigator; }; @@ -42,31 +55,14 @@ namespace armarx::navigation::client ComponentPluginUser(); void configureNavigator(const client::NavigationStackConfig& stackConfig); - - void configureNavigator(const client::NavigationStackConfig& stackConfig, - const std::string& configId); - - + Navigator& getNavigator() { + return plugin->navigator; + } // Non-API - - public: ~ComponentPluginUser() override; - friend class ComponentPlugin; - private: - IceNavigator iceNavigator; - // MemorySubscriber memorySubscriber; - SimpleEventHandler memorySubscriber; // FIXME - Navigator::InjectedServices navigatorServices{.navigator = &iceNavigator, - .subscriber = &memorySubscriber}; - - ComponentPlugin* plugin = nullptr; - - - public: - Navigator navigator; }; } // namespace armarx::navigation::client diff --git a/source/armarx/navigation/components/example_client/Component.cpp b/source/armarx/navigation/components/example_client/Component.cpp index 1a8b1fdd..5b702a53 100644 --- a/source/armarx/navigation/components/example_client/Component.cpp +++ b/source/armarx/navigation/components/example_client/Component.cpp @@ -103,10 +103,10 @@ namespace armarx::navigation::components::example_client .trajectoryController(traj_ctrl::TrajectoryFollowingControllerParams())); // Example of registering a lambda as callback. - navigator.onGoalReached([&]() { ARMARX_IMPORTANT << "Goal reached! (lambda-style)"; }); + getNavigator().onGoalReached([&]() { ARMARX_IMPORTANT << "Goal reached! (lambda-style)"; }); // Example of registering a method as callback. - navigator.onGoalReached([this] { goalReached(); }); + getNavigator().onGoalReached([this] { goalReached(); }); std::this_thread::sleep_for(1s); @@ -115,12 +115,12 @@ namespace armarx::navigation::components::example_client core::Pose goal = core::Pose::Identity(); goal.translation() << 2000, 1000, 0; - navigator.moveTo(goal, core::NavigationFrame::Absolute); + getNavigator().moveTo(goal, core::NavigationFrame::Absolute); std::this_thread::sleep_for(15s); // Wait until goal is reached - armarx::navigation::client::StopEvent se = navigator.waitForStop(); + armarx::navigation::client::StopEvent se = getNavigator().waitForStop(); if (se) { ARMARX_INFO << "Goal 1 reached."; @@ -143,12 +143,12 @@ namespace armarx::navigation::components::example_client } goal.translation() << -1500, 1000, 0; - navigator.moveTo(goal, core::NavigationFrame::Absolute); + getNavigator().moveTo(goal, core::NavigationFrame::Absolute); std::this_thread::sleep_for(15s); // Wait until goal is reached - se = navigator.waitForStop(); + se = getNavigator().waitForStop(); if (se) { ARMARX_INFO << "Goal 2 reached."; @@ -159,10 +159,10 @@ namespace armarx::navigation::components::example_client } goal.translation() << 4500, 4500, 0; - navigator.moveTo(goal, core::NavigationFrame::Absolute); + getNavigator().moveTo(goal, core::NavigationFrame::Absolute); // Wait until goal is reached - se = navigator.waitForStop(); + se = getNavigator().waitForStop(); if (se) { ARMARX_INFO << "Goal 3 reached."; @@ -178,12 +178,12 @@ namespace armarx::navigation::components::example_client ARMARX_INFO << "Moving into certain direction."; // Start moving towards a direction - navigator.moveTowards(core::Direction(100, 100, 0), core::NavigationFrame::Relative); + getNavigator().moveTowards(core::Direction(100, 100, 0), core::NavigationFrame::Relative); std::this_thread::sleep_for(3s); ARMARX_INFO << "Pausing movement."; - navigator.pause(); + getNavigator().pause(); } void @@ -206,10 +206,10 @@ namespace armarx::navigation::components::example_client .trajectoryController(traj_ctrl::TrajectoryFollowingControllerParams())); // Example of registering a lambda as callback. - navigator.onGoalReached([&]() { ARMARX_IMPORTANT << "Goal reached! (lambda-style)"; }); + getNavigator().onGoalReached([&]() { ARMARX_IMPORTANT << "Goal reached! (lambda-style)"; }); // Example of registering a method as callback. - navigator.onGoalReached([this] { goalReached(); }); + getNavigator().onGoalReached([this] { goalReached(); }); std::this_thread::sleep_for(1s); @@ -232,12 +232,12 @@ namespace armarx::navigation::components::example_client // clang-format on ARMARX_INFO << "Starting execution"; - navigator.moveTo(pathBuilder, core::NavigationFrame::Absolute); + 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 = navigator.waitForStop(); + armarx::navigation::client::StopEvent se = getNavigator().waitForStop(); if (se) { ARMARX_INFO << "Goal 1 reached."; @@ -260,7 +260,7 @@ namespace armarx::navigation::components::example_client } ARMARX_INFO << "Pausing movement."; - navigator.pause(); + getNavigator().pause(); } -- GitLab