28#include <ArmarXCore/interface/core/Log.h>
30#include <RobotAPI/interface/core/RobotState.h>
34#include <MemoryX/gui-plugins/WorkingMemoryGui/ui_WorkingMemoryConfigDialog.h>
49#include <SimoxUtility/algorithm/string/string_tools.h>
50#include <VirtualRobot/Grasping/Grasp.h>
51#include <VirtualRobot/Grasping/GraspSet.h>
52#include <VirtualRobot/ManipulationObject.h>
53#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
54#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
55#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h>
56#include <VirtualRobot/XML/ObjectIO.h>
57#include <VirtualRobot/XML/RobotIO.h>
63#include <QDialogButtonBox>
74#include <QTreeWidgetItem>
83#include <Inventor/Qt/SoQt.h>
84#include <Inventor/SoDB.h>
85#include <Inventor/nodes/SoUnits.h>
89#include <Inventor/VRMLnodes/SoVRMLGroup.h>
90#include <Inventor/actions/SoToVRML2Action.h>
91#include <Inventor/actions/SoWriteAction.h>
92#include <Inventor/nodes/SoRotation.h>
96#include <eigen3/Eigen/Core>
110Q_DECLARE_METATYPE(::memoryx::EntityBasePtr)
116#define DEFAULT_SETTINGS_PLUGIN_NAME "WorkingMemoryGuiPlugin"
117#define DEFAULT_SETTINGS_PRIORMEMORY_NAME "PriorKnowledge"
118#define DEFAULT_SETTINGS_WORKINGMEMORY_NAME "WorkingMemory"
119#define DEFAULT_SETTINGS_WORKINGMEMORY_UPDATESTOPIC "WorkingMemoryUpdates"
120#define DEFAULT_SETTINGS_OBJECT_INSTANCES_SEGMENT_NAME "objectInstances"
121#define DEFAULT_SETTINGS_AGENT_INSTANCES_SEGMENT_NAME "agentInstances"
122#define DEFAULT_SETTINGS_WORLD_STATE_SEGMENT_NAME "worldState"
123#define DEFAULT_SETTINGS_ADDITIONAL_PACKAGES "RobotAPI,Armar3,Armar4"
124#define DEFAULT_SETTINGS_COMMONSTORAGE_NAME "CommonStorage"
125#define MIN_OBJECT_TRANSPARENCY 0.1f
130static const int DEFAULT_ROBOT_UPDATE_STEP = 33;
137 eItemAttr = QTreeWidgetItem::UserType + 2,
146 qRegisterMetaType<memoryx::EntityBasePtr>(
"memoryx::EntityBasePtr");
147 qRegisterMetaType<Qt::SortOrder>(
"Qt::SortOrder");
158 customToolbar =
nullptr;
160 debugDrawer =
nullptr;
161 sceneConfigDialog =
nullptr;
162 debugDrawerConfigWidget =
nullptr;
166 visuSetting_transparentExistanceCertatinty =
ui.checkBox_existenceCertainty->isChecked();
167 visuSetting_showObjectModels =
ui.cbShowObjectModels->isChecked();
172 ui.tabWidget->removeTab(0);
182 ARMARX_INFO <<
"Destructor WorkingMemoryController";
191 std::unique_lock lock(*
mutex3D);
221 if (debugDrawer && debugDrawer->getObjectScheduler())
223 ARMARX_INFO <<
"Removing DebugDrawer component...";
224 debugDrawer->getObjectScheduler()->terminate();
225 ARMARX_INFO <<
"Removing DebugDrawer component...done";
241 std::string debugDrawerComponentName =
"WorkingMemoryDebugDrawer_" +
getName();
242 ARMARX_INFO <<
"Creating component " << debugDrawerComponentName;
248 debugDrawer->setMutex(
mutex3D);
256 m->addObject(debugDrawer);
261 std::unique_lock lock(*
mutex3D);
277 up << 0.0f, 0.0f, 1.0f;
281 planeVisu = CoinVisualizationFactory::CreatePlaneVisualization(pos, up, 30000.0f, 0);
286 ARMARX_INFO <<
"WorkingMemory: " << settings_workingMemoryName;
299 ARMARX_INFO <<
" Connecting WorkingMemoryController";
303 std::unique_lock lock(mutexEntities);
306 ARMARX_DEBUG <<
"Getting object instances segment " << settings_objectInstancesSegmentName;
307 objectInstancesPrx = ObjectInstanceMemorySegmentBasePrx::uncheckedCast(
308 memoryPrx->getSegment(settings_objectInstancesSegmentName));
309 ARMARX_DEBUG <<
"Getting agent instances segment " << settings_agentInstancesSegmentName;
310 agentInstancesProxy = AgentInstancesSegmentBasePrx::uncheckedCast(
311 memoryPrx->getSegment(settings_agentInstancesSegmentName));
312 ARMARX_DEBUG <<
"Getting world state segment " << settings_worldStateSegmentName;
313 worldStateProxy = WorldStateSegmentBasePrx::uncheckedCast(
314 memoryPrx->getSegment(settings_worldStateSegmentName));
317 CommonStorageInterfacePrx commonStoragePrx =
322 ARMARX_DEBUG <<
"Getting prior knowledge " << settings_priorMemoryName;
326 classesSegmentPrx = priorKnowledgePrx->getObjectClassesSegment();
327 if (!classesSegmentPrx)
329 ARMARX_ERROR <<
"Classes Segment not found in PriorKnowledge";
335 <<
"Could not connect to other components (WM/PriorKnowledge/CommonStorage)...";
339 usingTopic(settings_workingMemoryUpdatesTopic);
341 QMetaObject::invokeMethod(
this,
"startTimerInGUIThread");
343 QMetaObject::invokeMethod(
this,
"refetchEntitiesFromMemory");
359 killTimer(robotUpdateTimerId);
362 std::unique_lock lock(mutexEntities);
371 ARMARX_INFO <<
" Exiting component WorkingMemoryController";
415 std::unique_lock lock(mutexEntities);
416 std::unique_lock lock2(*
mutex3D);
428 dialog->ui->editWorkingMemoryGuiName->setText(
430 dialog->ui->editWorkingMemoryName->setText(
432 dialog->ui->editPriorMemoryName->setText(
434 dialog->ui->editWorkingMemoryUpdatesTopic->setText(
436 dialog->ui->editObjectInstancesSegmentName->setText(
438 dialog->ui->editAgentInstancesSegmentName->setText(
440 dialog->ui->editWorldStateSegmentName->setText(
442 dialog->ui->editAdditionalPackages->setText(
446 return qobject_cast<WorkingMemoryConfigDialog*>(dialog);
453 QString addPacksString = QString::fromStdString(packages);
454 auto addPacks = addPacksString.split(
",", QString::SkipEmptyParts);
456 for (QString& package : addPacks)
468 settings_priorMemoryName = dialog->ui->editPriorMemoryName->text().toStdString();
469 settings_workingMemoryName = dialog->ui->editWorkingMemoryName->text().toStdString();
470 settings_objectInstancesSegmentName =
471 dialog->ui->editObjectInstancesSegmentName->text().toStdString();
472 settings_agentInstancesSegmentName =
473 dialog->ui->editAgentInstancesSegmentName->text().toStdString();
474 settings_worldStateSegmentName = dialog->ui->editWorldStateSegmentName->text().toStdString();
475 settings_workingMemoryUpdatesTopic =
476 dialog->ui->editWorkingMemoryUpdatesTopic->text().toStdString();
477 settings_packages = dialog->ui->editAdditionalPackages->text().toStdString();
487 settings_priorMemoryName =
489 ->value(
"settings_priorMemoryName",
493 settings_workingMemoryName =
495 ->value(
"settings_workingMemoryName",
499 settings_objectInstancesSegmentName =
501 ->value(
"settings_objectInstancesSegmentName",
505 settings_agentInstancesSegmentName =
507 ->value(
"settings_agentInstancesSegmentName",
511 settings_worldStateSegmentName =
513 ->value(
"settings_worldStateSegmentName",
517 settings_workingMemoryUpdatesTopic =
519 ->value(
"settings_workingMemoryUpdatesTopic",
523 settings_packages = settings
524 ->value(
"settings_packages",
529 visuSetting_transparentExistanceCertatinty =
530 settings->value(
"settings_existenceCertaintyTransparency",
true).toBool();
531 ui.checkBox_existenceCertainty->setChecked(visuSetting_transparentExistanceCertatinty);
533 visuSetting_showObjectModels = settings->value(
"settings_showObjectModels",
true).toBool();
534 ui.cbShowObjectModels->setChecked(visuSetting_showObjectModels);
543 settings->beginGroup(
"DebugDrawer");
544 if (!settings->allKeys().empty())
547 debugDrawerConfigWidget->loadSettings(settings);
549 settings->endGroup();
556 settings->setValue(
"settings_priorMemoryName",
557 QString::fromStdString(settings_priorMemoryName));
558 settings->setValue(
"settings_workingMemoryName",
559 QString::fromStdString(settings_workingMemoryName));
560 settings->setValue(
"settings_objectInstancesSegmentName",
561 QString::fromStdString(settings_objectInstancesSegmentName));
562 settings->setValue(
"settings_agentInstancesSegmentName",
563 QString::fromStdString(settings_agentInstancesSegmentName));
564 settings->setValue(
"settings_worldStateSegmentName",
565 QString::fromStdString(settings_worldStateSegmentName));
566 settings->setValue(
"settings_workingMemoryUpdatesTopic",
567 QString::fromStdString(settings_workingMemoryUpdatesTopic));
568 settings->setValue(
"settings_packages", QString::fromStdString(settings_packages));
570 settings->setValue(
"settings_existenceCertaintyTransparency",
571 ui.checkBox_existenceCertainty->isChecked());
572 settings->setValue(
"settings_showObjectModels",
ui.cbShowObjectModels->isChecked());
573 settings->beginGroup(
"DebugDrawer");
574 if (debugDrawerConfigWidget)
576 debugDrawerConfigWidget->saveSettings(settings);
578 settings->endGroup();
597 if (!sceneConfigDialog)
599 sceneConfigDialog =
new QDialog(parent);
600 QVBoxLayout* verticalLayout =
new QVBoxLayout(sceneConfigDialog);
601 sceneConfigDialog->setLayout(verticalLayout);
603 debugDrawerConfigWidget =
605 verticalLayout->addWidget(debugDrawerConfigWidget);
607 QDialogButtonBox* buttonBox =
new QDialogButtonBox(sceneConfigDialog);
608 buttonBox->setOrientation(Qt::Horizontal);
609 buttonBox->setStandardButtons(QDialogButtonBox::Ok);
610 verticalLayout->addWidget(buttonBox);
611 QObject::connect(buttonBox, SIGNAL(accepted()), sceneConfigDialog, SLOT(accept()));
613 else if (!debugDrawerConfigWidget->getDebugDrawer())
615 debugDrawerConfigWidget->setDebugDrawer(debugDrawer);
617 return sceneConfigDialog;
624 connect(
ui.btnExport,
625 &QPushButton::clicked,
628 Qt::QueuedConnection);
631 connect(
ui.cbShowObjectModels,
632 SIGNAL(toggled(
bool)),
635 Qt::QueuedConnection);
636 connect(
ui.cbShowPositionUncertainty,
637 SIGNAL(toggled(
bool)),
640 Qt::QueuedConnection);
641 connect(
ui.checkBoxVisuLayers,
642 SIGNAL(toggled(
bool)),
645 Qt::QueuedConnection);
646 connect(
ui.rbEllipse,
647 SIGNAL(toggled(
bool)),
650 Qt::QueuedConnection);
651 connect(
ui.rbHeatMap,
652 SIGNAL(toggled(
bool)),
655 Qt::QueuedConnection);
656 connect(
ui.rbHeatSurface,
657 SIGNAL(toggled(
bool)),
660 Qt::QueuedConnection);
661 connect(
ui.spinEllipseRadius,
662 SIGNAL(valueChanged(
double)),
665 Qt::QueuedConnection);
667 connect(
ui.spinDisplayThreshold,
668 SIGNAL(valueChanged(
double)),
671 Qt::QueuedConnection);
672 connect(
ui.spinGridSize,
673 SIGNAL(valueChanged(
int)),
676 Qt::QueuedConnection);
682 Qt::QueuedConnection);
684 SIGNAL(
entityChanged(memoryx::EntityBasePtr, QString,
bool)),
687 Qt::QueuedConnection);
689 SIGNAL(
entityChanged(memoryx::EntityBasePtr, QString,
bool)),
692 Qt::QueuedConnection);
694 connect(
ui.checkBoxAgents,
695 SIGNAL(toggled(
bool)),
698 Qt::QueuedConnection);
699 connect(
ui.checkBox_existenceCertainty,
700 SIGNAL(toggled(
bool)),
703 Qt::QueuedConnection);
705 connect(
ui.checkBoxShowPlane,
706 SIGNAL(toggled(
bool)),
709 Qt::QueuedConnection);
718 Qt::QueuedConnection);
723 Qt::QueuedConnection);
730 QString fi = QFileDialog::getSaveFileName(
731 Q_NULLPTR, tr(
"VRML 2.0 File"), QString(), tr(
"VRML Files (*.wrl)"));
732 std::string s = std::string(fi.toLatin1());
738 if (!simox::alg::ends_with(s,
".wrl"))
743 std::unique_lock lock(*
mutex3D);
745 SoOutput* so =
new SoOutput();
746 if (!so->openFile(s.c_str()))
748 ARMARX_ERROR <<
"Could not open file " << s <<
" for writing." << std::endl;
752 so->setHeaderString(
"#VRML V2.0 utf8");
754 SoGroup* n =
new SoGroup;
757 SoGroup* newVisu = CoinVisualizationFactory::convertSoFileChildren(n);
760 SoToVRML2Action tovrml2;
761 tovrml2.apply(newVisu);
762 SoVRMLGroup* newroot = tovrml2.getVRML2SceneGraph();
764 SoWriteAction wra(so);
778 std::unique_lock lock(mutexEntities);
781 for (
const auto& agent : currentAgents)
783 updateAgent(agent.second);
795 msgBox.setText(
"Entity selected: id = " + item->text(1));
797 const std::string
id = item->text(1).toStdString();
812 QObject::disconnect(
this,
813 SIGNAL(
entityChanged(memoryx::EntityBasePtr, QString,
bool)),
816 QObject::disconnect(
this,
817 SIGNAL(
entityChanged(memoryx::EntityBasePtr, QString,
bool)),
821 debugDrawer->clearDebugLayer();
822 debugDrawer->clearLayer(
"ObjectUncertainties");
824 std::string selectedTabName =
"";
826 if (
ui.tabWidget->count())
828 selectedTabName =
ui.tabWidget->tabText(
ui.tabWidget->currentIndex()).toStdString();
833 ARMARX_INFO <<
"Refetching data from WorkingmemoryPrxMemory";
846 ARMARX_INFO <<
"Processing segment " << segmentName;
847 WorkingMemoryEntitySegmentBasePrx segmentPrx =
848 WorkingMemoryEntitySegmentBasePrx::uncheckedCast(
849 memoryPrx->getSegment(segmentName));
853 if (segmentName == selectedTabName)
855 ui.tabWidget->setCurrentIndex(
index);
859 for (
const EntityBasePtr& entityBase : segmentPrx->getAllEntities())
861 ARMARX_INFO <<
"Processing entity " << entityBase->getName();
879 SIGNAL(
entityChanged(memoryx::EntityBasePtr, QString,
bool)),
882 Qt::QueuedConnection);
884 SIGNAL(
entityChanged(memoryx::EntityBasePtr, QString,
bool)),
887 Qt::QueuedConnection);
890 std::unique_lock lock(*
mutex3D);
893 if (
ui.checkBoxViewAll->isChecked() &&
main->getViewerWidget())
895 main->getViewerWidget()->viewer->viewAll();
906 startTimer((DEFAULT_ROBOT_UPDATE_STEP > 0 ? DEFAULT_ROBOT_UPDATE_STEP : 1));
926 for (
auto& [name, agentDef] : currentAgents)
928 if (agentDef.robot->getName() == pose->agent)
937 ARMARX_WARNING <<
"Agent " << pose->agent <<
" not found in current agents.";
938 obj.
setPose(agentInstancesProxy->convertToWorldPose(pose->agent, obj.
getPose()));
945 << obj.
getName() <<
" before: \n"
949 bool sync_successful =
true;
951 if (localizationTimestamp != agent->
timestamp)
956 localizationTimestamp.toMicroSeconds());
957 agent->
timestamp = localizationTimestamp;
961 <<
"Updating Pose of object with ts " << localizationTimestamp
962 <<
" with agent " << pose->agent <<
"with pose: \n"
973 <<
" could not successfully be synced. Try to calculate pose with "
974 "current agent of agentSegment.";
975 obj.
setPose(agentInstancesProxy->convertToWorldPose(pose->agent, obj.
getPose()));
979 << obj.
getName() <<
" after: \n"
997 std::unique_lock lock(mutexEntities);
999 ARMARX_DEBUG <<
"Updating object entity " << obj->getName();
1004 if (obj->getPosition()->frame != obj->getOrientation()->frame)
1006 ARMARX_ERROR <<
"Frame of pos and orientation are not the same of object "
1007 << obj->getName() <<
" pos frame: " << obj->getPosition()->frame
1008 <<
" ori frame: " << obj->getOrientation()->frame;
1011 IceUtil::Time localizationTimestamp = obj->getLocalizationTimestamp();
1012 if (lastUpdated.find(obj->getName()) == lastUpdated.end() ||
1013 localizationTimestamp.toMicroSeconds() > lastUpdated.at(obj->getName()).first)
1017 lastUpdated[obj->getName()] =
1018 std::make_pair(localizationTimestamp.toMicroSeconds(), obj->getPose());
1022 obj->setPose(lastUpdated.at(obj->getName()).second);
1028 auto uncertainty = obj->getPositionUncertainty();
1032 float variance = std::min(5000.0f, uncertainty->getVarianceScalar());
1033 auto pos = obj->getPosition();
1037 debugDrawer->setSphereVisu(
1038 "ObjectUncertainties",
1039 obj->getName() + obj->getId() +
"_uncertainty",
1041 armarx::DrawColor{std::min(1.0f, variance / 1000),
1042 std::max(0.0f, 1 - variance / 1000),
1050 <<
"Not global position for " << obj->getName() + obj->getId();
1056 <<
"No position uncertainty for " << obj->getName() + obj->getId();
1062 <<
"Position uncertainty is not shown for "
1063 << obj->getName() + obj->getId();
1068 ARMARX_ERROR <<
"Execption during update object data...";
1076 const std::string
id = entity->getId();
1077 if (entityType == settings_objectInstancesSegmentName ||
1078 entityType == settings_worldStateSegmentName)
1082 std::unique_lock lock(mutexEntities);
1090 ARMARX_INFO <<
"Creating entity instance, id:" <<
id <<
", type " << entityType;
1093 EntityPtr e = EntityPtr::dynamicCast(entity);
1115 std::unique_lock lock(mutexEntities);
1124 else if (entityType == settings_agentInstancesSegmentName)
1129 std::unique_lock lock(mutexEntities);
1130 AgentEntryMap::iterator itAgent = currentAgents.find(
id);
1131 found = itAgent != currentAgents.end();
1135 ARMARX_INFO <<
"Creating agent entity, id:" <<
id <<
" name: " << entity->getName()
1136 <<
", type " << entity->ice_id();
1159 const std::string
id = entity->getId();
1160 const std::string typeS = entityType.toStdString();
1161 ARMARX_DEBUG <<
"Updating visualization, id:" <<
id <<
", type " << typeS;
1163 std::unique_lock lock1(mutexEntities);
1164 std::unique_lock lock2(*
mutex3D);
1167 if (typeS == settings_objectInstancesSegmentName || typeS == settings_worldStateSegmentName)
1174 ARMARX_INFO <<
"Could not find currentEntity entry for object with id = " <<
id
1175 <<
", building new entry";
1192 if (itEntity->second.simoxWrapper)
1194 itEntity->second.simoxWrapper->updateFromEntity(entity);
1196 if (visuSetting_transparentExistanceCertatinty)
1199 itEntity->second.obj->getExistenceCertainty());
1201 << itEntity->second.manipObj->getName() <<
":"
1202 << itEntity->second.obj->getExistenceCertainty();
1206 if (itEntity->second.cv)
1208 itEntity->second.cv->setTransparency(t);
1215 else if (typeS == settings_agentInstancesSegmentName)
1218 AgentEntryMap::iterator itAgent = currentAgents.find(
id);
1220 if (itAgent == currentAgents.end())
1222 ARMARX_VERBOSE <<
"Could not find currentAgents entry for object with id = " <<
id
1223 <<
", loading agent data...";
1242 ARMARX_DEBUG <<
"Updating visualization END, id:" <<
id <<
", type " << typeS;
1254 std::unique_lock lock(*
mutex3D);
1258 SoNode* s =
nullptr;
1262 o.
cv = o.
manipObj->getVisualization<VirtualRobot::CoinVisualization>();
1266 if (visuSetting_transparentExistanceCertatinty)
1273 o.
cv->setTransparency(t);
1275 s = o.
cv->getCoinVisualization();
1282 CoinVisualizationFactoryPtr coinVisFactory(
new CoinVisualizationFactory());
1284 s = std::dynamic_pointer_cast<VirtualRobot::CoinVisualizationNode>(
1285 coinVisFactory->createCoordSystem(1.0, &name))
1286 ->getCoinVisualization();
1304 if (objWrapper && objWrapper->getManipulationObject())
1307 << objWrapper->getManipulationObject()->getName();
1319 std::unique_lock lock(*
mutex3D);
1322 objWrapper->refreshVisuPose();
1333 ARMARX_DEBUG <<
"updateEntityTree:" << entity->getName() <<
",type:" << entityType;
1335 EntityPtr obj = EntityPtr::dynamicCast(entity);
1336 std::string entityTypeS = entityType.toStdString();
1340 ARMARX_INFO <<
"Segment " << entityTypeS <<
" not yet displayed";
1344 QString objName(obj->getName().c_str());
1345 QString objId = QString::fromStdString(entity->getId());
1347 QList<QTreeWidgetItem*> oldItems;
1348 QTreeWidgetItem* objItem;
1350 QTreeWidget* tree =
segmentTabs.at(entityTypeS).tree;
1351 oldItems = tree->findItems(objId, Qt::MatchFixedString, 1);
1354 objItem->setText(0, objName);
1355 objItem->setText(1, objId);
1364 QList<QTreeWidgetItem*> oldAttrs = objItem->takeChildren();
1366 while (!oldAttrs.empty())
1368 delete oldAttrs.takeFirst();
1371 QBrush evenRow(QColor(217, 255, 226));
1372 QBrush oddRow(Qt::white);
1374 memoryx::NameList attrNames = obj->getAttributeNames();
1376 for (
const auto& attrName : attrNames)
1381 attrItem->setText(0, QString::fromStdString(attrName));
1384 auto uncertainty = obj->getAttribute(attrName)->getUncertainty();
1388 QString attrValStr(attrValue->getOutputValueOnly().c_str());
1393 QString(
"\nUncertainty: ") + QString::fromStdString(uncertainty->output());
1396 attrItem->setText(1, attrValStr);
1400 attrItem->setText(1,
"Missing/unsupported value");
1404 QBrush& bgBrush = (i % 2 == 0) ? evenRow : oddRow;
1405 attrItem->setBackground(0, bgBrush);
1406 attrItem->setBackground(1, bgBrush);
1409 ARMARX_DEBUG <<
"updateEntityTree END:" << entity->getName() <<
",type:" << entityType;
1416 if (QMessageBox::Yes ==
1417 QMessageBox(QMessageBox::Information,
1418 "Clearing Working Memory",
1419 "Do you really want to clear the content of Working Memory?",
1420 QMessageBox::Yes | QMessageBox::No)
1423 std::unique_lock lock(mutexEntities);
1431 ARMARX_ERROR <<
"Execption during clear working memory...";
1444 debugDrawer->enableAllLayers();
1448 debugDrawer->disableAllLayers();
1457 std::unique_lock lock(*
mutex3D);
1484 std::unique_lock lock(*
mutex3D);
1511 std::unique_lock lock(mutexEntities);
1522 for (
auto& entity : currentAgents)
1524 deletedAgents[entity.first] = entity.second;
1527 currentAgents.clear();
1534 std::unique_lock lock(mutexEntities);
1537 if (segmentName ==
"" || segmentName == settings_objectInstancesSegmentName)
1543 entity.second.manipObj.reset();
1545 if (entity.second.simoxWrapper)
1547 entity.second.simoxWrapper->setEntity(EntityBasePtr());
1548 entity.second.simoxWrapper =
nullptr;
1555 if (segmentName ==
"" || segmentName == settings_agentInstancesSegmentName)
1558 deletedAgents.clear();
1561 std::unique_lock lock2(*
mutex3D);
1580 ARMARX_INFO <<
"Rebuilding complete visualization";
1581 std::unique_lock lock1(mutexEntities);
1582 std::unique_lock lock2(*
mutex3D);
1595 ARMARX_VERBOSE <<
"Rebuilding entity visualization for: " << entity.first;
1602 ARMARX_INFO <<
"Rebuilding robot visualization for " << currentAgents.size() <<
" agents";
1605 for (
const auto& agent : currentAgents)
1607 ARMARX_VERBOSE <<
"Rebuilding robot visualization for: " << agent.first;
1616 if (
main &&
main->getViewerWidget())
1618 auto l =
main->getViewerWidget()->viewer->getScopedLock();
1620 if (
ui.checkBoxViewAll->isChecked() &&
main->getViewerWidget())
1622 main->getViewerWidget()->viewer->viewAll();
1642 visuSetting_transparentExistanceCertatinty = isChecked;
1650 std::unique_lock lock(mutexEntities);
1658 visuSetting_showObjectModels =
ui.cbShowObjectModels->isChecked();
1662 debugDrawer->clearLayer(
"ObjectUncertainties");
1683 std::unique_lock lock(*
mutex3D);
1688 ARMARX_VERBOSE <<
"Only ObjectInstances are currently supported";
1693 ui.cbShowObjectModels->isChecked() || !obj->getPositionAttribute()->getUncertainty();
1694 bool showUncertaintyVisu =
ui.cbShowPositionUncertainty->isChecked();
1696 if (showUncertaintyVisu)
1702 if (
ui.rbEllipse->isChecked())
1706 else if (
ui.rbHeatMap->isChecked())
1710 else if (
ui.rbHeatSurface->isChecked())
1714 objWrapper.
simoxWrapper->setUncertaintyVisuType(visuType);
1715 objWrapper.
simoxWrapper->setUncertaintyVisuParams(
ui.spinEllipseRadius->value(),
1716 ui.spinMinVariance->value(),
1717 expf(-
ui.spinDisplayThreshold->value()),
1718 ui.spinGridSize->value());
1724 objWrapper.
manipObj->setupVisualization(showMainVisu, showUncertaintyVisu);
1730 const EntityBasePtr& entityBase,
1731 const Ice::Current&)
1734 std::unique_lock lock(mutexEntities);
1739 <<
", entity:" << entityBase->getName();
1741 EntityPtr entity = EntityPtr::dynamicCast(entityBase);
1744 QString entityType(segmentName.c_str());
1763 ARMARX_VERBOSE <<
"reportEntityCreated: entity type not supported: " << segmentName;
1771 ARMARX_ERROR <<
"Execption during reportEntityCreated...";
1777 const EntityBasePtr& entityBaseOld,
1778 const EntityBasePtr& entityBaseNew,
1779 const Ice::Current&)
1782 (void)entityBaseOld;
1784 ARMARX_DEBUG <<
"entity " << entityBaseNew->getName() <<
" got updated";
1785 std::unique_lock lock(mutexEntities);
1791 EntityPtr entity = EntityPtr::dynamicCast(entityBaseNew);
1793 QString entityId(entity->getId().c_str());
1794 QString entityType(segmentName.c_str());
1810 auto it = currentAgents.find(entityId.toStdString());
1812 if (it == currentAgents.end())
1823 ARMARX_ERROR <<
"Exception during reportEntityUpdated...";
1825 ARMARX_DEBUG <<
"entity " << entityBaseNew->getName() <<
" got updated END";
1830 const EntityBasePtr& entity,
1831 const Ice::Current&)
1834 std::unique_lock lock(mutexEntities);
1838 std::string entityId = entity->getId();
1851 ARMARX_INFO <<
"Object removed: id = " << entityId;
1854 QMetaObject::invokeMethod(
this,
"objectsRemoved");
1858 ARMARX_INFO <<
"Object not present, id = " << entityId;
1869 auto it = currentAgents.find(entityId);
1871 if (it != currentAgents.end())
1873 ARMARX_INFO <<
"Object removed (agent): id = " << entityId;
1874 deletedAgents[entityId] = currentAgents[entityId];
1875 currentAgents.erase(it);
1876 QMetaObject::invokeMethod(
this,
"agentsRemoved");
1880 ARMARX_INFO <<
"agent not present, id = " << entityId;
1885 QMetaObject::invokeMethod(
this,
1886 "removeEntityInTree",
1887 Q_ARG(std::string, entityId),
1888 Q_ARG(std::string, segmentName));
1894 ARMARX_ERROR <<
"Execption during reportEntityRemoved...";
1903 std::unique_lock lock(mutexEntities);
1904 std::unique_lock lock2(*
mutex3D);
1909 objectsVisu->findChild(e.second.visualization) >= 0)
1924 std::unique_lock lock(mutexEntities);
1925 std::unique_lock lock2(*
mutex3D);
1928 for (
auto& e : deletedAgents)
1932 agentsVisu->findChild(e.second.visualization) >= 0)
1934 agentsVisu->removeChild(e.second.visualization);
1940 deletedAgents.clear();
1954 std::unique_lock lock(mutexEntities);
1965 std::unique_lock lock(mutexEntities);
1968 ARMARX_INFO <<
"segment " << segmentName <<
" cleared";
1972 if (segmentName == settings_objectInstancesSegmentName)
1983 if (segmentName == settings_agentInstancesSegmentName)
1985 for (
auto& entity : currentAgents)
1987 deletedAgents[entity.first] = entity.second;
1990 currentAgents.clear();
1998 ARMARX_ERROR <<
"Execption during reportMemoryCleared...";
2012 debugDrawer->setMutex(
mutex3D);
2018 const std::string entityType)
2020 ARMARX_INFO <<
"Remove qt element: " << entityId <<
", " << entityType;
2021 QString entityItemId(entityId.c_str());
2022 QTreeWidgetItem* entityItem =
nullptr;
2026 QList<QTreeWidgetItem*> items =
2027 segmentTabs.at(entityType).tree->findItems(entityItemId, Qt::MatchFixedString, 1);
2028 if (items.size() > 0)
2030 entityItem = items.at(0);
2035 ARMARX_WARNING <<
"Undefined entity type: " << entityType << std::endl;
2041 ARMARX_WARNING <<
"Could not determine Qt tree item for entity " << entityId <<
", type "
2046 QList<QTreeWidgetItem*> entityAttributes = entityItem->takeChildren();
2048 while (!entityAttributes.empty())
2050 delete entityAttributes.takeFirst();
2067 QWidget* tab =
new QWidget();
2068 QGridLayout* layout =
new QGridLayout();
2069 tab->setLayout(layout);
2072 QTreeWidget* tree =
new QTreeWidget();
2073 tree->setColumnCount(2);
2077 tree->setHeaderLabels(header);
2078 tree->header()->setDefaultSectionSize(200);
2079 tree->setSortingEnabled(
true);
2080 tree->sortByColumn(0, Qt::SortOrder::AscendingOrder);
2081 index =
ui.tabWidget->addTab(tab, QString::fromStdString(segmentName));
2084 layout->addWidget(tree);
2087 segmentTabs.insert(std::pair<std::string, struct SegmentTab>(segmentName, et));
2090 SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
2110 QObject::disconnect(tab.
tree,
2111 SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
2116 tab.
tree->~QTreeWidget();
2117 tab.
tab->~QWidget();
2139 if (parent != customToolbar->parent())
2141 customToolbar->setParent(parent);
2144 return customToolbar;
2147 customToolbar =
new QToolBar(parent);
2148 customToolbar->setIconSize(QSize(16, 16));
2150 customToolbar->addAction(QIcon(
":/icons/view-refresh-7.png"),
2154 customToolbar->addAction(QIcon(
":/icons/dialog-close.ico"),
2155 "Clear Working Memory",
2159 return customToolbar;
2166 std::unique_lock lock(mutexEntities);
2167 if (currentAgents.find(entityId) == currentAgents.end() || !currentAgents[entityId].robot)
2171 currentAgents[entityId].visualization =
2172 VirtualRobot::CoinVisualizationFactory::getCoinVisualization(
2173 currentAgents[entityId].robot, VirtualRobot::SceneObject::Full,
false);
2175 if (!currentAgents[entityId].visualization)
2177 ARMARX_WARNING <<
"createAgentVisualisation: could not retrieve visualisation from robot "
2178 << currentAgents[entityId].robot->getName() <<
"; using ellipse";
2179 currentAgents[entityId].visualization =
2180 VirtualRobot::CoinVisualizationFactory::CreateEllipse(0.5, 0.5, 1,
nullptr,
false);
2186 agentsVisu->addChild(currentAgents[entityId].visualization);
2196 std::unique_lock lock(mutexEntities);
2202 ARMARX_ERROR <<
"addAgent: entity is not of type AgentInstance";
2206 const std::string agentId = agent->getId();
2209 if (!agent->hasAttribute(
"agentFilePath"))
2211 ARMARX_INFO <<
"No filepath available for agent " << agent->getName();
2214 std::string agentFilePath = agent->getAgentFilePath();
2215 ARMARX_INFO <<
"Adding agent " << agent->getName() <<
" agentId:" << agentId
2216 <<
", filepath: " << agentFilePath;
2218 if (sharedRobotInterfaceProxy)
2221 <<
" proxy: " << sharedRobotInterfaceProxy->ice_toString();
2225 ARMARX_INFO << agent->getName() <<
" proxy nullptr";
2229 if (!sharedRobotInterfaceProxy &&
2230 !agent->getStringifiedSharedRobotInterfaceProxy().empty())
2232 sharedRobotInterfaceProxy =
2233 armarx::SharedRobotInterfacePrx::checkedCast(iceCommunicator->stringToProxy(
2234 agent->getStringifiedSharedRobotInterfaceProxy()));
2237 catch (std::exception& e)
2239 ARMARX_ERROR <<
"Failed to get robot state proxy for agent " << agent->getName() <<
": "
2243 if (sharedRobotInterfaceProxy)
2246 if (sharedRobotInterfaceProxy->getRobotStateComponent())
2249 sharedRobotInterfaceProxy->getRobotStateComponent()->getArmarXPackages();
2251 for (
auto& p : packages)
2262 ARMARX_INFO <<
"RobotStateComponent proxy is empty";
2268 ARMARX_ERROR <<
"Could not find robot file " << agentFilePath;
2271 <<
" additional paths";
2286 sharedRobotInterfaceProxy, agentFilePath, sharedRobotInterfaceProxy->getScaling());
2287 robotDefinition.
robot->setName(sharedRobotInterfaceProxy->getName());
2294 robotDefinition.
robot.reset();
2295 ARMARX_ERROR <<
"addAgent: error while loading robot from file: "
2300 ARMARX_VERBOSE <<
"addAgent: loaded robot from file " << agentFilePath;
2302 robotDefinition.
robotStateComponent = sharedRobotInterfaceProxy->getRobotStateComponent();
2306 currentAgents[agentId] = robotDefinition;
2320 std::unique_lock lock(mutexEntities);
2321 auto entity = agentInstancesProxy->getEntityById(entityId);
2329 std::unique_lock lock(*
mutex3D);
2333 if (!agent || currentAgents.find(entity->getId()) == currentAgents.end())
2338 auto entityId = entity->getId();
2339 Eigen::Matrix4f matrix = Eigen::Matrix4f::Identity();
2345 matrix.block(0, 3, 3, 1) = agentPosition->toEigen();
2350 if (agentOrientation)
2352 matrix.block(0, 0, 3, 3) = agentOrientation->toEigen();
2355 auto& agentInstance = currentAgents[entityId];
2356 agentInstance.robot->setGlobalPose(matrix);
2363 std::unique_lock lock(mutexEntities);
2364 std::unique_lock lock2(*
mutex3D);
2371 std::map<std::string, float> jointValues;
2372 std::vector<RobotNodePtr> storeNodesRemote;
int main(int argc, char *argv[])
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
#define DEFAULT_SETTINGS_PRIORMEMORY_NAME
#define DEFAULT_SETTINGS_PLUGIN_NAME
#define DEFAULT_SETTINGS_WORKINGMEMORY_NAME
#define MIN_OBJECT_TRANSPARENCY
#define DEFAULT_SETTINGS_WORLD_STATE_SEGMENT_NAME
#define DEFAULT_SETTINGS_WORKINGMEMORY_UPDATESTOPIC
#define DEFAULT_SETTINGS_AGENT_INSTANCES_SEGMENT_NAME
#define DEFAULT_SETTINGS_ADDITIONAL_PACKAGES
#define DEFAULT_SETTINGS_OBJECT_INSTANCES_SEGMENT_NAME
#define DEFAULT_SETTINGS_COMMONSTORAGE_NAME
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
static std::vector< std::string > getDataPaths()
static void addDataPaths(const std::string &dataPathList)
std::enable_if<!HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
The ArmarXMainWindow class.
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
std::string getDataDir() const
bool packageFound() const
Returns whether or not this package was found with cmake.
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
std::string getName() const
Retrieve name of object.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
static bool synchronizeLocalCloneToTimestamp(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx, Ice::Long timestamp)
Synchronizes a local robot to a robot state at timestamp.
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
::std::string getId(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve id of this entity which is an integer in string representation.
::std::string getName(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve name of this entity.
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
armarx::FramedPosePtr getPose() const
Convenience function to get position and orientation attributes at once.
armarx::FramedPositionPtr getPosition() const
Retrieve position of the instance.
void setPose(const armarx::FramedPoseBasePtr &newPose)
Convenience function to set position and orientation attributes at once.
IceUtil::Time getLocalizationTimestamp() const
void initEntityInPlace(const EntityBasePtr &updateEntity)
void rebuildVisualization()
void processPackages(const std::string &packages)
int addTab(std::string segmentName)
bool createEntity(memoryx::EntityBasePtr entity, const std::string &entityType)
createEntity Updates currentEntities or currentAgents with data.
void onInitComponent() override
Pure virtual hook for the subclass.
void setupVisualization()
void uncertaintyVisuToggled(bool isChecked)
EntityEntryMap currentEntities
std::atomic< bool > showObjInstanceUncertainties
void startTimerInGUIThread()
void treeItemDoubleClicked(QTreeWidgetItem *item, int column)
QPointer< QDialog > getConfigDialog(QWidget *parent=nullptr) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
void updateObjectData(const ObjectInstancePtr obj)
DebugLayerControlWidget * debugLayerControlWidget
void updateEntityTree(memoryx::EntityBasePtr entity, QString entityType, bool isNew)
void refetchEntitiesFromMemory()
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
void onDisconnectComponent() override
Hook for subclass.
void reportSnapshotLoaded(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) override
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void entityChanged(memoryx::EntityBasePtr entity, QString entityType, bool isNew)
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
SoNode * getScene() override
Reimplementing this function and returning a SoNode* will show this SoNode in the 3DViewerWidget,...
QPointer< QDialog > getSceneConfigDialog(QWidget *parent=nullptr) override
Reimplementing this function and returning a QDialog* will enable a configuration button which opens ...
void signalClearEntities(const std::string &segmentName)
void existenceCertaintyToggled(bool isChecked)
EntityEntryMap deletedEntities
void reportEntityUpdated(const std::string &segmentName, const ::memoryx::EntityBasePtr &entityBaseOld, const ::memoryx::EntityBasePtr &entityBaseNew, const ::Ice::Current &=Ice::emptyCurrent) override
void setMutex3D(RecursiveMutexPtr const &mutex3D) override
This mutex is used to protect 3d scene updates. Usually called by the ArmarXGui main window on creati...
std::map< std::string, struct SegmentTab > segmentTabs
void clearWorkingMemory()
clearWorkingMemory deletes the current contents of WorkingMemory
void reportSnapshotCompletelyLoaded(const Ice::Current &c=Ice::emptyCurrent) override
void updateVisualization(const EntityWrappers::SimoxObjectWrapperPtr objWrapper)
void updateEntityVisu(memoryx::EntityBasePtr entity, QString entityType, bool isNew)
~WorkingMemoryController() override
void removeEntityInTree(const std::string entityId, const std::string entityType)
void reportEntityRemoved(const std::string &segmentName, const ::memoryx::EntityBasePtr &entity, const ::Ice::Current &=Ice::emptyCurrent) override
void convertObjectInstanceToGlobalPose(ObjectInstance &obj)
void signalAgentsRemoved()
void signalObjectRemoved()
SoSeparator * objectsVisu
void timerEvent(QTimerEvent *) override
void reportEntityCreated(const std::string &segmentName, const ::memoryx::EntityBasePtr &entity, const ::Ice::Current &=Ice::emptyCurrent) override
void showPlane(bool show)
void onConnectComponent() override
Pure virtual hook for the subclass.
void createAgentVisualisation(const std::string entityId)
memoryx::NameList segmentNames
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
void updateAgentVisualisation(const std::string entityId)
WorkingMemoryController()
void signalRebuildVisualization()
void setupEntityVisu(const ObjectDefinition &objWrapper)
Ui::WorkingMemoryGuiPlugin ui
void onExitComponent() override
Hook for subclass.
void showAgents(bool show)
Sets the visibility for agents.
void showVisuLayers(bool show)
Sets the visibility for debugDrawer's visualization layers.
void removeTab(std::string segmentName)
void createObjectVisualization(ObjectDefinition &o)
bool addAgent(const AgentInstancePtr agent)
void reportMemoryCleared(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) override
void signalRefetchEntities()
SoSeparator * debugLayerVisu
void clearEntitiesVisu(const std::string &segmentName="")
void objectsRemoved()
objectsRemoved One or multiple object(s) have been removed from memory. This method updates all Qt re...
void agentsRemoved()
agentsRemoved One or multiple agent(s) have been removed from memory. This method updates all Qt rela...
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::string const GlobalFrame
Variable of the global coordinate system.
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< ArmarXManager > ArmarXManagerPtr
std::string GetHandledExceptionString()
IceInternal::Handle< Variant > VariantPtr
IceInternal::Handle< FramedPosition > FramedPositionPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
IceInternal::Handle< FramedPose > FramedPosePtr
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
IceInternal::Handle< AgentInstance > AgentInstancePtr
Typedef of AgentEntityPtr as IceInternal::Handle<AgentEntity> for convenience.
IceInternal::Handle< ObjectInstance > ObjectInstancePtr
IceInternal::Handle< Entity > EntityPtr
Typedef of EntityPtr as IceInternal::Handle<Entity> for convenience.
VirtualRobot::ManipulationObjectPtr manipObj
Object used for visualisation purposes.
SoNode * visualization
Object visualisation.
EntityWrappers::SimoxObjectWrapperPtr simoxWrapper
VirtualRobot::CoinVisualizationPtr cv
SoNode * visualization
Robot visualisation.
VirtualRobot::RobotPtr robot
Robot used for visualisation purposes.
IceUtil::Time timestamp
Time when timestamped robot was updated.
VirtualRobot::RobotPtr timestampedRobot
armarx::RobotStateComponentInterfacePrx robotStateComponent