diff --git a/source/Navigation/components/Navigator/Navigator.cpp b/source/Navigation/components/Navigator/Navigator.cpp index cbcf31cbf144a3453d3d81e72d4d980adaa0f4ea..3f16c96100f0356715b67d9e3203bc662c556caf 100644 --- a/source/Navigation/components/Navigator/Navigator.cpp +++ b/source/Navigation/components/Navigator/Navigator.cpp @@ -39,7 +39,6 @@ #include "Navigation/libraries/util/util.h" #include <Navigation/libraries/factories/NavigationStackFactory.h> - armarx::nav::components::Navigator::Navigator() : executor{platformUnit} { } @@ -48,60 +47,48 @@ armarx::nav::components::Navigator::~Navigator() { } - -void -armarx::nav::components::Navigator::onInitComponent() +void armarx::nav::components::Navigator::onInitComponent() { } - -void -armarx::nav::components::Navigator::onConnectComponent() +void armarx::nav::components::Navigator::onConnectComponent() { } - -void -armarx::nav::components::Navigator::onDisconnectComponent() +void armarx::nav::components::Navigator::onDisconnectComponent() { } - -void -armarx::nav::components::Navigator::onExitComponent() +void armarx::nav::components::Navigator::onExitComponent() { } - -void -armarx::nav::components::Navigator::updateContext() +void armarx::nav::components::Navigator::updateContext() { scene.staticScene = staticScene(); scene.robot = getRobot(); } - -std::string -armarx::nav::components::Navigator::getDefaultName() const +std::string armarx::nav::components::Navigator::getDefaultName() const { return "Navigator"; } - -std::vector<armarx::nav::core::Pose> -convert(const std::vector<Eigen::Matrix4f>& wps) +std::vector<armarx::nav::core::Pose> convert(const std::vector<Eigen::Matrix4f>& wps) { using namespace armarx::nav; std::vector<core::Pose> p; p.reserve(wps.size()); - std::transform(wps.begin(), wps.end(), std::back_inserter(p), [](const auto & p) + std::transform(wps.begin(), + wps.end(), + std::back_inserter(p), + [](const auto & p) { return Eigen::Affine3f(p); }); return p; } - std::string armarx::nav::components::Navigator::createConfig(const aron::data::AronDictPtr& stackConfig, const Ice::Current&) @@ -115,50 +102,39 @@ armarx::nav::components::Navigator::createConfig(const aron::data::AronDictPtr& return uuid; } - -void -armarx::nav::components::Navigator::moveTo(const std::vector<Eigen::Matrix4f>& waypoints, +void armarx::nav::components::Navigator::moveTo(const std::vector<Eigen::Matrix4f>& waypoints, const std::string& navigationMode, const std::string& configId, const Ice::Current&) { // TODO: Error handling. - navigators.at(configId).moveTo(convert(waypoints), core::NavigationFramesMap.from_name(navigationMode)); + navigators.at(configId).moveTo(convert(waypoints), + core::NavigationFramesMap.from_name(navigationMode)); } - -void -armarx::nav::components::Navigator::moveTowards(const Eigen::Vector3f& direction, +void armarx::nav::components::Navigator::moveTowards(const Eigen::Vector3f& direction, const std::string& navigationMode, const std::string& configId, const Ice::Current&) { // TODO: Error handling. - navigators.at(configId).moveTowards(direction, core::NavigationFramesMap.from_name(navigationMode)); + navigators.at(configId).moveTowards(direction, + core::NavigationFramesMap.from_name(navigationMode)); } - -void -armarx::nav::components::Navigator::pauseMovement(const Ice::Current&) +void armarx::nav::components::Navigator::pauseMovement(const Ice::Current&) { - } - -void -armarx::nav::components::Navigator::resumeMovement(const Ice::Current&) +void armarx::nav::components::Navigator::resumeMovement(const Ice::Current&) { - } - -armarx::PropertyDefinitionsPtr -armarx::nav::components::Navigator::createPropertyDefinitions() +armarx::PropertyDefinitionsPtr armarx::nav::components::Navigator::createPropertyDefinitions() { - armarx::PropertyDefinitionsPtr def = - new ComponentPropertyDefinitions(getConfigIdentifier()); + armarx::PropertyDefinitionsPtr def = new ComponentPropertyDefinitions(getConfigIdentifier()); // Publish to a topic (passing the TopicListenerPrx). // def->topic(myTopicListener); @@ -167,7 +143,7 @@ armarx::nav::components::Navigator::createPropertyDefinitions() // def->topic<PlatformUnitListener>("MyTopic"); // Use (and depend on) another component (passing the ComponentInterfacePrx). - def->component(platformUnit); + // def->component(platformUnit); // Add a required property. // def->required(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz."); @@ -178,9 +154,7 @@ armarx::nav::components::Navigator::createPropertyDefinitions() return def; } - -armarx::nav::core::StaticScene -armarx::nav::components::Navigator::staticScene() +armarx::nav::core::StaticScene armarx::nav::components::Navigator::staticScene() { core::StaticScene scene; @@ -191,9 +165,7 @@ armarx::nav::components::Navigator::staticScene() return scene; } - -VirtualRobot::RobotPtr -armarx::nav::components::Navigator::getRobot() +VirtualRobot::RobotPtr armarx::nav::components::Navigator::getRobot() { auto robot = RemoteRobot::createLocalCloneFromFile( getRobotStateComponent(), VirtualRobot::RobotIO::RobotDescription::eFull); @@ -207,3 +179,60 @@ armarx::nav::components::Navigator::getRobot() return robot; } + + +void armarx::nav::components::Navigator::createRemoteGuiTab() +{ + using namespace armarx::RemoteGui::Client; + + // Setup the widgets. + + tab.boxLayerName.setValue(0); + tab.numBoxes.setValue(1); + tab.numBoxes.setRange(0, 100); + + tab.drawBoxes.setLabel("Draw Boxes"); + + // Setup the layout. + + GridLayout grid; + int row = 0; + { + grid.add(Label("Box Layer"), {row, 0}).add(tab.boxLayerName, {row, 1}); + ++row; + + grid.add(Label("Num Boxes"), {row, 0}).add(tab.numBoxes, {row, 1}); + ++row; + + grid.add(tab.drawBoxes, {row, 0}, {2, 1}); + ++row; + } + + VBoxLayout root = {grid, VSpacer()}; + RemoteGui_createTab(getName(), root, &tab); +} + + +void armarx::nav::components::Navigator::RemoteGui_update() +{ + // if (tab.boxLayerName.hasValueChanged() || tab.numBoxes.hasValueChanged()) + // { + // std::scoped_lock lock(propertiesMutex); + // properties.boxLayerName = tab.boxLayerName.getValue(); + // properties.numBoxes = tab.numBoxes.getValue(); + + // { + // setDebugObserverDatafield("numBoxes", properties.numBoxes); + // setDebugObserverDatafield("boxLayerName", properties.boxLayerName); + // sendDebugObserverBatch(); + // } + // } + if (tab.drawBoxes.wasClicked()) + { + // Lock shared variables in methods running in seperate threads + // and pass them to functions. This way, the called functions do + // not need to think about locking. + std::scoped_lock lock(propertiesMutex); + // drawBoxes(properties, arviz); + } +} diff --git a/source/Navigation/components/Navigator/Navigator.h b/source/Navigation/components/Navigator/Navigator.h index a22d4de00766b499cebb59ff16db3fa695fb6c2b..16ad98af456be7461d78847456433a9836e0c072 100644 --- a/source/Navigation/components/Navigator/Navigator.h +++ b/source/Navigation/components/Navigator/Navigator.h @@ -20,10 +20,8 @@ * GNU General Public License */ - #pragma once - // STD/STL #include <optional> #include <string> @@ -34,6 +32,9 @@ // ArmarX #include <ArmarXCore/core/Component.h> + +#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> + #include <RobotAPI/interface/units/PlatformUnitInterface.h> #include <RobotAPI/libraries/ArmarXObjects/plugins/ObjectPoseClientPlugin.h> #include <RobotAPI/libraries/RobotAPIComponentPlugins/RobotStateComponentPlugin.h> @@ -41,10 +42,9 @@ // Navigation #include "Navigation/libraries/core/StaticScene.h" #include "Navigation/libraries/core/types.h" +#include <Navigation/components/Navigator/NavigatorInterface.h> #include <Navigation/libraries/server/Navigator.h> #include <Navigation/libraries/server/execution/PlatformUnitExecutor.h> -#include <Navigation/components/Navigator/NavigatorInterface.h> - namespace armarx::nav::components { @@ -64,11 +64,11 @@ namespace armarx::nav::components virtual public armarx::Component, virtual public NavigatorInterface, virtual public armarx::ObjectPoseClientPluginUser, - virtual public armarx::RobotStateComponentPluginUser + virtual public armarx::RobotStateComponentPluginUser, + virtual public armarx::LightweightRemoteGuiComponentPluginUser { public: - Navigator(); ~Navigator() override; @@ -115,16 +115,32 @@ namespace armarx::nav::components VirtualRobot::RobotPtr getRobot(); + void createRemoteGuiTab(); + void RemoteGui_update() override; + + private: // TODO update context periodically - PlatformUnitInterfacePrx platformUnit; core::Scene scene; server::PlatformUnitExecutor executor; std::map<std::string, server::Navigator> navigators; + + + std::mutex propertiesMutex; + + struct RemoteGuiTab : armarx::RemoteGui::Client::Tab + { + armarx::RemoteGui::Client::LineEdit boxLayerName; + + armarx::RemoteGui::Client::IntSpinBox numBoxes; + + armarx::RemoteGui::Client::Button drawBoxes; + }; + RemoteGuiTab tab; }; } // namespace armarx::nav::components