WorkingMemoryGuiPlugin.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::MemoryX::WorkingMemoryGuiPlugin
17* @author Nikolaus Vahrenkamp (vahrenkamp at kit dot edu)
18* @copyright 2012
19* @license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21
22*/
23
24#pragma once
25
26/* ArmarX headers */
28
31
36
38#include <MemoryX/gui-plugins/WorkingMemoryGui/ui_WorkingMemoryGuiPlugin.h>
39
40/* MemoryX headers */
42#include <MemoryX/interface/memorytypes/MemorySegments.h>
43#include <MemoryX/interface/workingmemory/AbstractWorkingMemoryInterface.h>
48
49/** VirtualRobot headers **/
50#include <VirtualRobot/Nodes/RobotNode.h>
51#include <VirtualRobot/Robot.h>
52#include <VirtualRobot/RobotNodeSet.h>
53#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
54#include <VirtualRobot/Visualization/VisualizationFactory.h>
55
56/* Qt headers */
57#include <QMainWindow>
58#include <QMatrix4x4>
59#include <QTreeWidget>
60#include <QTreeWidgetItem>
61
62/* Coin3D/SoQt headers */
63#include <atomic>
64#include <memory>
65
66#include <Eigen/Dense>
67
68#include <Inventor/Qt/SoQt.h>
69#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
70#include <Inventor/nodes/SoEventCallback.h>
71#include <Inventor/nodes/SoMatrixTransform.h>
72#include <Inventor/nodes/SoNode.h>
73#include <Inventor/nodes/SoSeparator.h>
74#include <Inventor/sensors/SoTimerSensor.h>
75
76namespace memoryx
77{
79
80 /** \class WorkingMemoryGuiPlugin
81 * \brief The WorkingMemoryGuiPlugin provides a widget that allows you to inspect the current state of the
82 * working memory.
83 * @see WorkingMemoryController
84 */
86 {
87 Q_OBJECT
88 Q_INTERFACES(ArmarXGuiInterface)
89 Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
90 public:
92 };
93
94 /**
95 \page MemoryX-GuiPlugins-WorkingMemoryEditor WorkingMemoryEditor
96 \brief This widget allows you to inspect the current state of the working memory.
97 \image html WorkingMemoryGui.png
98 You can inspect the current working memory.
99 The 3D viewer shows the currently known 3D workspace.
100 In the table in the center of the widget you find a list of all object and agent instances and their attributes that are currently
101 in the working memory.
102
103 When you add the widget to the Gui, you need to specify the following parameters:
104
105 Parameter Name | Example Value | Required? | Description
106 :---------------- | :-------------: | :-------------- |:--------------------
107 Gui Plugin Name | WorkingMemoryGuiPlugin | ? | ?
108 Working Memory Name | Working Memory | ? | ?
109 Working Memory Updates Topic | WorkingMemoryUpdates | ? | ?
110 Object Instances Segment Name | objectInstances | ? | The name of the segment in memory containing the object instances.
111 Agent Instances Segment Name | agentInstances | ? | The name of the segment in memory containing the agent instances.
112 World State Segment Name | worldState | ? | The name of the world state.
113 Extend datapaths with additional ArmarX packages (comma-separated) | Armar 3, Armar 4 | ? | ?
114
115 \note In order to use this widget there must be working memory available.
116
117 An example scenario for viewing and editing the WorkingMemory
118
119 \verbatim
120 ${MemoryX_DIR}/scenarios/WorkingMemoryGui
121 \endverbatim
122
123 The collection db.snapshots of memdb contains all snapshots such as
124 \li MobileKitchen_mm (millimeter)
125 \li KitchenKK
126
127 Those snapshots contain a list with segment names.
128 Each entry in this list refers to a collection name
129 which contains all objects in the scene for this segment.
130 An object entry contains:
131
132 \li object name
133 \li object class
134 \li object pose
135 \li object certainty
136
137 The WorkingMemoryExample contains several tests which load one Snapshot into WorkingMemory
138 and operates on it.
139 It is located in
140 \verbatim
141 ${MemoryX_DIR}/scenarios/WorkingMemoryExample
142 \endverbatim
143
144 The configuration file WorkingMemory.cfg contains important parameters such as
145
146 \li "DatabaseName": name of the main database (should be memdb in our case)
147 \li "KalmanFilter": object positions can be fused with a filter
148 \li "WMExample.SnapshotName": name of the snapshot to load
149 \li "WMExample.TestToRun": name of the test to execute
150 \li "WMExample.CommonPlacesSnapshot": name of the CommonPlaces snapshot which should be used
151 \li "MemoryX.PriorKnowledge.ClassCollections": which collections should be used for PriorKnowledge
152
153 After the configuration files are in the wanted state the Gui can be started with
154 \verbatim
155 ${MemoryX_DIR}/scenarios/WorkingMemoryExample/startGui.sh
156 \endverbatim
157
158 After the Gui has loaded click on the "addWidget()" menu and then select "WorkingMemoryGui".
159
160 \li ->setClass("cup", ..)
161
162 WorkingMemoryEditor API Documentation \ref WorkingMemoryController
163 \see WorkingMemoryGuiPlugin
164 */
165
166 /**
167 * @class WorkingMemoryController
168 * \brief This widget allows you to inspect the current state of the
169 * working memory.
170 * \see WorkingMemoryGuiPlugin
171 */
173 public armarx::ArmarXComponentWidgetControllerTemplate<WorkingMemoryController>,
174 public WorkingMemoryListenerInterface
175 {
176 Q_OBJECT
177 public:
179 ~WorkingMemoryController() override;
180
181 /* Inherited from Component */
182 void onInitComponent() override;
183 void onConnectComponent() override;
184 void onDisconnectComponent() override;
185 void onExitComponent() override;
186
187 /* Inherited from ArmarXWidget. */
188 static QString
190 {
191 return "MemoryX.WorkingMemoryGui";
192 }
193
194 static QIcon
196 {
197 return QIcon("://icons/brain.svg");
198 }
199
200 void loadSettings(QSettings* settings) override;
201 void saveSettings(QSettings* settings) override;
202 QPointer<QDialog> getConfigDialog(QWidget* parent = nullptr) override;
203
204 void configured() override;
205 SoNode* getScene() override;
206 QPointer<QDialog> getSceneConfigDialog(QWidget* parent = nullptr) override;
207
208 /* Inherited from WorkingMemoryListener. */
209 void reportEntityCreated(const std::string& segmentName,
210 const ::memoryx::EntityBasePtr& entity,
211 const ::Ice::Current& = Ice::emptyCurrent) override;
212 void reportEntityUpdated(const std::string& segmentName,
213 const ::memoryx::EntityBasePtr& entityBaseOld,
214 const ::memoryx::EntityBasePtr& entityBaseNew,
215 const ::Ice::Current& = Ice::emptyCurrent) override;
216 void reportEntityRemoved(const std::string& segmentName,
217 const ::memoryx::EntityBasePtr& entity,
218 const ::Ice::Current& = Ice::emptyCurrent) override;
219 void reportSnapshotLoaded(const std::string& segmentName,
220 const ::Ice::Current& = Ice::emptyCurrent) override;
221 void reportSnapshotCompletelyLoaded(const Ice::Current& c = Ice::emptyCurrent) override;
222 void reportMemoryCleared(const std::string& segmentName,
223 const ::Ice::Current& = Ice::emptyCurrent) override;
224
225 // overwrite setMutex, so thatwe can inform the debugdrawer
226 void setMutex3D(RecursiveMutexPtr const& mutex3D) override;
227 signals:
228
229 /* Emitted when: entities are fetched from the working memory, an entity is removed from the working memory or the working memory has been cleared. */
231 /* Emitted when: an entity is created/updated in the working memory. */
232 void entityChanged(memoryx::EntityBasePtr entity, QString entityType, bool isNew);
233
236
238
239 void signalClearEntities(const std::string& segmentName);
240
242
243 public slots:
244
245
246 /*!
247 * Fetches all entities stored in the objectInstances, agentInstances and worldState segments in the working memory.
248 */
250
252
253 /*!
254 * Shows information about a double-clicked item in the tree widget.
255 * \param item Double-clicked item.
256 * \param column Double-clicked column.
257 */
258 void treeItemDoubleClicked(QTreeWidgetItem* item, int column);
259 /*!
260 * Rebuilds the visualisation for all entities.
261 */
263 /*!
264 * Updates the visualisation for an entity.
265 * \param entityID Entity ID.
266 * \param entityType Entity type. Supported options are: objectInstances, agentInstances and worldState.
267 * \param \isNew TRUE if it is a new entity.
268 */
269 void updateEntityVisu(memoryx::EntityBasePtr entity, QString entityType, bool isNew);
270 /*!
271 * Setups visualisation for all entities stored in currentEntities if the uncertainty visualisation is checked.
272 * \param isChecked TRUE if the uncertainty visualisation option is checked.
273 */
274 void uncertaintyVisuToggled(bool isChecked);
275 void existenceCertaintyToggled(bool isChecked);
276 /*!
277 * Setups the visualisation for all entities stored in currentEntities.
278 */
279 void setupVisualization();
280 /*!
281 * Updates the item corresponding to an entity in the tree widget.
282 * \param entityId Entity ID.
283 * \param entityType Entity type. Supported options are: objectInstances, agentInstances and worldState.
284 * \param isNew TRUE if it is a new entity.
285 */
286 void updateEntityTree(memoryx::EntityBasePtr entity, QString entityType, bool isNew);
287
288 /*!
289 * \brief clearWorkingMemory deletes the current contents of WorkingMemory
290 */
291 void clearWorkingMemory();
292
293 /*!
294 * \brief Sets the visibility for debugDrawer's visualization layers
295 * \param show Whether they should be visible.
296 */
297 void showVisuLayers(bool show);
298
299 /*!
300 * \brief Sets the visibility for agents
301 * \param show Whether they should be visible.
302 */
303 void showAgents(bool show);
304
305
306 void showPlane(bool show);
307
308 /*!
309 * \brief agentsRemoved One or multiple agent(s) have been removed from memory. This method updates all Qt related things (visu/gui).
310 */
311 void agentsRemoved();
312
313 /*!
314 * \brief objectsRemoved One or multiple object(s) have been removed from memory. This method updates all Qt related things (visu/gui).
315 */
316 void objectsRemoved();
317
318 /*!
319 * Removes the item corresponding to an entity from the tree widget.
320 * \param entityId Entity ID.
321 * \param entityType Entity type.
322 */
323 void removeEntityInTree(const std::string entityId, const std::string entityType);
324
325
326 /*!
327 * Clears all entity data in the current agents and current entities maps. All cleared entities/agents are stored to the deletedAgents/deletedEntities map.
328 */
329 void clearEntitiesData();
330 /*!
331 * Clears all visu data of deletedAgents/deletedEntites all items in the tree widget.
332 */
333 void clearEntitiesVisu(const std::string& segmentName = "");
334
335 protected:
336 void exportToVRML();
337
338 /*!
339 * Updates joint values for all agents.
340 * \param event QTimerEvent.
341 */
342 void timerEvent(QTimerEvent*) override;
343
344 /*!
345 * Connects signals to the slots.
346 */
347 void connectSlots();
348
349 Ui::WorkingMemoryGuiPlugin ui;
350
352
354 {
355 VirtualRobot::RobotPtr robot; ///< Robot used for visualisation purposes.
356 SoNode* visualization = nullptr; ///< Robot visualisation.
358
359 /// Time when timestamped robot was updated.
360 IceUtil::Time timestamp = IceUtil::Time::seconds(0);
362 };
363
365 {
368 VirtualRobot::ManipulationObjectPtr
369 manipObj; ///< Object used for visualisation purposes.
370 SoNode* visualization = nullptr; ///< Object visualisation.
371 VirtualRobot::CoinVisualizationPtr cv;
372 };
373
375 {
377 QTreeWidget* tree;
378 QWidget* tab;
379 };
380
381 /* Maps entityId with data if the entity is of type ObjectInstance. */
382 using EntityEntryMap = std::map<std::string, ObjectDefinition>;
383
384 std::map<std::string, struct SegmentTab> segmentTabs; /*!< Current segment tabs. */
385 memoryx::NameList segmentNames; /*!< Name of current segments. */
386
387 EntityEntryMap currentEntities; /*!< Current entities of type ObjectInstance. */
389 deletedEntities; /*!< Entities that have been deleted (during last loop) of type ObjectInstance. */
390
393
394 SoSeparator* rootVisu; /*!< Root visualisation node. */
395 SoSeparator* objectsVisu; /*!< object visualisation node. */
396 SoSeparator* agentsVisu; /*!< agent visualisation node. */
397 SoSeparator* debugLayerVisu;
398 SoSeparator* planeVisu;
399
401 /*!
402 * Updates an entity of type ObjectInstance in the current entities map.
403 * obj Pointer to the entity instance.
404 */
405 void updateObjectData(const ObjectInstancePtr obj);
406
407 /*!
408 * Creates visualisation for entities of type ObjectInstance.
409 * \param objWrapper Simox wrapper of the entity.
410 */
412
413 /*!
414 * Updates visualisation for entities of type AgentInstance.
415 * \param objWrapper Simox wrapper of the entity.
416 */
418
419 /*!
420 * Setups visualisation for entities of type ObjectInstance.
421 * \param objWrapper Simox wrapper of the entity.
422 */
423 void setupEntityVisu(const ObjectDefinition& objWrapper);
424
425 /*!
426 * Updates an entity of type AgentInstance in the agents map.
427 * \param entity Pointer to the entity instance.
428 * \return True on success.
429 */
430 bool addAgent(const AgentInstancePtr agent);
431 /*!
432 * Creates visualisation for entities of type AgentInstance.
433 * \param entityId Entity ID.
434 */
435 void createAgentVisualisation(const std::string entityId);
436 /*!
437 * Updates visualisation for entities of type AgentInstance.
438 * \param entityId Entity ID.
439 */
440 void updateAgentVisualisation(const std::string entityId);
441 void updateAgentVisualisation(const EntityBasePtr entity);
442
443
444 /*!
445 * At tab for a given segment name if the tab does not already exist.
446 * \param segmentName segment name.
447 * \return index of new tab
448 */
449 int addTab(std::string segmentName);
450
451 /*!
452 * Removes all segment-tabs.
453 */
454 void removeTabs();
455
456 /*!
457 * Removes a single tab for a given segment name.
458 * \param segmentName segment name.
459 */
460 void removeTab(std::string segmentName);
461
462 void processPackages(const std::string& packages);
463
464 /*!
465 * \brief createEntity Updates currentEntities or currentAgents with data.
466 * \param entity
467 * \param entityType
468 * \return
469 */
470
471 bool createEntity(memoryx::EntityBasePtr entity, const std::string& entityType);
472
473 private:
474 std::recursive_mutex mutexEntities;
475 std::map<std::string, std::pair<long, armarx::FramedPosePtr>>
476 lastUpdated; // a map containing the timestamp (us) and the pose when the entity got last updated.
477
478 AbstractWorkingMemoryInterfacePrx memoryPrx;
479 ObjectInstanceMemorySegmentBasePrx objectInstancesPrx;
480 AgentInstancesSegmentBasePrx agentInstancesProxy;
481 WorldStateSegmentBasePrx worldStateProxy;
482 PersistentObjectClassSegmentBasePrx classesSegmentPrx;
483 PriorKnowledgeInterfacePrx priorKnowledgePrx;
484
485 GridFileManagerPtr fileManager;
486
487 QPointer<WorkingMemoryConfigDialog> dialog;
488
489 std::string settings_priorMemoryName;
490 std::string settings_workingMemoryName;
491 std::string settings_workingMemoryUpdatesTopic;
492 std::string settings_objectInstancesSegmentName;
493 std::string settings_agentInstancesSegmentName;
494 std::string settings_worldStateSegmentName;
495 std::string settings_packages;
496
497 int robotUpdateTimerId;
498
499
500 bool visuSetting_transparentExistanceCertatinty;
501 bool visuSetting_showObjectModels;
502
503 /* Maps entityId with data for entities of type AgentInstance. */
504 using AgentEntryMap = std::map<std::string, RobotDefinition>;
505
506 void updateAgent(const RobotDefinition& agent);
507
508 AgentEntryMap currentAgents; /*!< Current entities of type AgentInstance. */
509 AgentEntryMap
510 deletedAgents; /*!< Deleted entities of type AgentInstance (removed during last loop, visu needs to be updated). */
511
513 QToolBar* customToolbar;
514
515 QPointer<QDialog> sceneConfigDialog;
516 QPointer<armarx::DebugDrawerConfigWidget> debugDrawerConfigWidget;
517
518 // ArmarXWidgetController interface
519 public:
520 QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
522 };
523
524 using WorkingMemoryGuiPluginPtr = std::shared_ptr<WorkingMemoryController>;
525} // namespace memoryx
constexpr T c
The main gui interface.
std::shared_ptr< RecursiveMutex > RecursiveMutexPtr
std::shared_ptr< std::recursive_mutex > mutex3D
void processPackages(const std::string &packages)
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 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)
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)
std::map< std::string, ObjectDefinition > EntityEntryMap
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 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)
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 timerEvent(QTimerEvent *) override
void reportEntityCreated(const std::string &segmentName, const ::memoryx::EntityBasePtr &entity, const ::Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
Pure virtual hook for the subclass.
void createAgentVisualisation(const std::string entityId)
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
void updateAgentVisualisation(const std::string entityId)
void setupEntityVisu(const ObjectDefinition &objWrapper)
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 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...
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
Definition helper.h:35
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
VirtualRobot headers.
IceInternal::Handle< AgentInstance > AgentInstancePtr
Typedef of AgentEntityPtr as IceInternal::Handle<AgentEntity> for convenience.
std::shared_ptr< WorkingMemoryController > WorkingMemoryGuiPluginPtr
IceInternal::Handle< ObjectInstance > ObjectInstancePtr
IceInternal::Handle< EntityDrawerComponent > EntityDrawerComponentPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
VirtualRobot::ManipulationObjectPtr manipObj
Object used for visualisation purposes.
VirtualRobot::RobotPtr robot
Robot used for visualisation purposes.
IceUtil::Time timestamp
Time when timestamped robot was updated.
armarx::RobotStateComponentInterfacePrx robotStateComponent