diff --git a/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp b/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp index 331d7b35ed6d9720e1436a3776026783caf179b4..990b2cea609c44a563f1009da27fe079359e5e9f 100644 --- a/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp +++ b/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp @@ -40,8 +40,9 @@ namespace armarx::armem::server::obj defs->topic<objpose::ObjectPoseTopic>(); // "ObjectPoseTopic", "ObjectPoseTopicName", "Name of the Object Pose Topic."); // Use - defs->component(kinematicUnitObserver); - + // defs->component(kinematicUnitObserver); // Optional dependency. + defs->defineOptionalProperty<std::string>("cmp.KinematicUnitObserverName", "KinematicUnitObserver", + "Name of the kinematic unit observer."); const std::string prefix = "mem."; @@ -83,7 +84,7 @@ namespace armarx::armem::server::obj } robotStateComponent = getRobotStateComponent(); - // getProxyFromProperty(kinematicUnitObserver, "KinematicUnitObserverName", false, "", false); + getProxyFromProperty(kinematicUnitObserver, "cmp.KinematicUnitObserverName", false, "", false); instance::SegmentAdapter::connect( robotStateComponent, robot, @@ -113,7 +114,7 @@ namespace armarx::armem::server::obj VBoxLayout root = { - tab.instance.root, + tab.instance.group, VSpacer() }; RemoteGui_createTab(Component::getName(), root, &tab); diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp b/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp index 0e1cc8cf6be52d8865d15ba0ad6886d9886f5729..8425a15ed88c1a7a27ce540a75c348c12f81ea4a 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp +++ b/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp @@ -52,8 +52,9 @@ namespace armarx::armem::server::obj::instance void Segment::defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix) { - defs->optional(maxHistorySize, "mem.MaxHistorySize", "Maximal size of object poses history (-1 for infinite)."); - defs->optional(discardSnapshotsWhileAttached, "mem.DiscardSnapshotsWhileAttached", + defs->optional(p.coreSegmentName, prefix + "CoreSegmentName", "Name of the object instance core segment."); + defs->optional(p.maxHistorySize, prefix + "MaxHistorySize", "Maximal size of object poses history (-1 for infinite)."); + defs->optional(p.discardSnapshotsWhileAttached, prefix + "DiscardSnapshotsWhileAttached", "If true, no new snapshots are stored while an object is attached to a robot node.\n" "If false, new snapshots are stored, but the attachment is kept in the new snapshots."); @@ -64,8 +65,8 @@ namespace armarx::armem::server::obj::instance { ARMARX_CHECK_NOT_NULL(iceMemory.memory); - coreSegment = &iceMemory.memory->addCoreSegment("ObjectPose", objpose::arondto::ObjectPose::toInitialAronType()); - coreSegment->setMaxHistorySize(maxHistorySize); + coreSegment = &iceMemory.memory->addCoreSegment(p.coreSegmentName, objpose::arondto::ObjectPose::toInitialAronType()); + coreSegment->setMaxHistorySize(p.maxHistorySize); } @@ -102,7 +103,7 @@ namespace armarx::armem::server::obj::instance } else if (previousPose) { - if (discardSnapshotsWhileAttached && previousPose->attachment) + if (p.discardSnapshotsWhileAttached && previousPose->attachment) { // Discard update due to active attachemnt. discard = true; @@ -125,7 +126,7 @@ namespace armarx::armem::server::obj::instance if (previousPose && previousPose->attachment) { // Keep current attachment. - ARMARX_CHECK(!discardSnapshotsWhileAttached); + ARMARX_CHECK(!p.discardSnapshotsWhileAttached); newPose.attachment = previousPose->attachment; } @@ -638,10 +639,10 @@ namespace armarx::armem::server::obj::instance { using namespace armarx::RemoteGui::Client; - maxHistorySize.setValue(std::max(1, int(data.maxHistorySize))); + maxHistorySize.setValue(std::max(1, int(data.p.maxHistorySize))); maxHistorySize.setRange(1, 1e6); - infiniteHistory.setValue(data.maxHistorySize == -1); - discardSnapshotsWhileAttached.setValue(data.discardSnapshotsWhileAttached); + infiniteHistory.setValue(data.p.maxHistorySize == -1); + discardSnapshotsWhileAttached.setValue(data.p.discardSnapshotsWhileAttached); GridLayout grid; int row = 0; @@ -649,7 +650,7 @@ namespace armarx::armem::server::obj::instance row++; grid.add(Label("Infinite History Size"), {row, 0}).add(infiniteHistory, {row, 1}); row++; - grid.add(Label("Discard Snapshots while attached"), {row, 0}).add(discardSnapshotsWhileAttached, {row, 1}); + grid.add(Label("Discard Snapshots while Attached"), {row, 0}).add(discardSnapshotsWhileAttached, {row, 1}); row++; group.setLabel("Data"); @@ -660,14 +661,14 @@ namespace armarx::armem::server::obj::instance { if (infiniteHistory.hasValueChanged() || maxHistorySize.hasValueChanged()) { - data.maxHistorySize = infiniteHistory.getValue() ? -1 : maxHistorySize.getValue(); + data.p.maxHistorySize = infiniteHistory.getValue() ? -1 : maxHistorySize.getValue(); if (data.coreSegment) { - data.coreSegment->setMaxHistorySize(long(data.maxHistorySize)); + data.coreSegment->setMaxHistorySize(long(data.p.maxHistorySize)); } } - data.discardSnapshotsWhileAttached = discardSnapshotsWhileAttached.getValue(); + data.p.discardSnapshotsWhileAttached = discardSnapshotsWhileAttached.getValue(); } } diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/Segment.h b/source/RobotAPI/libraries/armem_objects/server/instance/Segment.h index 275d9973856bc2a59a71c633374e98bee34cc845..20ee8ffdfe3f786e7cea0be8a5f71589437153cc 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/Segment.h +++ b/source/RobotAPI/libraries/armem_objects/server/instance/Segment.h @@ -152,8 +152,13 @@ namespace armarx::armem::server::obj::instance armem::CoreSegment* coreSegment = nullptr; - long maxHistorySize = -1; - bool discardSnapshotsWhileAttached = true; + struct Properties + { + std::string coreSegmentName = "Instance"; + long maxHistorySize = -1; + bool discardSnapshotsWhileAttached = true; + }; + Properties p; /// Caches results of attempts to retrieve the OOBB from ArmarXObjects. diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.cpp b/source/RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.cpp index 91fa17d0317b1e081c35b8032aace7f64ce92912..d44f5dfa0f1eb73ac3cf5a41af76b9b2532aa1d7 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.cpp +++ b/source/RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.cpp @@ -38,7 +38,7 @@ namespace armarx::armem::server::obj::instance { SegmentAdapter::SegmentAdapter(MemoryToIceAdapter& iceMemory, std::mutex& memoryMutex) : - data(iceMemory), + segment(iceMemory), memoryMutex(memoryMutex) { } @@ -51,19 +51,19 @@ namespace armarx::armem::server::obj::instance void SegmentAdapter::defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix) { calibration.defineProperties(defs, prefix + "calibration."); - data.defineProperties(defs, prefix); + segment.defineProperties(defs, prefix); robotHead.defineProperties(defs, prefix + "head."); visu.defineProperties(defs, prefix + "visu."); } void SegmentAdapter::init() { - data.setTag(getName()); - data.decay.setTag(getName()); + segment.setTag(getName()); + segment.decay.setTag(getName()); robotHead.setTag(getName()); visu.setTag(getName()); - data.init(); + segment.init(); } void SegmentAdapter::connect( @@ -77,8 +77,8 @@ namespace armarx::armem::server::obj::instance this->debugObserver = debugObserver; this->arviz = arviz; - data.robot = robot; - data.robotStateComponent = robotStateComponent; + segment.robot = robot; + segment.robotStateComponent = robotStateComponent; robotHead.kinematicUnitObserver = kinematicUnitObserver; robotHead.debugObserver = debugObserver; @@ -126,7 +126,7 @@ namespace armarx::armem::server::obj::instance } ARMARX_VERBOSE << "Provider '" << providerName << "' available.\n" << "Supported objects: \n" << ss.str(); - data.providers[providerName] = info; + segment.providers[providerName] = info; } } @@ -160,18 +160,18 @@ namespace armarx::armem::server::obj::instance { std::scoped_lock lock(memoryMutex); - RemoteRobot::synchronizeLocalClone(data.robot, data.robotStateComponent); + RemoteRobot::synchronizeLocalClone(segment.robot, segment.robotStateComponent); - if (data.robot->hasRobotNode(calibration.robotNode)) + if (segment.robot->hasRobotNode(calibration.robotNode)) { - VirtualRobot::RobotNodePtr robotNode = data.robot->getRobotNode(calibration.robotNode); + VirtualRobot::RobotNodePtr robotNode = segment.robot->getRobotNode(calibration.robotNode); float value = robotNode->getJointValue(); robotNode->setJointValue(value + calibration.offset); } TIMING_START(tCommitObjectPoses); Segment::CommitStats stats = - data.commitObjectPoses(providerName, providedPoses, discard.updatesUntil); + segment.commitObjectPoses(providerName, providedPoses, discard.updatesUntil); TIMING_END_STREAM(tCommitObjectPoses, ARMARX_VERBOSE); if (debugObserver) @@ -201,9 +201,9 @@ namespace armarx::armem::server::obj::instance void SegmentAdapter::handleProviderUpdate(const std::string& providerName) { // Initialized to 0 on first access. - if (data.providers.count(providerName) == 0) + if (segment.providers.count(providerName) == 0) { - data.providers[providerName] = objpose::ProviderInfo(); + segment.providers[providerName] = objpose::ProviderInfo(); } } @@ -217,7 +217,7 @@ namespace armarx::armem::server::obj::instance TIMING_END_STREAM(tGetObjectPosesLock, ARMARX_VERBOSE); const IceUtil::Time now = TimeUtil::GetTime(); - const objpose::data::ObjectPoseSeq result = objpose::toIce(data.getObjectPoses(now)); + const objpose::data::ObjectPoseSeq result = objpose::toIce(segment.getObjectPoses(now)); TIMING_END_STREAM(tGetObjectPoses, ARMARX_VERBOSE); @@ -242,7 +242,7 @@ namespace armarx::armem::server::obj::instance TIMING_END_STREAM(GetObjectPosesLock, ARMARX_VERBOSE); const IceUtil::Time now = TimeUtil::GetTime(); - const objpose::data::ObjectPoseSeq result = objpose::toIce(data.getObjectPosesByProvider(providerName, now)); + const objpose::data::ObjectPoseSeq result = objpose::toIce(segment.getObjectPosesByProvider(providerName, now)); TIMING_END_STREAM(GetObjectPoses, ARMARX_VERBOSE); @@ -271,7 +271,7 @@ namespace armarx::armem::server::obj::instance { if (proxies.count(providerName) == 0) { - if (auto it = data.providers.find(providerName); it != data.providers.end()) + if (auto it = segment.providers.find(providerName); it != segment.providers.end()) { proxies[providerName] = it->second.proxy; } @@ -294,7 +294,7 @@ namespace armarx::armem::server::obj::instance for (const auto& objectID : input.request.objectIDs) { bool found = true; - for (const auto& [providerName, info] : data.providers) + for (const auto& [providerName, info] : segment.providers) { // ToDo: optimize look up. if (std::find(info.supportedObjects.begin(), info.supportedObjects.end(), objectID) != info.supportedObjects.end()) @@ -337,25 +337,25 @@ namespace armarx::armem::server::obj::instance objpose::ProviderInfoMap SegmentAdapter::getAvailableProvidersInfo(const Ice::Current&) { std::scoped_lock lock(memoryMutex); - return data.providers; + return segment.providers; } Ice::StringSeq SegmentAdapter::getAvailableProviderNames(const Ice::Current&) { std::scoped_lock lock(memoryMutex); - return simox::alg::get_keys(data.providers); + return simox::alg::get_keys(segment.providers); } objpose::ProviderInfo SegmentAdapter::getProviderInfo(const std::string& providerName, const Ice::Current&) { std::scoped_lock lock(memoryMutex); - return data.getProviderInfo(providerName); + return segment.getProviderInfo(providerName); } bool SegmentAdapter::hasProvider(const std::string& providerName, const Ice::Current&) { std::scoped_lock lock(memoryMutex); - return data.providers.count(providerName) > 0; + return segment.providers.count(providerName) > 0; } @@ -363,21 +363,21 @@ namespace armarx::armem::server::obj::instance const objpose::AttachObjectToRobotNodeInput& input, const Ice::Current&) { std::scoped_lock lock(memoryMutex); - return data.attachObjectToRobotNode(input); + return segment.attachObjectToRobotNode(input); } objpose::DetachObjectFromRobotNodeOutput SegmentAdapter::detachObjectFromRobotNode( const objpose::DetachObjectFromRobotNodeInput& input, const Ice::Current&) { std::scoped_lock lock(memoryMutex); - return data.detachObjectFromRobotNode(input); + return segment.detachObjectFromRobotNode(input); } objpose::DetachAllObjectsFromRobotNodesOutput SegmentAdapter::detachAllObjectsFromRobotNodes( const objpose::DetachAllObjectsFromRobotNodesInput& input, const Ice::Current&) { std::scoped_lock lock(memoryMutex); - return data.detachAllObjectsFromRobotNodes(input); + return segment.detachAllObjectsFromRobotNodes(input); } @@ -386,7 +386,7 @@ namespace armarx::armem::server::obj::instance std::scoped_lock lock(memoryMutex); objpose::AgentFramesSeq output; - std::vector<VirtualRobot::RobotPtr> agents = { data.robot }; + std::vector<VirtualRobot::RobotPtr> agents = { segment.robot }; for (VirtualRobot::RobotPtr agent : agents) { objpose::AgentFrames& frames = output.emplace_back(); @@ -423,11 +423,11 @@ namespace armarx::armem::server::obj::instance std::scoped_lock lock(memoryMutex); const IceUtil::Time now = TimeUtil::GetTime(); - objectPoses = data.getObjectPoses(now); - objectFinder = data.objectFinder; - if (data.decay.enabled) + objectPoses = segment.getObjectPoses(now); + objectFinder = segment.objectFinder; + if (segment.decay.enabled) { - visu.minConfidence = data.decay.removeObjectsBelowConfidence; + visu.minConfidence = segment.decay.removeObjectsBelowConfidence; } } const std::vector<viz::Layer> layers = visu.visualizeCommit(objectPoses, objectFinder); @@ -462,15 +462,18 @@ namespace armarx::armem::server::obj::instance using namespace armarx::RemoteGui::Client; this->visu.setup(adapter.visu); - this->data.setup(adapter.data); - this->decay.setup(adapter.data.decay); + this->segment.setup(adapter.segment); + this->decay.setup(adapter.segment.decay); this->robotHead.setup(adapter.robotHead); - root = VBoxLayout + layout = VBoxLayout { - this->visu.group, this->data.group, this->decay.group, this->robotHead.group, + this->visu.group, this->segment.group, this->decay.group, this->robotHead.group, VSpacer() }; + + group.setLabel("Instance"); + group.addChild(layout); } void SegmentAdapter::RemoteGui::update(SegmentAdapter& adapter) @@ -482,8 +485,8 @@ namespace armarx::armem::server::obj::instance } { std::scoped_lock lock(adapter.memoryMutex); - this->data.update(adapter.data); - this->decay.update(adapter.data.decay); + this->segment.update(adapter.segment); + this->decay.update(adapter.segment.decay); } { std::scoped_lock lock(adapter.robotHeadMutex); diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.h b/source/RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.h index 9819a162eee886fcb1e7878f5787b866d1273c82..a1e356e53c77608937b0df952798d0427a3cc86b 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.h +++ b/source/RobotAPI/libraries/armem_objects/server/instance/SegmentAdapter.h @@ -126,7 +126,7 @@ namespace armarx::armem::server::obj::instance viz::Client arviz; DebugObserverInterfacePrx debugObserver; - instance::Segment data; + instance::Segment segment; std::mutex& memoryMutex; instance::RobotHeadMovement robotHead; @@ -150,10 +150,11 @@ namespace armarx::armem::server::obj::instance struct RemoteGui { - armarx::RemoteGui::Client::VBoxLayout root; + armarx::RemoteGui::Client::GroupBox group; + armarx::RemoteGui::Client::VBoxLayout layout; instance::Visu::RemoteGui visu; - instance::Segment::RemoteGui data; + instance::Segment::RemoteGui segment; instance::Decay::RemoteGui decay; instance::RobotHeadMovement::RemoteGui robotHead; diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/Visu.cpp b/source/RobotAPI/libraries/armem_objects/server/instance/Visu.cpp index 3689a9bd1534d4e405cdf3fa8de92f0963df90c3..cc85dc53c51871fad99a57b044e823c49ed6f224 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/Visu.cpp +++ b/source/RobotAPI/libraries/armem_objects/server/instance/Visu.cpp @@ -156,7 +156,7 @@ namespace armarx::armem::server::obj::instance row++; grid.add(Label("Alpha"), {row, 0}).add(alpha, {row, 1}, {1, 3}); row++; - grid.add(Label("Alpha By Confidence"), {row, 0}).add(alphaByConfidence, {row, 1}); + grid.add(Label("Alpha by Confidence"), {row, 0}).add(alphaByConfidence, {row, 1}); row++; grid.add(Label("OOBB"), {row, 0}).add(oobbs, {row, 1}); row++; diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/Visu.h b/source/RobotAPI/libraries/armem_objects/server/instance/Visu.h index 99f6857a6e89a953cd20565dd973d6417c9a4a4e..1cd1d41c835e56e820ce3db8b3397b1e117d8202 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/Visu.h +++ b/source/RobotAPI/libraries/armem_objects/server/instance/Visu.h @@ -56,7 +56,7 @@ namespace armarx::armem::server::obj::instance viz::Client arviz; - bool enabled = false; + bool enabled = true; float frequencyHz = 25; bool inGlobalFrame = true;