From 24830cf84d033922e9710eb83dddd67c70413bd2 Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Wed, 29 Nov 2023 09:25:48 +0100 Subject: [PATCH] Add component MemoryPlotter (WIP) --- .../components/armem/client/CMakeLists.txt | 1 + .../armem/client/MemoryPlotter/CMakeLists.txt | 21 ++++ .../client/MemoryPlotter/MemoryPlotter.cpp | 106 ++++++++++++++++++ .../client/MemoryPlotter/MemoryPlotter.h | 99 ++++++++++++++++ 4 files changed, 227 insertions(+) create mode 100644 source/RobotAPI/components/armem/client/MemoryPlotter/CMakeLists.txt create mode 100644 source/RobotAPI/components/armem/client/MemoryPlotter/MemoryPlotter.cpp create mode 100644 source/RobotAPI/components/armem/client/MemoryPlotter/MemoryPlotter.h diff --git a/source/RobotAPI/components/armem/client/CMakeLists.txt b/source/RobotAPI/components/armem/client/CMakeLists.txt index 9e9e2da67..160f90fff 100644 --- a/source/RobotAPI/components/armem/client/CMakeLists.txt +++ b/source/RobotAPI/components/armem/client/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(ExampleMemoryClient) add_subdirectory(GraspProviderExample) +add_subdirectory(MemoryPlotter) add_subdirectory(ObjectInstanceToIndex) add_subdirectory(RobotStatePredictionClientExample) add_subdirectory(SimpleVirtualRobot) diff --git a/source/RobotAPI/components/armem/client/MemoryPlotter/CMakeLists.txt b/source/RobotAPI/components/armem/client/MemoryPlotter/CMakeLists.txt new file mode 100644 index 000000000..401035be3 --- /dev/null +++ b/source/RobotAPI/components/armem/client/MemoryPlotter/CMakeLists.txt @@ -0,0 +1,21 @@ +armarx_component_set_name(MemoryPlotter) + +set(COMPONENT_LIBS + ArmarXCore + ArmarXCoreComponentPlugins + ArmarXGuiComponentPlugins + RobotAPICore RobotAPIInterfaces + armem +) + +set(SOURCES + MemoryPlotter.cpp +) + +set(HEADERS + MemoryPlotter.h +) + +armarx_add_component("${SOURCES}" "${HEADERS}") + +armarx_generate_and_add_component_executable() diff --git a/source/RobotAPI/components/armem/client/MemoryPlotter/MemoryPlotter.cpp b/source/RobotAPI/components/armem/client/MemoryPlotter/MemoryPlotter.cpp new file mode 100644 index 000000000..e442247df --- /dev/null +++ b/source/RobotAPI/components/armem/client/MemoryPlotter/MemoryPlotter.cpp @@ -0,0 +1,106 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::MemoryPlotter + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2023 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "MemoryPlotter.h" + +#include <ArmarXCore/core/time/Frequency.h> +#include <ArmarXCore/core/time/Metronome.h> + +namespace armarx +{ + + armarx::PropertyDefinitionsPtr + MemoryPlotter::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = + new ComponentPropertyDefinitions(getConfigIdentifier()); + + + return defs; + } + + std::string + MemoryPlotter::getDefaultName() const + { + return "MemoryPlotter"; + } + + void + MemoryPlotter::onInitComponent() + { + } + + void + MemoryPlotter::onConnectComponent() + { + createRemoteGuiTab(); + RemoteGui_startRunningTask(); + + task = new RunningTask<MemoryPlotter>(this, &MemoryPlotter::run); + task->start(); + } + + void + MemoryPlotter::onDisconnectComponent() + { + task->stop(); + } + + void + MemoryPlotter::onExitComponent() + { + } + + void + MemoryPlotter::run() + { + Frequency frequency = Frequency::Hertz(30); + Metronome metronome(frequency); + while (not task->isStopped()) + { + metronome.waitForNextTick(); + } + } + + void + MemoryPlotter::createRemoteGuiTab() + { + using namespace armarx::RemoteGui::Client; + + if (tab.queryResult) + { + } + + VBoxLayout root = {tab.queryResultGroup, VSpacer()}; + RemoteGui_createTab(getName(), root, &tab); + } + + void + MemoryPlotter::RemoteGui_update() + { + if (tab.rebuild.exchange(false)) + { + createRemoteGuiTab(); + } + } + +} // namespace armarx diff --git a/source/RobotAPI/components/armem/client/MemoryPlotter/MemoryPlotter.h b/source/RobotAPI/components/armem/client/MemoryPlotter/MemoryPlotter.h new file mode 100644 index 000000000..5e3067985 --- /dev/null +++ b/source/RobotAPI/components/armem/client/MemoryPlotter/MemoryPlotter.h @@ -0,0 +1,99 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::MemoryPlotter + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2023 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <ArmarXCore/core/Component.h> +#include <ArmarXCore/interface/observers/ObserverInterface.h> +#include <ArmarXCore/libraries/ArmarXCoreComponentPlugins/DebugObserverComponentPlugin.h> +#include <ArmarXCore/util/tasks.h> + +#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> + +#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> +#include <RobotAPI/libraries/armem/client/Reader.h> +#include <RobotAPI/libraries/armem/client/plugins/PluginUser.h> +#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> + +namespace armarx +{ + + /** + * @defgroup Component-MemoryPlotter MemoryPlotter + * @ingroup RobotAPI-Components + * + * Transfers data from the memory system to the DebugObserver, allowing to visualize them in + * the LivePlotter. + * + * @class MemoryPlotter + * @ingroup Component-MemoryPlotter + * @brief Implementation of \ref Component-MemoryPlotter. + */ + class MemoryPlotter : + virtual public armarx::Component, + virtual public armarx::armem::ClientPluginUser, + virtual public armarx::DebugObserverComponentPluginUser, + virtual public armarx::LightweightRemoteGuiComponentPluginUser + { + public: + /// @see armarx::ManagedIceObject::getDefaultName() + std::string getDefaultName() const override; + + // LightweightRemoteGuiComponentPluginUser interface + public: + void createRemoteGuiTab(); + void RemoteGui_update() override; + + + protected: + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + + void onInitComponent() override; + void onConnectComponent() override; + void onDisconnectComponent() override; + void onExitComponent() override; + + void run(); + + + private: + struct Properties + { + }; + + Properties p; + + std::map<armem::MemoryID, armem::client::Reader> memoryReaders; + + armarx::RunningTask<MemoryPlotter>::pointer_type task; + + struct RemoteGuiTab : RemoteGui::Client::Tab + { + std::atomic_bool rebuild = false; + + std::optional<armem::wm::Memory> queryResult; + RemoteGui::Client::GroupBox queryResultGroup; + }; + + RemoteGuiTab tab; + }; +} // namespace armarx -- GitLab