diff --git a/source/RobotAPI/components/ArViz/ArVizStorage.cpp b/source/RobotAPI/components/ArViz/ArVizStorage.cpp index 2df6e08e9b7cde6a129f5459091ba1df578ea7b1..24d933cc3653b567235fd3eac80c80ac0720d6bb 100644 --- a/source/RobotAPI/components/ArViz/ArVizStorage.cpp +++ b/source/RobotAPI/components/ArViz/ArVizStorage.cpp @@ -28,6 +28,8 @@ #include <SimoxUtility/json/json.hpp> +#include <iomanip> +#include <optional> namespace armarx { diff --git a/source/RobotAPI/components/ArViz/CMakeLists.txt b/source/RobotAPI/components/ArViz/CMakeLists.txt index e4022f09ab2c719eaaeb7438fbc4a1980ea3f2fd..16442d23b8acbb12446de1f288c3f73dec39092c 100644 --- a/source/RobotAPI/components/ArViz/CMakeLists.txt +++ b/source/RobotAPI/components/ArViz/CMakeLists.txt @@ -10,6 +10,7 @@ set(COMPONENT_LIBS set(SOURCES + Client/Client.cpp Client/Elements.cpp Client/elements/Mesh.cpp Client/elements/Robot.cpp diff --git a/source/RobotAPI/components/ArViz/Client/Client.cpp b/source/RobotAPI/components/ArViz/Client/Client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a049c68ef97d88312c646cbb7cf1a89f04a10f5d --- /dev/null +++ b/source/RobotAPI/components/ArViz/Client/Client.cpp @@ -0,0 +1,56 @@ +#include "Client.h" + +#include <ArmarXCore/core/Component.h> + +namespace armarx::viz +{ + +Client::Client(Component& component, std::string const& topicNameProperty, std::string const& storageNameProperty) +{ + componentName = component.getName(); + component.getTopicFromProperty(topic, topicNameProperty); + + // Optional dependency on ArVizStorage + std::string storageName; + if (component.hasProperty(storageNameProperty)) + { + storageName = component.getProperty<std::string>(storageNameProperty); + } + else + { + storageName = "ArVizStorage"; + } + component.getProxy(storage, storageName, false, "", false); +} + +Client::Client(ManagedIceObject& obj, const std::string& topicName) +{ + componentName = obj.getName(); + obj.getTopic(topic, topicName); +} + +Client Client::createFromTopic(const std::string arvizNamespace, Topic::ProxyType topic) +{ + Client client; + client.componentName = arvizNamespace; + client.topic = topic; + return client; +} + +Client Client::createForGuiPlugin(Component& component, const std::string& topicName) +{ + Client client; + std::string name = component.getName(); + std::size_t dashPos = name.find('-'); + if (dashPos != std::string::npos) + { + name = name.substr(0, dashPos); + } + client.componentName = name; + component.getTopic(client.topic, topicName); + return client; +} + + + +} diff --git a/source/RobotAPI/components/ArViz/Client/Client.h b/source/RobotAPI/components/ArViz/Client/Client.h index f946e02d4298910c72bb4d8a59bf9d64d42ac5ab..53c33e17b0c22445e25dfc1e50c080d46026a2ee 100644 --- a/source/RobotAPI/components/ArViz/Client/Client.h +++ b/source/RobotAPI/components/ArViz/Client/Client.h @@ -5,159 +5,129 @@ #include "Layer.h" -#include <ArmarXCore/core/Component.h> - -namespace armarx::viz +namespace armarx { + class Component; + class ManagedIceObject; - class Client +namespace viz +{ + /** + * A staged commit prepares multiple layers to be committed. + * + * Add all relevant layer updates via .add(layer). + * Add layers for which you want interaction feedback via .requestInteraction(layer). + * Then, commit via client.commit(stagedCommit). + * + * A staged commit can be reused for subsequent commits. + * Remember to call .reset() to clear the internal data structures. + * + * As long as you keep the staged commits separate, this method is thread-safe. + * So you can have two threads calling .commit(A) and .commit(B) + * simultaneously without any locking mechanism. + */ + struct StagedCommit { - public: - Client() = default; - virtual ~Client() = default; - - Client(armarx::Component& component, std::string topicNameProperty = "ArVizTopicName") + /** + * @brief Stage a layer to be committed later via client.commit(*this) + * @param layer The layer to be added to this staged commit. + */ + void add(Layer const& layer) { - componentName = component.getName(); - component.getTopicFromProperty(_topic, topicNameProperty); + data_.updates.push_back(layer.data_); } - Client(ManagedIceObject& obj, const std::string& topicName = "ArVizTopic") + /** + * @brief Request interaction feedback for a particular layer. + * @param layer The layer you want to get interaction feedback for. + */ + void requestInteraction(Layer const& layer) { - componentName = obj.getName(); - obj.getTopic(_topic, topicName); + data_.interactionComponent = layer.data_.component; + data_.interactionLayers.push_back(layer.data_.name); } - static Client createFromTopic(const std::string arvizNamespace, armarx::viz::Topic::ProxyType topic) + /** + * @brief Reset all staged layers and interaction requests. + */ + void reset() { - Client client; - client.componentName = arvizNamespace; - client._topic = topic; - return client; + data_.updates.clear(); + data_.interactionComponent.clear(); + data_.interactionLayers.clear(); } - static Client createForGuiPlugin(armarx::Component& component, std::string const& topicName = "ArVizTopic") - { - Client client; - std::string name = component.getName(); - std::size_t dashPos = name.find('-'); - if (dashPos != std::string::npos) - { - name = name.substr(0, dashPos); - } - client.componentName = name; - component.getTopic(client._topic, topicName); - return client; - } + viz::data::CommitInput data_; + }; - // ////////////////////////////////////////////////////////////////// // - //layer - virtual Layer layer(std::string const& name) const - { - return Layer(componentName, name); - } + struct Client + { + Client() = default; - template<class...Ts> - Layer layerContaining(std::string const& name, Ts&& ...elems) const - { - auto l = layer(name); - l.add(std::forward<Ts>(elems)...); - return l; - } - // ////////////////////////////////////////////////////////////////// // - //enqueue - void enqueueLayer(const Layer& l) - { - updates.emplace_back(l.data_); - } - void enqueueLayer(const Layer* l) - { - updates.emplace_back(l->data_); - } - void enqueueLayer(std::initializer_list<Layer> const& layers) - { - for (const auto& l : layers) - { - enqueueLayer(l); - } - } - void enqueueLayer(const std::vector<const Layer*>& layers) - { - for (const auto& l : layers) - { - enqueueLayer(l); - } - } - void enqueueLayer(const std::vector<Layer>& layers) - { - for (const auto& l : layers) - { - enqueueLayer(l); - } - } - template<class...Ts> - void enqueueLayerContaining(std::string const& name, Ts&& ...elems) - { - enqueueLayer(layerContaining(name, std::forward<Ts>(elems)...)); - } - void enqueueDeleteLayer(std::string const& name) - { - auto l = layer(name); - l.data_.action = data::LayerAction::Layer_DELETE; - enqueueLayer(std::move(l)); - } - // ////////////////////////////////////////////////////////////////// // - //commit + Client(armarx::Component& component, + std::string const& topicNameProperty = "ArVizTopicName", + std::string const& storageNameProperty = "ArVizStorageName"); - void commit(std::initializer_list<Layer> const& layers) + Client(ManagedIceObject& obj, const std::string& topicName = "ArVizTopic"); + + static Client createFromTopic(const std::string arvizNamespace, armarx::viz::Topic::ProxyType topic); + + static Client createForGuiPlugin(armarx::Component& component, std::string const& topicName = "ArVizTopic"); + + Layer layer(std::string const& name) const { - enqueueLayer(layers); - commit(); + return Layer(componentName, name); } - void commit(const std::vector<const Layer*>& layers) + StagedCommit stage() { - enqueueLayer(layers); - commit(); + return StagedCommit(); } - void commit(const std::vector<Layer>& layers) + void apply(StagedCommit const& commit) { - enqueueLayer(layers); - commit(); + // TODO: Implement } - template<class...Ts> - void - commit(Ts&& ...ts) + void commit(std::vector<Layer> const& layers) { - (enqueueLayer(std::forward<Ts>(ts)), ...); - _topic->updateLayers(updates); - updates.clear(); + data::LayerUpdateSeq updates; + updates.reserve(layers.size()); + for (Layer const& layer : layers) + { + updates.push_back(layer.data_); + } + // This commit call still uses the legacy topic API + topic->updateLayers(updates); } - template<class...Ts> - void commitLayerContaining(std::string const& name, Ts&& ...elems) + template <typename ElementT> + void commitLayerContaining(std::string const& name, ElementT const& element = nullptr) { - commit(layerContaining(name, std::forward<Ts>(elems)...)); + std::vector<viz::Layer> layers; + viz::Layer& newLayer = layers.emplace_back(this->layer(name)); + if (element != nullptr) + { + newLayer.add(element); + } + commit(layers); } void commitDeleteLayer(std::string const& name) { - enqueueDeleteLayer(name); - commit(); + std::vector<viz::Layer> layers; + viz::Layer& layerToDelete = layers.emplace_back(this->layer(name)); + layerToDelete.markForDeletion(); + commit(layers); } - const armarx::viz::TopicPrx& topic() const - { - return _topic; - } private: std::string componentName; - armarx::viz::TopicPrx _topic; - + armarx::viz::StorageInterfacePrx storage; + armarx::viz::TopicPrx topic; data::LayerUpdateSeq updates; }; } +} diff --git a/source/RobotAPI/components/ArViz/Client/Layer.h b/source/RobotAPI/components/ArViz/Client/Layer.h index 27e056d78eb767637ab9b7a96951c01e3035e902..ef9b0fef855eb89f9151717694a1a2c33517d108 100644 --- a/source/RobotAPI/components/ArViz/Client/Layer.h +++ b/source/RobotAPI/components/ArViz/Client/Layer.h @@ -31,19 +31,18 @@ namespace armarx::viz data_.elements.push_back(element.data_); } - template <typename ElementT> - void add(std::vector<ElementT> const& elements) - { - for (const auto& e : elements) - { - add(e); - } - } - - template<class...Ts> - std::enable_if_t < sizeof...(Ts) != 1 > add(Ts&& ...elems) +// template <typename ElementT> +// void add(std::vector<ElementT> const& elements) +// { +// for (ElementT const& e : elements) +// { +// add(e); +// } +// } + + void markForDeletion() { - (add(std::forward<Ts>(elems)), ...); + data_.action = data::LayerAction::Layer_DELETE; } std::size_t size() const noexcept diff --git a/source/RobotAPI/components/ArViz/Client/ScopedClient.h b/source/RobotAPI/components/ArViz/Client/ScopedClient.h index 4a799efda714e8850f23e3cac7ecaad995c28119..28969ed9fed88eb4ec3fc36ad271ac496dd9b9e7 100644 --- a/source/RobotAPI/components/ArViz/Client/ScopedClient.h +++ b/source/RobotAPI/components/ArViz/Client/ScopedClient.h @@ -45,11 +45,11 @@ namespace armarx::viz using Client::Client; ScopedClient(const Client& client); - Layer layer(std::string const& name) const override; + Layer layer(std::string const& name) const; virtual ~ScopedClient(); private: mutable std::set<std::string> layers; }; -} // namespace armarx::viz \ No newline at end of file +} // namespace armarx::viz diff --git a/source/RobotAPI/components/ArViz/Client/drawer/ArVizDrawerBase.cpp b/source/RobotAPI/components/ArViz/Client/drawer/ArVizDrawerBase.cpp index 9d2c8e7ed36b6a494556ecdd55e652aea93b7e77..1dc87da8eda2a1d6507c9e6bdf56c82dd88a20c9 100644 --- a/source/RobotAPI/components/ArViz/Client/drawer/ArVizDrawerBase.cpp +++ b/source/RobotAPI/components/ArViz/Client/drawer/ArVizDrawerBase.cpp @@ -22,13 +22,13 @@ namespace armarx void ArVizDrawerBase::commit(const viz::Layer& layer) { - std::lock_guard guard{layerMtx}; - arvizClient.commit(layer); + // std::lock_guard guard{layerMtx}; + arvizClient.commit({layer}); } void ArVizDrawerBase::commit(const std::vector<viz::Layer>& layers) { - std::lock_guard guard{layerMtx}; + // std::lock_guard guard{layerMtx}; arvizClient.commit(layers); } diff --git a/source/RobotAPI/components/ArViz/Client/drawer/ArVizDrawerBase.h b/source/RobotAPI/components/ArViz/Client/drawer/ArVizDrawerBase.h index e302acc5c27e025aac9c103793f7a5ed726d76d9..fffd7fbb5f470428978409ff4ad88640f43a7ec8 100644 --- a/source/RobotAPI/components/ArViz/Client/drawer/ArVizDrawerBase.h +++ b/source/RobotAPI/components/ArViz/Client/drawer/ArVizDrawerBase.h @@ -58,7 +58,8 @@ namespace armarx private: viz::ScopedClient arvizClient; - std::mutex layerMtx; + // Mutex is no longer necessary ==> This class can be removed! + // std::mutex layerMtx; }; } // namespace armarx diff --git a/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp b/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp index 2cef2e309bc535edee1f5b86194a002e90fd59ed..df75428333532a8975f4a142700d08c41ac13b90 100644 --- a/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp +++ b/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp @@ -561,23 +561,23 @@ namespace armarx { viz::Layer permanentLayer = arviz.layer("Permanent"); fillPermanentLayer(permanentLayer); - arviz.commit(permanentLayer); + arviz.commit({permanentLayer}); } bool manyElements = getProperty<bool>("layers.ManyElements"); if (manyElements) { viz::Layer manyElementsLayer = arviz.layer("ManyElements"); fillManyElementsLayer(manyElementsLayer, 0); - arviz.commit(manyElementsLayer); + arviz.commit({manyElementsLayer}); } { viz::Layer colorMapsLayer = arviz.layer("ColorMaps"); fillColorMapsLayer(colorMapsLayer, 0); - arviz.commit(colorMapsLayer); + arviz.commit({colorMapsLayer}); } fillInteractionLayer(interactionLayer); - arviz.commit(interactionLayer); + arviz.commit({interactionLayer}); CycleUtil c(20); diff --git a/source/RobotAPI/components/DebugDrawer/DebugDrawerHelper.h b/source/RobotAPI/components/DebugDrawer/DebugDrawerHelper.h index c5c4c52b6d430a4715f83893346ec7fa1acb1706..72a4ee76f56373b6e03697b76a9c45e07a3816dd 100644 --- a/source/RobotAPI/components/DebugDrawer/DebugDrawerHelper.h +++ b/source/RobotAPI/components/DebugDrawer/DebugDrawerHelper.h @@ -124,7 +124,7 @@ namespace armarx class DebugDrawerHelper : public armarx::detail::DebugDrawerHelper::FrameView { using FrameView = armarx::detail::DebugDrawerHelper::FrameView; - friend class FrameView; + friend class armarx::detail::DebugDrawerHelper::FrameView; public: struct Defaults { diff --git a/source/RobotAPI/components/DebugDrawerToArViz/DebugDrawerToArViz.cpp b/source/RobotAPI/components/DebugDrawerToArViz/DebugDrawerToArViz.cpp index 4ac857086a55e5ec19b709ca00dcd24f2b23a574..f3417d30644acd9540aa8c1f888a77c49290a225 100644 --- a/source/RobotAPI/components/DebugDrawerToArViz/DebugDrawerToArViz.cpp +++ b/source/RobotAPI/components/DebugDrawerToArViz/DebugDrawerToArViz.cpp @@ -21,13 +21,13 @@ */ #include "DebugDrawerToArViz.h" - -#include <SimoxUtility/math/pose/pose.h> -#include <SimoxUtility/color/interpolation.h> +#include "BlackWhitelistUpdate.h" #include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <ArmarXCore/core/logging/Logging.h> -#include "BlackWhitelistUpdate.h" +#include <SimoxUtility/color/interpolation.h> +#include <SimoxUtility/math/pose/pose.h> #define FUNCTION_NOT_IMPLEMENTED_MESSAGE \ @@ -180,7 +180,7 @@ namespace armarx setLayerElement(layer, viz::Polygon(ss.str()).addPoint(toEigen(p1)).addPoint(toEigen(p2)) .lineColor(color).lineWidth(lineSet.lineWidth).color(simox::Color::black(0))); } - arviz.commit(layer); + arviz.commit({layer}); } void DebugDrawerToArViz::setBoxVisu(const std::string& layer, const std::string& name, const PoseBasePtr& globalPose, const Vector3BasePtr& dimensions, const DrawColor& color, const Ice::Current&) @@ -390,7 +390,7 @@ namespace armarx viz::Robot& robot = it->second; robot.pose(toEigen(globalPose)); } - arviz.commit(getLayer(layer)); + arviz.commit({getLayer(layer)}); } void DebugDrawerToArViz::updateRobotConfig(const std::string& layer, const std::string& name, const NameValueMap& configuration, const Ice::Current&) @@ -405,7 +405,7 @@ namespace armarx viz::Robot& robot = it->second; robot.joints(configuration); } - arviz.commit(getLayer(layer)); + arviz.commit({getLayer(layer)}); } void DebugDrawerToArViz::updateRobotColor(const std::string& layer, const std::string& name, const DrawColor& color, const Ice::Current&) @@ -420,7 +420,7 @@ namespace armarx viz::Robot& robot = it->second; robot.overrideColor(toViz(color)); } - arviz.commit(getLayer(layer)); + arviz.commit({getLayer(layer)}); } void DebugDrawerToArViz::updateRobotNodeColor(const std::string& layer, const std::string& name, const std::string& robotNodeName, const DrawColor& color, const Ice::Current&) @@ -675,12 +675,12 @@ namespace armarx { std::scoped_lock lock(mutex); - std::vector<const viz::Layer*> commit; + std::vector<viz::Layer> commit; commit.reserve(layers.size()); for (auto& [name, layer] : layers) { layer.clear(); - commit.push_back(&layer); + commit.push_back(layer); } arviz.commit(commit); } @@ -690,7 +690,7 @@ namespace armarx viz::Layer layer = getLayer(layerName); layer.clear(); - arviz.commit(layer); + arviz.commit({layer}); } void DebugDrawerToArViz::clearDebugLayer(const Ice::Current&) { @@ -802,7 +802,7 @@ namespace armarx { viz::Layer& layer = getLayer(layerName); removeLayerElement(layer, name); - arviz.commit(layer); + arviz.commit({layer}); } } diff --git a/source/RobotAPI/components/DebugDrawerToArViz/DebugDrawerToArViz.h b/source/RobotAPI/components/DebugDrawerToArViz/DebugDrawerToArViz.h index f4ce170c84fb0ce7507a8e87bf2901b53d3b7d89..38e66882d00f87ee17e55e76699b943be51d66c6 100644 --- a/source/RobotAPI/components/DebugDrawerToArViz/DebugDrawerToArViz.h +++ b/source/RobotAPI/components/DebugDrawerToArViz/DebugDrawerToArViz.h @@ -187,7 +187,7 @@ namespace armarx { viz::Layer& layer = getLayer(layerName); setLayerElement(layer, element); - arviz.commit(layer); + arviz.commit({layer}); } void removeLayerElement(viz::Layer& layer, const std::string& name); diff --git a/source/RobotAPI/components/DynamicObstacleManager/DynamicObstacleManager.cpp b/source/RobotAPI/components/DynamicObstacleManager/DynamicObstacleManager.cpp index 6ca25b01ef9eb704a2f29140e54e6e602c8b32b6..61497d62d399adf6f1c89a0a0de1c544a902ec51 100644 --- a/source/RobotAPI/components/DynamicObstacleManager/DynamicObstacleManager.cpp +++ b/source/RobotAPI/components/DynamicObstacleManager/DynamicObstacleManager.cpp @@ -269,7 +269,7 @@ namespace armarx while (current_distance < distance_to_goal) { - for (const auto man_obstacle : m_managed_obstacles) + for (const auto& man_obstacle : m_managed_obstacles) { Eigen::Vector2f sample = agentPosition + ((goal - agentPosition).normalized() * current_distance); Eigen::Vector2f sample_left = sample + (orthogonal_normalized * 250); diff --git a/source/RobotAPI/components/DynamicObstacleManager/ManagedObstacle.h b/source/RobotAPI/components/DynamicObstacleManager/ManagedObstacle.h index 5dd70f211733cc61469a0d8b2be38f242b3307ff..a730c63ab96362386781388d65f426217b328721 100644 --- a/source/RobotAPI/components/DynamicObstacleManager/ManagedObstacle.h +++ b/source/RobotAPI/components/DynamicObstacleManager/ManagedObstacle.h @@ -30,6 +30,7 @@ #include <shared_mutex> #include <string> #include <vector> +#include <memory> // Eigen #include <Eigen/Geometry> diff --git a/source/RobotAPI/components/KITProstheticHandUnit/KITProstheticHandUnit.cpp b/source/RobotAPI/components/KITProstheticHandUnit/KITProstheticHandUnit.cpp index 997be9e96b87d88593d27fd7120f332a21912b05..906fc21433a7e5f6f6aec6898da7d55c6667e2cd 100644 --- a/source/RobotAPI/components/KITProstheticHandUnit/KITProstheticHandUnit.cpp +++ b/source/RobotAPI/components/KITProstheticHandUnit/KITProstheticHandUnit.cpp @@ -147,7 +147,7 @@ namespace armarx { ARMARX_CHECK_NOT_NULL(_driver); - for (const std::pair<std::string, float>& pair : targetJointAngles) + for (const auto& pair : targetJointAngles) { if (pair.first == "Fingers") { diff --git a/source/RobotAPI/components/ObjectPoseClientExample/ObjectPoseClientExample.cpp b/source/RobotAPI/components/ObjectPoseClientExample/ObjectPoseClientExample.cpp index b6d5c668ecd0ad66bf47036d1b300efa9e814803..43f32295717ff031d2ac9b6f54184c21b8c60e73 100644 --- a/source/RobotAPI/components/ObjectPoseClientExample/ObjectPoseClientExample.cpp +++ b/source/RobotAPI/components/ObjectPoseClientExample/ObjectPoseClientExample.cpp @@ -89,7 +89,7 @@ namespace armarx .fileByObjectFinder(objectPose.objectID) .alpha(objectPose.confidence)); } - arviz.commit(layer); + arviz.commit({layer}); } cycle.waitForCycleDuration(); diff --git a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h index a6cf94b3a961e53c179c14132e5d3aaa3a11ba5b..7e83132236f7478cf9570747a6c0e83add0e1fab 100644 --- a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h +++ b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h @@ -3,6 +3,7 @@ #include <memory> +#include <ArmarXCore/core/Component.h> #include <ArmarXCore/interface/observers/ObserverInterface.h> #include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> #include <RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h> diff --git a/source/RobotAPI/components/units/GraspCandidateObserver.cpp b/source/RobotAPI/components/units/GraspCandidateObserver.cpp index 8b3f0299ee9732265b757d6c5b375a08e72d554b..e780bbfe388f6e484673bbd44d5cc7c3bf5f0570 100644 --- a/source/RobotAPI/components/units/GraspCandidateObserver.cpp +++ b/source/RobotAPI/components/units/GraspCandidateObserver.cpp @@ -185,7 +185,7 @@ GraspCandidateSeq GraspCandidateObserver::getAllCandidates(const Ice::Current&) { std::unique_lock lock(dataMutex); GraspCandidateSeq all; - for (const std::pair<std::string, grasping::GraspCandidateSeq>& pair : candidates) + for (const auto& pair : candidates) { all.insert(all.end(), pair.second.begin(), pair.second.end()); } @@ -215,7 +215,7 @@ GraspCandidateSeq GraspCandidateObserver::getCandidatesByFilter(const CandidateF { std::unique_lock lock(dataMutex); GraspCandidateSeq matching; - for (const std::pair<std::string, grasping::GraspCandidateSeq>& pair : candidates) + for (const auto& pair : candidates) { for (const grasping::GraspCandidatePtr& candidate : pair.second) { @@ -268,7 +268,7 @@ BimanualGraspCandidateSeq GraspCandidateObserver::getAllBimanualCandidates(const { std::unique_lock lock(dataMutex); BimanualGraspCandidateSeq all; - for (const std::pair<std::string, grasping::BimanualGraspCandidateSeq>& pair : bimanualCandidates) + for (const auto& pair : bimanualCandidates) { all.insert(all.end(), pair.second.begin(), pair.second.end()); } @@ -311,7 +311,7 @@ void GraspCandidateObserver::checkHasProvider(const std::string& providerName) StringSeq GraspCandidateObserver::getAvailableProviderNames() { StringSeq names; - for (const std::pair<std::string, ProviderInfoPtr>& pair : providers) + for (const auto& pair : providers) { names.push_back(pair.first); } diff --git a/source/RobotAPI/components/units/RobotUnit/NJointControllers/GazeController.cpp b/source/RobotAPI/components/units/RobotUnit/NJointControllers/GazeController.cpp index daacae417637d89a1a4d23a79a6a4668d196b69d..1a545e067effa40daed3e05b5c34dda4c8f851a9 100644 --- a/source/RobotAPI/components/units/RobotUnit/NJointControllers/GazeController.cpp +++ b/source/RobotAPI/components/units/RobotUnit/NJointControllers/GazeController.cpp @@ -200,7 +200,8 @@ namespace armarx void GazeController::removeTargetAfter(long durationMilliSeconds, const Ice::Current&) { - std::async(std::launch::async, [](long durationMilliSeconds, GazeController * self) + // TODO: This probably does not run async, as a future associated with std::async waits on destruction + auto void_f = std::async(std::launch::async, [](long durationMilliSeconds, GazeController * self) -> void { std::this_thread::sleep_for(std::chrono::milliseconds(durationMilliSeconds)); self->removeTarget(); diff --git a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointTaskSpaceImpedanceController.h b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointTaskSpaceImpedanceController.h index 7ed79a0b5f833864eedf06900548b37fa1e6b780..f23c8a04945858b9efdb071f1c5215b719073be0 100644 --- a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointTaskSpaceImpedanceController.h +++ b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointTaskSpaceImpedanceController.h @@ -72,7 +72,7 @@ namespace armarx void setPositionOrientation(const Eigen::Vector3f& pos, const Eigen::Quaternionf& ori, const Ice::Current&) override; void setPose(const Eigen::Matrix4f& mat, const Ice::Current&) override; - void setImpedanceParameters(const std::string&, const Ice::FloatSeq&, const Ice::Current&); + void setImpedanceParameters(const std::string&, const Ice::FloatSeq&, const Ice::Current&) override; void setNullspaceConfig(const Eigen::VectorXf& joint, const Eigen::VectorXf& knull, const Eigen::VectorXf& dnull, const Ice::Current&) override; void setConfig(const NJointTaskSpaceImpedanceControlRuntimeConfig& cfg, const Ice::Current&) override; diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleLogging.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleLogging.h index 975979177d45d71530317ea6f282929d72f6924c..add2ad5c7c23515351db4b7a9cb2f05f5dfffc6d 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleLogging.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleLogging.h @@ -300,5 +300,11 @@ namespace armarx::RobotUnitModule std::size_t rtLoggingTimestepMs {0}; /// @brief The time an entry shold remain in the backlog. IceUtil::Time rtLoggingBacklogRetentionTime; + + friend void WriteTo(const auto& dentr, + const Logging::DataStreamingEntry::OutVal& out, + const auto& val, + std::size_t fidx, + auto& data); }; } diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleSelfCollisionChecker.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleSelfCollisionChecker.cpp index e65e6506a5312346f4409f68a09880c3aa77b939..a9d2e8de69625147071a2e2aaa650d43de40cdb9 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleSelfCollisionChecker.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleSelfCollisionChecker.cpp @@ -293,7 +293,7 @@ namespace armarx::RobotUnitModule //check for all nodes 0 { bool allJoints0 = true; - for (const VirtualRobot::RobotNodePtr node : selfCollisionAvoidanceRobotNodes) + for (const auto& node : selfCollisionAvoidanceRobotNodes) { if (0 != node->getJointValue()) { diff --git a/source/RobotAPI/components/units/RobotUnit/util/HeterogenousContinuousContainer.h b/source/RobotAPI/components/units/RobotUnit/util/HeterogenousContinuousContainer.h index 3a98c100b79bef43a55b1dd12475a41c8016c5b5..8539b52e860fc21b785fad49e6d1a0c342c92ae1 100644 --- a/source/RobotAPI/components/units/RobotUnit/util/HeterogenousContinuousContainer.h +++ b/source/RobotAPI/components/units/RobotUnit/util/HeterogenousContinuousContainer.h @@ -30,7 +30,7 @@ #include "HeterogenousContinuousContainerMacros.h" -#if __GNUC__< 5 +#if __GNUC__< 5 && !defined(__clang__) namespace std { inline void* align(size_t alignment, size_t bytes, void*& bufferPlace, size_t& bufferSpace) noexcept diff --git a/source/RobotAPI/gui-plugins/ArVizDrawerGui/ArVizDrawerGuiWidgetController.cpp b/source/RobotAPI/gui-plugins/ArVizDrawerGui/ArVizDrawerGuiWidgetController.cpp index defcb3362d6c038761389b87215cc149c5a061d9..090a2c7e47eeb7647b955dc69b166d9aa97b2c05 100644 --- a/source/RobotAPI/gui-plugins/ArVizDrawerGui/ArVizDrawerGuiWidgetController.cpp +++ b/source/RobotAPI/gui-plugins/ArVizDrawerGui/ArVizDrawerGuiWidgetController.cpp @@ -84,7 +84,7 @@ namespace armarx elem->addTo(layer); } } - getArvizClient().commit(layer); + getArvizClient().commit({layer}); } } diff --git a/source/RobotAPI/gui-plugins/BoxToGraspCandidates/BoxToGraspCandidatesWidgetController.cpp b/source/RobotAPI/gui-plugins/BoxToGraspCandidates/BoxToGraspCandidatesWidgetController.cpp index 27cb74dadea8b121431466d39e4633d94832a3d6..1e8b97c14c4d086336373c19dfcd59aff13e4ca9 100644 --- a/source/RobotAPI/gui-plugins/BoxToGraspCandidates/BoxToGraspCandidatesWidgetController.cpp +++ b/source/RobotAPI/gui-plugins/BoxToGraspCandidates/BoxToGraspCandidatesWidgetController.cpp @@ -296,10 +296,14 @@ namespace armarx side_enabled_r[ba::neg_z_neg_y] = _ui.checkBoxGraspRNegZNegY->isChecked(); } - auto layer_l = getArvizClient().layer("grasps_l"); - auto layer_r = getArvizClient().layer("grasps_r"); - auto layer_hand_vec = getArvizClient().layer("hand_vec"); - getArvizClient().enqueueLayerContaining("box", viz::Box{"box"}.set(box).transformPose(_robot->getGlobalPose())); + viz::Layer layer_l = arviz.layer("grasps_l"); + viz::Layer layer_r = arviz.layer("grasps_r"); + viz::Layer layer_hand_vec = arviz.layer("hand_vec"); + viz::Layer layer_box = arviz.layer("box"); + layer_box.add(viz::Box{"box"} + .set(box) + .transformPose(_robot->getGlobalPose()) + ); gc_draw.draw(b2gc.side("Left"), layer_hand_vec); gc_draw.draw(b2gc.side("Right"), layer_hand_vec); @@ -318,7 +322,7 @@ namespace armarx b2gc.center_grasps(box, "Left", lim, consume_l, side_enabled_l); b2gc.center_grasps(box, "Right", lim, consume_r, side_enabled_r); - getArvizClient().commit(layer_l, layer_r, layer_hand_vec); + arviz.commit({layer_l, layer_r, layer_hand_vec, layer_box}); _gc_topic->reportGraspCandidates(getName(), graps); } diff --git a/source/RobotAPI/gui-plugins/ObjectPoseGui/ObjectPoseGuiWidgetController.cpp b/source/RobotAPI/gui-plugins/ObjectPoseGui/ObjectPoseGuiWidgetController.cpp index c5f588adf750b8b2eda12375c798b7d80c741dfa..68fbc7165c7d318cf68990f779c074d2f9e12cd4 100644 --- a/source/RobotAPI/gui-plugins/ObjectPoseGui/ObjectPoseGuiWidgetController.cpp +++ b/source/RobotAPI/gui-plugins/ObjectPoseGui/ObjectPoseGuiWidgetController.cpp @@ -357,7 +357,7 @@ namespace armarx QAction* attachAgentAction = new QAction(QString::fromStdString(frame), tree); // attachAgentAction->setStatusTip(tr("Attach object rigidly to a robot node")); connect(attachAgentAction, &QAction::triggered, - [ = ]() + [ =, this ]() { this->attachObjectToRobotNode(providerName, objectID, agentFrames.agent, frame); }); @@ -368,7 +368,7 @@ namespace armarx QAction* detachAction = new QAction(tr("Detach from to robot node"), tree); detachAction->setEnabled(!item->text(OBJECTS_COLUMN_ATTACHMENT).isEmpty()); - connect(detachAction, &QAction::triggered, [ = ]() + connect(detachAction, &QAction::triggered, [ =, this ]() { this->detachObjectFromRobotNode(providerName, objectID); }); diff --git a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp index 92a5760ae47f099c3408606903efb25db007f764..4b61a29ecf41a7af19336ccdc81d30c7dc32189a 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp +++ b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp @@ -75,19 +75,19 @@ namespace armarx } // Search for object in datasets. const std::vector<std::string>& datasets = getDatasets(); - for (const std::string& dataset : datasets) + for (const std::string& ds : datasets) { - if (fs::is_directory(_rootDirAbs() / dataset / name)) + if (fs::is_directory(_rootDirAbs() / ds / name)) { - return ObjectInfo(packageName, absPackageDataDir, relObjectsDir, dataset, name); + return ObjectInfo(packageName, absPackageDataDir, relObjectsDir, ds, name); } } std::stringstream ss; ss << "Did not find object '" << name << "' in any of these datasets:\n"; - for (const path& dataset : datasets) + for (const auto& ds : datasets) { - ss << "- " << dataset << "\n"; + ss << "- " << ds << "\n"; } ss << "Objects root directory: " << _rootDirAbs(); ARMARX_VERBOSE << ss.str(); diff --git a/source/RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h b/source/RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h index 6ce746eddb21cf676150d615cb2d9d57f2211d13..b55213a1a07b1403ca2375187284cd4a5ccecdb4 100644 --- a/source/RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h +++ b/source/RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h @@ -46,10 +46,6 @@ namespace armarx armarx::viz::Client& getArvizClient() { - if (!arviz.topic()) - { - arviz = createArVizClient(); - } return arviz; } diff --git a/source/RobotAPI/libraries/RobotAPIComponentPlugins/CMakeLists.txt b/source/RobotAPI/libraries/RobotAPIComponentPlugins/CMakeLists.txt index ea00db45e6987b2df3fd021abf71cbd95d1e6a37..100088eb3f98b6b37ce669b7830d60b20587f59a 100644 --- a/source/RobotAPI/libraries/RobotAPIComponentPlugins/CMakeLists.txt +++ b/source/RobotAPI/libraries/RobotAPIComponentPlugins/CMakeLists.txt @@ -9,6 +9,7 @@ set(LIBS diffik RobotStatechartHelpers RobotUnitDataStreamingReceiver + ArViz ) set(LIB_FILES diff --git a/source/RobotAPI/libraries/RobotStatechartHelpers/RobotNameHelper.cpp b/source/RobotAPI/libraries/RobotStatechartHelpers/RobotNameHelper.cpp index d256ee202c02d8ebf204455afa241731557815c8..57a714eacc92f1243dcd31d30ea08b1d48648dc0 100644 --- a/source/RobotAPI/libraries/RobotStatechartHelpers/RobotNameHelper.cpp +++ b/source/RobotAPI/libraries/RobotStatechartHelpers/RobotNameHelper.cpp @@ -48,7 +48,7 @@ namespace armarx return; } str << ind << n->name << ", profile = " << n->profile << ", value " << n->value << '\n'; - for (const auto c : n->children) + for (const auto& c : n->children) { writeRobotInfoNode(c, str, indent + 1); } diff --git a/source/RobotAPI/libraries/RobotStatechartHelpers/RobotNameHelper.h b/source/RobotAPI/libraries/RobotStatechartHelpers/RobotNameHelper.h index 65fbc12c2b037ab7b1f7e9101d651e2592e168aa..1c40eac0d8c07c476129e0e852f4e29f57d20144 100644 --- a/source/RobotAPI/libraries/RobotStatechartHelpers/RobotNameHelper.h +++ b/source/RobotAPI/libraries/RobotStatechartHelpers/RobotNameHelper.h @@ -103,7 +103,7 @@ namespace armarx struct RobotArm { friend class RobotNameHelper; - friend class Arm; + friend struct Arm; public: std::string getSide() const; VirtualRobot::RobotNodeSetPtr getKinematicChain() const; diff --git a/source/RobotAPI/libraries/SimpleJsonLogger/SimpleJsonLoggerEntry.cpp b/source/RobotAPI/libraries/SimpleJsonLogger/SimpleJsonLoggerEntry.cpp index 75096ffed0c58eb6b98245f21ded0d2a81e23109..ecf7f69cdc41df7319c29a9fac28aa0362724a8d 100644 --- a/source/RobotAPI/libraries/SimpleJsonLogger/SimpleJsonLoggerEntry.cpp +++ b/source/RobotAPI/libraries/SimpleJsonLogger/SimpleJsonLoggerEntry.cpp @@ -109,7 +109,7 @@ namespace armarx JsonObjectPtr SimpleJsonLoggerEntry::ToObj(const std::map<std::string, float>& value) { JsonObjectPtr obj(new JsonObject); - for (const std::pair<std::string, float>& pair : value) + for (const auto& pair : value) { obj->add(pair.first, JsonValue::Create(pair.second)); } diff --git a/source/RobotAPI/libraries/armem_objects/server/class/FloorVis.cpp b/source/RobotAPI/libraries/armem_objects/server/class/FloorVis.cpp index cb0088285ca161ddc9283f3a024b65a86809fb1b..f0be74213236e8cc13ea2eb0716bcdff98065ff8 100644 --- a/source/RobotAPI/libraries/armem_objects/server/class/FloorVis.cpp +++ b/source/RobotAPI/libraries/armem_objects/server/class/FloorVis.cpp @@ -43,7 +43,7 @@ namespace armarx::armem::server::obj::clazz ARMARX_INFO << "Did not find floor class '" << properties.entityName << "'."; } } - arviz.commit(layer); + arviz.commit({layer}); } diff --git a/source/RobotAPI/libraries/armem_objects/server/class/Segment.cpp b/source/RobotAPI/libraries/armem_objects/server/class/Segment.cpp index 8b1ae942a95b73119eea072b7f33a539a05fbbdf..7c032c40a0a42914a9810a64b41e5d6b958feef7 100644 --- a/source/RobotAPI/libraries/armem_objects/server/class/Segment.cpp +++ b/source/RobotAPI/libraries/armem_objects/server/class/Segment.cpp @@ -167,7 +167,7 @@ namespace armarx::armem::server::obj::clazz } } - arviz.commit(layerObject, layerOrigin, layerAABB, layerOOBB); + arviz.commit({layerObject, layerOrigin, layerAABB, layerOOBB}); } diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/RobotHeadMovement.h b/source/RobotAPI/libraries/armem_objects/server/instance/RobotHeadMovement.h index 5a731720c49fdb33749edab4ca4c9792eedc0599..b6b0acb6da46d593f2da2677e9e7258ce6d7e0c2 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/RobotHeadMovement.h +++ b/source/RobotAPI/libraries/armem_objects/server/instance/RobotHeadMovement.h @@ -2,6 +2,7 @@ #include <string> #include <vector> +#include <optional> #include <IceUtil/Time.h> diff --git a/source/RobotAPI/libraries/aron/core/data/rw/Writer.h b/source/RobotAPI/libraries/aron/core/data/rw/Writer.h index 7482b13b6ab19f1ca5ef38087e1417a8b1479d56..0461a50fcb25567f4df2315e86f44dba2f5e343d 100644 --- a/source/RobotAPI/libraries/aron/core/data/rw/Writer.h +++ b/source/RobotAPI/libraries/aron/core/data/rw/Writer.h @@ -23,6 +23,7 @@ // STD/STL #include <memory> #include <string> +#include <optional> // ArmarX #include <RobotAPI/interface/aron.h> diff --git a/source/RobotAPI/libraries/aron/core/type/rw/Writer.h b/source/RobotAPI/libraries/aron/core/type/rw/Writer.h index e0f0620a491c120090be226712b5e1e8e9d55411..471b145503c02021a92cee6ba8e1e1599a22d6c5 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/Writer.h +++ b/source/RobotAPI/libraries/aron/core/type/rw/Writer.h @@ -23,6 +23,7 @@ // STD/STL #include <memory> #include <string> +#include <optional> // ArmarX #include <RobotAPI/interface/aron.h> diff --git a/source/RobotAPI/libraries/aron/core/typereader/xml/Data.h b/source/RobotAPI/libraries/aron/core/typereader/xml/Data.h index 2fdda0b29d766300ae6364bdacf3ab3a855614a3..34fc92ef71afbfa4bee417ebe4cb1d3f4c47cc39 100644 --- a/source/RobotAPI/libraries/aron/core/typereader/xml/Data.h +++ b/source/RobotAPI/libraries/aron/core/typereader/xml/Data.h @@ -26,6 +26,7 @@ // STD/STL #include <memory> #include <map> +#include <optional> // ArmarX #include <SimoxUtility/xml.h> diff --git a/source/RobotAPI/libraries/core/FramedOrientedPoint.cpp b/source/RobotAPI/libraries/core/FramedOrientedPoint.cpp index fa5ea9fe7c8ba2e5dab6ea7a8020c47d1e605070..67391514fcba1a51f62ab4488aa1d5f4d54a4a1e 100644 --- a/source/RobotAPI/libraries/core/FramedOrientedPoint.cpp +++ b/source/RobotAPI/libraries/core/FramedOrientedPoint.cpp @@ -34,6 +34,7 @@ namespace armarx FramedOrientedPoint::FramedOrientedPoint(const FramedOrientedPoint& source) : IceUtil::Shared(source), + armarx::Serializable(source), OrientedPointBase(source), FramedOrientedPointBase(source), OrientedPoint(source) diff --git a/source/RobotAPI/libraries/core/FramedPose.cpp b/source/RobotAPI/libraries/core/FramedPose.cpp index c5e4d774bf02fdb78bb84c6bb4253bdec6713679..3399214dc4957654f5e8cdefa76a99bdee29640f 100644 --- a/source/RobotAPI/libraries/core/FramedPose.cpp +++ b/source/RobotAPI/libraries/core/FramedPose.cpp @@ -50,6 +50,7 @@ namespace armarx FramedDirection::FramedDirection(const FramedDirection& source) : IceUtil::Shared(source), + armarx::Serializable(source), Vector3Base(source), FramedDirectionBase(source), Vector3(source) @@ -282,6 +283,8 @@ namespace armarx FramedPose::FramedPose(const FramedPose& pose) : IceUtil::Shared(pose), + armarx::Serializable(pose), + armarx::VariantDataClass(pose), PoseBase(pose), FramedPoseBase(pose), Pose(pose) diff --git a/source/RobotAPI/libraries/core/FramedPose.h b/source/RobotAPI/libraries/core/FramedPose.h index 601dc48bbb5df213edf8abbad0cf19bb487ae0b6..27a04fccb69d3b8bf89d91a4e33c45d0d0b36885 100644 --- a/source/RobotAPI/libraries/core/FramedPose.h +++ b/source/RobotAPI/libraries/core/FramedPose.h @@ -156,6 +156,7 @@ namespace armarx //FramedPosition(const Vector3BasePtr pos, const std::string &frame ); // this doesnt work for unknown reasons FramedPosition(const FramedPosition& other): Shared(other), + armarx::Serializable(other), Vector3Base(other.x, other.y, other.z), FramedPositionBase(other.x, other.y, other.z, other.frame, other.agent), Vector3(other.x, other.y, other.z) diff --git a/source/RobotAPI/libraries/core/LinkedPose.cpp b/source/RobotAPI/libraries/core/LinkedPose.cpp index 10b93907b5873f521378987329895c1a7033a960..4a4d285d97a3001b2d5d3eb1ab504604809806c6 100644 --- a/source/RobotAPI/libraries/core/LinkedPose.cpp +++ b/source/RobotAPI/libraries/core/LinkedPose.cpp @@ -48,6 +48,8 @@ namespace armarx LinkedPose::LinkedPose(const LinkedPose& other) : IceUtil::Shared(other), + armarx::Serializable(other), + armarx::VariantDataClass(other), PoseBase(other), FramedPoseBase(other), LinkedPoseBase(other), @@ -214,6 +216,7 @@ namespace armarx LinkedDirection::LinkedDirection(const LinkedDirection& source) : IceUtil::Shared(source), + armarx::Serializable(source), Vector3Base(source), FramedDirectionBase(source), LinkedDirectionBase(source), diff --git a/source/RobotAPI/libraries/core/Pose.cpp b/source/RobotAPI/libraries/core/Pose.cpp index 0bca83408ff4831cd028c664aed9c20f7e056c1f..39968afc088d5ed82cad8461cfd89cb96a75e321 100644 --- a/source/RobotAPI/libraries/core/Pose.cpp +++ b/source/RobotAPI/libraries/core/Pose.cpp @@ -277,6 +277,8 @@ namespace armarx Pose::Pose(const Pose& source) : IceUtil::Shared(source), + armarx::Serializable(source), + armarx::VariantDataClass(source), PoseBase(source) { orientation = QuaternionBasePtr::dynamicCast(source.orientation->clone()); diff --git a/source/RobotAPI/libraries/core/Trajectory.cpp b/source/RobotAPI/libraries/core/Trajectory.cpp index f8068131cc9a3d0b939ff06242505195310f830a..1c75dcd1cf70470595a5f2f0f242e1106c287229 100644 --- a/source/RobotAPI/libraries/core/Trajectory.cpp +++ b/source/RobotAPI/libraries/core/Trajectory.cpp @@ -176,6 +176,8 @@ namespace armarx Trajectory::Trajectory(const Trajectory& source) : IceUtil::Shared(source), + armarx::Serializable(source), + armarx::VariantDataClass(source), TrajectoryBase(source) { CopyData(source, *this);