The LongtermMemory component

Table of Contents

The longterm memory is a segmented memory and provides methods to store the current WorkingMemory into a snapshot and to fill the WorkingMemory with previously stored snapshots.

The working memory is a SegmentedMemory, which means that the data is organized in segments. By default there are the following segments available:

  • snapshots: A list of snapshots that have been previously stored.
  • oacs: OACS can be stored here.

Configuration

Following properties are supported:

  • DatabaseName: Name of the MongoDB dabatase (usually "memdb" is used here).
  • SnapshotListCollection (snapshots): MongoDB collection holding a list of snapshots with corresponding metadata
  • OacCollection (oacs): MongoDB collection holding all OACs

See List of Application & Component Properties for an overview of properties.

Usage

An exemplary application can be found in the applications/SimoxSceneImporter folder of the MemoryX sources.

The following code snippet shows how to save the current content of the WorkingMemory as a snapshot to the LongtermMemory.

void LongtermMemoryExample::onConnectComponent()
{
    // ...

    WorkingMemoryInterfacePrx memoryPrx = getProxy<WorkingMemoryInterfacePrx>("WorkingMemory");
    LongtermMemoryInterfacePrx longtermMemoryPrx = getProxy<LongtermMemoryInterfacePrx>("LongtermMemory");

    // now the working memory can be filled
    // e.g.
    ObjectInstanceMemorySegmentBasePrx objectInstancesMemoryPrx = memoryPrx->getObjectInstancesSegment();
    ObjectInstanceBasePtr object = new ObjectInstance("myObject");
    Eigen::Vector3f pos;
    pos << 100.0f , 0 , 0;
    FramedPositionBasePtr entityPos = new FramedPosition(pos, "");
    object->setPosition(entityPos);
    objectInstancesMemoryPrx->addEntity(object);

    // get snapshot name from property definition
    const std::string snapshotName = getProperty<std::string>("SnapshotName").getValue();
    if (!snapshotName.empty())
    {
        // save snapshot
        longtermMemoryPrx->saveWorkingMemorySnapshot(snapshotName, memoryPrx);
        ARMARX_INFO << "Snapshot succcessfully stored: " << snapshotName << flush;
    }
    else
        ARMARX_ERROR << "SnapshotName parameter must be specified!" << flush;

    // ...
}