diff --git a/source/armarx/navigation/client/ComponentPlugin.cpp b/source/armarx/navigation/client/ComponentPlugin.cpp index 3578b69541b521fad45360ffa78e794a5c7dc180..07cb43c00480fb7a95c6aaf692e3e58ebf9746ce 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 f64ce55b7a22545d49dcd99e2d992c589d6449c8..ce6c5ad80f4564b5c86af1cec1a7533bb48972e3 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 1a8b1fdda8526184bd7052d3b0a061556ad179d6..5b702a537dfc0b489e0ef23bf363a923e1b0bceb 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(); }