Skip to content
Snippets Groups Projects
Commit e8f4f568 authored by Your Name's avatar Your Name
Browse files

Merge remote-tracking branch 'origin/master' into feature/armem_laser_scans

parents fbc7c5fb de533b2b
No related branches found
No related tags found
1 merge request!266Feature/armem laser scans
This commit is part of merge request !266. Comments created here will be created in the context of that merge request.
Showing
with 1679 additions and 4 deletions
...@@ -20,6 +20,7 @@ depends_on_armarx_package(ArmarXGui) ...@@ -20,6 +20,7 @@ depends_on_armarx_package(ArmarXGui)
find_package(DMP QUIET) find_package(DMP QUIET)
find_package(OpenCV QUIET) find_package(OpenCV QUIET)
find_package(IVT COMPONENTS ivt ivtopencv QUIET) find_package(IVT COMPONENTS ivt ivtopencv QUIET)
find_package(manif QUIET)
add_subdirectory(source) add_subdirectory(source)
......
# RobotAPI
## Documentation
[Wiki](docs)
docs/README.md 0 → 100644
[Aron](aron)
[ArMem](armem)
* [Introduction](introduction)
* [Existing Memories (Memory Servers)](existing_memory_servers_and_segments)
* [How to create a new Core Segment or Memory Server](how_to_create_a_new_core_segment_or_memory_server)
This is a list of existing memory servers, their core segments and their ARON data types.
# `RobotState`
* Memory Server: [`RobotStateMemory` (RobotAPI)](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/tree/master/source/RobotAPI/components/armem/server/RobotStateMemory)
* Core Segments:
| Core Segment Name | Type | Description | Example Entities |
|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|-------------------------|
| `Description` | [RobotDescription](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem_robot/aron/RobotDescription.xml) | Robot description (e.g. link to XML or URDF file) | |
| `Proprioception` | ToDo | Robot configuration and internal sensor values. | tbd |
| [`Localization`](RobotState/Localization) | [Transform](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem_robot_localization/aron/Transform.xml) | Transformations between frames {world,map,robot} to retrieve global robot pose. | armarx::aron::Transform |
Missing:
- Robot calibration: should be part of `Description` core segment
# `Object`
* Memory Server: [`ObjectMemory` (RobotAPI)](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/components/armem/server/ObjectMemory)
* Core Segments:
| Core Segment Name | Type | Description | Example Entities |
|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|-----------------------------------------------------|
| `Class` | [ObjectClass](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem_objects/aron/ObjectClass.xml) | Static description of a known object class. Entity names are (ArmarXObjects) object IDs. | `KIT/CoffeeFilters`, `YCB/001_chips_can` |
| `Instance` | [ObjectInstance](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem_objects/aron/ObjectInstance.xml) | Localized object instance. Entity names are (ArmarXObjects) object IDs. | `KIT/CoffeeFilters`, `YCB/001_chips_can/instance_1` |
| `ArticulatedObjectClass` | [RobotDescription](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem_robot/aron/RobotDescription.xml) | Static description of a known object class. Entity names are (ArmarXObjects) object IDs. | |
| `ArticulatedObjectInstance` | [Robot](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem_robot/aron/Robot.xml) | Localized object instance. Entity names are (ArmarXObjects) object IDs. | |
| `Attachments` | [ObjectAttachment and ArticulatedObjectAttachment](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem_objects/aron/Attachment.xml) | | |
# `Vision`
* Memory Server: [`ArMemVisionMemory` (VisionX)](https://git.h2t.iar.kit.edu/sw/armarx/visionx/-/tree/master/source/VisionX/components/armem/ArMemVisionMemory)
* Core Segments:
| Core Segment Name | Type | Description | Example Entities |
|-------------------|--------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------|------------------|
| `ImageRGB` | [`ImageRGB`](https://git.h2t.iar.kit.edu/sw/armarx/visionx/-/blob/master/source/VisionX/libraries/ArMem/aron/ImageRGB.xml) | RGB images (mono and stereo) of a camera | image |
| `ImageDepth` | [`ImageDepth`](https://git.h2t.iar.kit.edu/sw/armarx/visionx/-/blob/master/source/VisionX/libraries/ArMem/aron/ImageDepth.xml) | Depth images of an RGB-D or stereo camera | image |
# `Speech`
* Memory Server: [`SpeechMemory` (SpeechX)](https://git.h2t.iar.kit.edu/sw/armarx/speechx/-/tree/master/source/SpeechX/components/SpeechMemory)
* Core Segments:
| Core Segment Name | Type | Description | Example Entities |
|-------------------------|-----------------|---------------------------------------------------------------------------|------------------|
| `Command` | `SpeechCommand` | Language commands from speech (topic `Speech_Commands`). | `command` |
| `TextListenerInterface` | `Text` | Data from `TextListenerInterface` topics. (`TextToSpeech`, `RobotAction`) | `text` |
...
# `Skills`
* Memory Server: [`SkillsMemory` (RobotAPI)](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/tree/master/source/RobotAPI/components/armem/server/SkillsMemory)
* Core Segments:
| Core Segment Name | Type | Description | Example Entities |
|-------------------|--------------|-------------------------------------|------------------|
| `Statechart` | `Transition` | Transitions in ArmarX state charts. | tbd |
# `GeneralPurpose`
This memory is meant to allow for a quick-and-dirty integration of your data type in the memory framework. When your development finishes a stable state, consider creating moving the core segment(s) to an existing memory server or creating a new dedicated memory server.
* Memory Server: [`GeneralPurposeMemory` (RobotAPI)](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/tree/master/source/RobotAPI/components/armem/server/GeneralPurposeMemory)
* Core Segments:
| Core Segment Name | Type | Description | Example Entities |
|----------------------------------------|------|-------------|------------------|
| None. You can add segments on the fly. | | | |
# `Mapping`
* Memory Server: `ToDo`
* Core Segments:
| Core Segment Name | <br/>Type | Description | Example Entities |
|---------------------------------|-----------|--------------------------------------------------|------------------|
| [`Mapping`](RobotState/Mapping) | `ToDo` | Mapping related sensor data (e.g. point clouds). | tbd |
# `Example`
An example memory server (alongside a matching client) showing how to implement a standard memory server and test the framework during development.
* Memory Server: [`ExampleMemory` (RobotAPI)](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/tree/master/source/RobotAPI/components/armem/server/ExampleMemory)
* Core Segments:
| Core Segment Name | Type | Description | Example Entities |
|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------|------------------|
| `ExampleData` | [ExampleData](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml) | Some example data. | example |
\ No newline at end of file
# The localization segment within the RobotState memory
## Concept
There exist various frames that are needed to obtain the robot's global pose (pose within in the global frame):
* [global] the "world" frame.
* [map] During mapping, the robot does not have knowledge about the world but creates a local map (with "map" as root frame). All map features (e.g. point clouds, occupancy grids, ...) are linked to this frame.
* [odom] The odometry as an integration of the robot's velocity.
* [robot] The robot's root frame
![frames](res/frames.png)
For each transformation between frames, there exist individual components:
* [global->map] **Map registration:** given a scene (objects with known poses, e.g. walls, ...), this component obtains a static transformation between a the scene and the map.
* [map->odom] **Localization** The localization component computes the transformation [map->robot] and performs map corrections by updating [map->odom].
* [odom->robot] **Odometry**
### Memory design
Within the core segment, each robot has its own provider segment (here: Armar6). Within the provider segment, entities describe the transformations between the frames ("Global,Map" -> [global->map]).
![Localization](res/localization-armem.png)
### Using the localization memory
See **RobotAPI/libraries/armem_robot_localization**
There exist two classes:
* TransformWriter to send transformations to memory
* TransformReader to obtain transformations between any of the frames; can also be used to obtain the "robot's global pose"
For an example, see RobotComponents/components/carographer_mapping_and_localization (currently branch feature/cartographer_integration)
docs/armem/existing_memory_servers_and_segments/RobotState/Localization/res/frames.png

13.7 KiB

# The mapping segment within the RobotState memory
## Concept
Within the memory segment, sensor data is stored that is relevant for
* mapping
* map registration
![transformations_frames-Page-2](res/transformations_frames-Page-2.png)
In order to make a new type of data available in the memory system, you first need to create an ARON XML file. Please refer to [Aron/CodeGeneration](Aron/CodeGeneration) if you want to know how to do so.
[[_TOC_]]
<!--
# Define your data type in ARON
Consider you want to use a data type called `MyData` (in the namespace `armarx::mydata`) in the memory system. First, you need to describe it in ARON.
- Choose a library in an ArmarX package where your data type will be defined (or create a new one). Here, we will call it `MyDataLib`.
- In the directory `MyDataLib/`, create a directory `aron/` (if necessary). Inside, add a file `MyData.xml`. The directory structure should now look like this:
```plaintext
.../libraries/
- MyDataLib/
- CMakeLists.txt
- ...
- aron/
- MyData.xml
```
- In the `CMakeLists.txt`, add or extend after the definition of the target (e.g. through add_library or add_component):
```cmake
armarx_enable_aron_file_generation_for_target(
TARGET_NAME
${LIB_NAME}
ARON_FILES
aron/MyData.xml
)
```
- Define your data in ARON. A hello world example could look like this:
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<AronTypeDefinition>
<CodeIncludes>
</CodeIncludes>
<AronIncludes>
</AronIncludes>
<GenerateTypes>
<Object name="armarx::mydata::arondto::MyData">
<ObjectChild key="helloWorld">
<String />
</ObjectChild>
</Object>
</GenerateTypes>
</AronTypeDefinition>
```
Note:
- `<Object>` defines a new ARON object type (generating a C++ class) containing a number of children.
- `<ObjectChild>` defines a child (generating a public member variable of the generated C++ class, with `key` specifying the member's name).
- `<String />` inside a `<ObjectChild>` defines the type of the child. It can be a number of primitive types, or fully qualified names of other ARON objects.
Conventions:
- Put your ARON object type into a `arondto::` namespace inside your usual namespace (e.g., `armarx::mydata::arondto::MyData`), where "DTO" stands for "Data Transfer Object". This way, you can define or use a custom or existing C++ type with more methods/intelligence in the usual namespace in your business logic code (e.g. `armarx::mydata::MyData`).
Here is an example of an ARON object representing the business object (BO) type `simox::OrientedBox`:
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<AronTypeDefinition>
<CodeIncludes>
<Include include="<Eigen/Core>" />
<Include include="<Eigen/Geometry>" />
</CodeIncludes>
<GenerateTypes>
<Object name="simox::arondto::OrientedBox">
<ObjectChild key='center'>
<Position />
</ObjectChild>
<ObjectChild key='orientation'>
<Orientation />
</ObjectChild>
<ObjectChild key='extents'>
<Position />
</ObjectChild>
</Object>
</GenerateTypes>
</AronTypeDefinition>
```
Note:
- (At the moment), you need to specify `<CodeIncludes>` to Eigen to use `Pose`, `Position` and `Orientation` (which are translated to `Eigen::Matrix4f`, `Eigen::Vector3f`, and `Eigen::Quaternionf` in C++).
If you want to use an ARON object type defined in another file, this could look like this:
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<AronTypeDefinition>
<CodeIncludes>
<Include include="<RobotAPI/libraries/aron/common/aron/AxisAlignedBoundingBox.aron.generated.h>" />
<Include include="<RobotAPI/libraries/aron/common/aron/OrientedBox.aron.generated.h>" />
<Include include="<RobotAPI/libraries/aron/common/aron/PackagePath.aron.generated.h>" />
<Include include="<RobotAPI/libraries/ArmarXObjects/aron/ObjectID.aron.generated.h>" />
<Include include="<RobotAPI/libraries/ArmarXObjects/aron/ObjectNames.aron.generated.h>" />
<Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" />
</CodeIncludes>
<AronIncludes>
<Include include="<RobotAPI/libraries/aron/common/aron/AxisAlignedBoundingBox.xml>" />
<Include include="<RobotAPI/libraries/aron/common/aron/OrientedBox.xml>" />
<Include include="<RobotAPI/libraries/aron/common/aron/PackagePath.xml>" />
<Include include="<RobotAPI/libraries/ArmarXObjects/aron/ObjectID.xml>" />
<Include include="<RobotAPI/libraries/ArmarXObjects/aron/ObjectNames.xml>" />
<Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" />
</AronIncludes>
<GenerateTypes>
<Object name="armarx::armem::arondto::ObjectClass">
<ObjectChild key="id">
<armarx::arondto::ObjectID />
</ObjectChild>
<ObjectChild key="simoxXmlPath">
<armarx::arondto::PackagePath />
</ObjectChild>
<ObjectChild key="meshWrlPath">
<armarx::arondto::PackagePath />
</ObjectChild>
<ObjectChild key="meshObjPath">
<armarx::arondto::PackagePath />
</ObjectChild>
<ObjectChild key="aabb">
<simox::arondto::AxisAlignedBoundingBox />
</ObjectChild>
<ObjectChild key="oobb">
<simox::arondto::OrientedBox />
</ObjectChild>
<ObjectChild key="names">
<armarx::arondto::ObjectNames />
</ObjectChild>
</Object>
</GenerateTypes>
</AronTypeDefinition>
```
Note:
- You need to include other ARON files in `<AronIncludes>`. The paths have the same form as usual C++ includes and point to the ARON XML files.
- At the moment, you also have to `<CodeInclude>` the respective generated headers (`.../MyData.aron.generated.h`). These should be generated automatically in the future.
# (Optional) Add conversions to existing (potentially more intelligent) C++ types
Consider the case of `simox::OrientedBoxf` and `simox::arondto::OrientedBox`. The former is the business object (BO), used in daily business logic code (as it offers useful methods to construct and manipulate it). The latter is a mere data storage used to transfer the data, which is called a data transfer object (DTO).
Therefore, you usually want to convert a `simox::arondto::OrientedBox` to a `simox::OrientedBoxf` as soon as you want to do things other than passing it around over network (e.g., at the beginning of a component method or after reading it from the working memory). Likewise, you want to convert a `simox::OrientedBoxf` to a `simox::arondto::OrientedBox` when you send the information over network or store it in the memory.
To allow this conversion, follow these steps:
- In your library, add a file pair `aron_conversions.{h, cpp}` next to your `aron/` directory and add them to the `CMakeLists.txt`
- In the header, declare functions following this form:
```cpp
#pragma once
#include <SimoxUtility/shapes/OrientedBox.h>
#include <RobotAPI/libraries/aron/common/aron/OrientedBox.aron.generated.h>
namespace simox
{
void fromAron(const arondto::OrientedBox& dto, OrientedBoxf& bo);
void toAron(arondto::OrientedBox& dto, const OrientedBoxf& bo);
}
```
Note:
- Both functions take the DTO first and the BO second.
- `fromAron()` takes a `const` DTO and a `non-const` BO.
- `toAron()` takes a `non-const` DTO and a `const` BO.
- All arguments are passed as reference (especially the `non-const` arguments).
- The functions are defined in the BO's namespace (`simox` in this example, `armarx::mydata` in the running example).
* In the cpp file, define the functions like this:
```cpp
#include "aron_conversions.h"
// Include this and use armarx::aron::to/fromAron() for std::vector, std::map.
#include <RobotAPI/libraries/aron/common/aron_conversions.h>
// Include other aron_conversions.h files for other ARON types
void simox::fromAron(const arondto::OrientedBox& dto, OrientedBoxf& bo)
{
bo = OrientedBoxf(dto.center, dto.orientation, dto.extents);
}
void simox::toAron(arondto::OrientedBox& dto, const OrientedBoxf& bo)
{
dto.center = bo.center();
dto.orientation = bo.rotation();
dto.extents = bo.dimensions();
}
```
Note:
- The implementation depends on your data. It might be as simple as copying all members, or require more complex conversions. Especially, you might use `fromAron()` for `toAron()` for other ARON object types.
-->
# Create a new memory server
> **Note:** If you plan to extend an existing memory server, you can skip this step.
If your data should be stored in a new memory server, follow these steps:
Create a new component, let's say `MyMemory`:
```plaintext
# In the root directory of your ArmarX package:
armarx-package add component MyMemory
```
Then, extend the new component by the respective component plugin.
Add the include:
```cpp
#include <RobotAPI/libraries/armem/server/plugins/ReadWritePluginUser.h>
// Or:
#include <RobotAPI/libraries/armem/server/plugins/ReadOnlyPluginUser.h>
```
Make the component derive from the component plugin user:
```cpp
class MyMemory :
virtual public armarx::Component
// v Add this line ... v
, virtual public armarx::armem::server::ReadWritePluginUser
// v ... or this line ... v
, virtual public armem::server::ReadOnlyPluginUser
```
Don't forget to add the respective library to your `CMakeLists.txt`:
```cmake
set(COMPONENT_LIBS
...
# Add this:
armem
...
)
```
**If the component already implements an ice interface,** you have to add the memory server into face to it (otherwise, you will receive `no unique final overrider for 'virtual function ...'` errors by the compiler):
```cpp
// memory_tutorial/source/memory_tutorial/components/object_memory/ComponentInterface.ice
#pragma once
// v either include this one (read-write) v
#include <RobotAPI/interface/armem/server/MemoryInterface.ice>
// v or this one (read-only) v
// #include <RobotAPI/interface/armem/server/ReadingMemoryInterface.ice>
module memory_tutorial { module components { module object_memory
{
interface ComponentInterface
// v either extend from this one (read-write) v
extends armarx::armem::server::MemoryInterface
// v or this one (read-only) v
// extends armarx::armem::server::ReadingMemoryInterface
{
...
};
};};};
```
In this case, make sure `RobotAPIInterfaces` is in the Ice dependencies of your ice library:
```cmake
armarx_add_component(object_memory
ICE_FILES
ComponentInterface.ice
ICE_DEPENDENCIES
...
RobotAPIInterfaces
...
```
You can set the memory name of the memory server in the `createPropertyDefinitions()`:
```cpp
#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h>
...
armarx::PropertyDefinitionsPtr MyMemory::createPropertyDefinitions()
{
armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier());
...
// Set the memory name:
workingMemory().name() = "My";
...
return defs;
}
```
**Note:**
* The `ReadWritePluginUser` implements the ice interface `MemoryInterface`, which combines, among others, the `ReadingMemoryInterface` and the `WritingMemoryInterface`.
* The `ReadOnlyPluginUser` only implements the `ReadingMemoryInterface`.
* Both provide a working memory data storage `workingMemory()` (of type `armem::server::wm::Memory`) and an `iceAdapter()` (`armem::server::MemoryToIceAdapter`).
That's it: Your component is now a memory server.
# Add a core segment with your new data type in a memory server
> Wait, how does the new memory server know of my specially written ARON type?
Oh right, it doesn't. At least not yet. But this is easy to fix: We just have to add a core segment.
> What on earth is a core segment?
A _segment_ is a section of a memory (server) containing data of a specific type, i.e. they are homogeneous data containers (in contrast to heterogeneous, which would mean they contain different kinds of data) (see the [Introduction](ArMem/Introduction)).
There are two kinds of segments: _core_ segments, and _provider_ segments:
* **Core segments** are usually added by the memory server itself with a name and the ARON data type the core segment is going to keep.
* **Provider segments** are usually added by clients committing data to the memory. You can think of them as "sub-segments" of a (core) segment, providing a namespace for the provider's entities and some additional features.
> ... what?
Just stick with me, you'll get used to it.
> Okay ... but how does the memory add the ... core segment?
A fine question! Luckily, that's very simple. All we need is your ARON type, a name and the working memory data structure.
> ...
Okay, okay, I'll come to the code. Adding a core segment merely alters a local data structure (it is not an ice/network operation). Thus, we can do it in `onInitComponent()`:
```cpp
void MyMemory::onInitComponent()
{
workingMemory().addCoreSegment("Data", armarx::mydata::arondto::MyData::toAronType());
}
```
* `workingMemory()` is a function provided by the component plugin user (`ReadWritePluginUser` or `ReadOnlyPluginUser`) returning a reference to the working memory data of the type `armem::server::wm::Memory`.
* `addCoreSegment()` adds a core segment. It takes a name and (optionally) an ARON type.
* `"Data"` is the name of the core segment.
* It should refer to a modality or concept, not to its elements (i.e. prefer "Instance" over "Instances" and "Location" over "Locations").
* Also, try to avoid repeating the memory name, as the core segment's ID is prepended by the memory name anyway (e.g. "Object/Instance" over "Object/ObjectInstance" and "Navigation/Location" over "Navigation/NavigationLocation").
* `armarx::mydata::arondto::MyData` is the C++ class generated from your `MyData.xml` ARON XML description file.
* `::toAronType()` creates a runtime type object describing the ARON type. This allows, e.g., the `MemoryViewer` GUI to show the data in a suitable manner (e.g. a pose as an affine transformation instead of a 4x4 matrix).
* Of course, you need to include the respective header: It's located at the same path where your XML is. For example, for the `ObjectInstance.xml` located at `RobotAPI/libraries/armem_objects/aron/ObjectInstance.xml`, the include would be:
```cpp
#include <RobotAPI/libraries/armem_objects/aron/ObjectInstance.h>
```
Note that you need to include the `.h` file, not the `.xml`. As the generated class is header-only, you do not need to link any libraries in your `CMakeLists.txt`.
When you now start your new memory server and the MemoryNameSystem (MNS) (e.g. using the scenario _ArMemCore_ in RobotAPI), and open the _MemoryViewer_ gui plugin, you should see an entry for your memory (`My`) and the core segment (`Data` under `My`).
# Conclusion
That's it! You now have a memory server providing a place where your nice and interesting data can feel welcome, and where interested listeners would look to find it.
[Next, we learn how to commit data to the memory, and query data from the memory.](ArMem/How-to-read-from-and-write-to-a-Memory-Server)
\ No newline at end of file
# Distributed Memory
The ArMem memory system is distributed: It is comprised of several **memory servers** storing data in a hierarchical structure.
A memory server can be defined in any ArmarX package and defines which kind of data it stores (e.g. robot state, object classes and instances, visual data, speech, ...).
As a memory server knows which data it stores, it can provide special behaviour, such as custom visualization, aggregation, interpolation or prediction.
As each server is a separate component describing its own structure, it is simple to add new memory servers containing special data types, which are defined in ArmarX packages further down in the dependency chain.
All memory servers follow the same hierarchical data structure and self-describing data format.
The data structure consists of several levels, storing histories/timelines of different entities stored in different segments (see "Memory Levels" below).
The common data format is ARON (ArmarX Object Notation), which is a self-describing, hierarchical data format, allowing extensive introspection as well as general storage.
Each item in the memory (i.e. entries in all levels) can be identified with a **Memory ID**, which contains the keys of each (specified) level. For example, a core segment ID specifies the memory name and core segment name, while an entity instance ID specifies the whole path to the leaf of the data structure.
Technically, each memory server is one ArmarX component implementing the `armem::server::MemoryInterface` (comprising a `ReadingMemoryInterface` and a `WritingMemoryInterface`).
Memory servers register themselves in the **Memory Name System (MNS)**, where they can be found by their (semantic) memory name (which is usually a short, human-readable name such as "Robot", "Object" or "Vision").
Memory servers receive data via **commits** (via the `WritingMemoryInterface`), and return data according to **queries** (via the `ReadingMemoryInterface`).
# Memory Levels
A memory server stores data in a hierarchical structure consisting of several levels:
```
- Grasping (Memory)
- Grasps (Core Segment)
- KnownObjectGraspPlanner (Provider Segment)
- my_object (Entity)
- t = 2021-03-09 14:24:20.064524 (Entity Snapshot)
- 00 (Entity Instance)
- 01 (Entity Instance)
- 02 (Entity Instance)
```
| Level | Key | Description | Examples | Implementation |
| ----- | --- | ----------- | -------- | -------------- |
| Memory | Name (String) | Semantic grouping of one or more core segments. Corresponds to one memory server. | Robot, Object, Vision | [Memory](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem/core/Memory.h) |
| Core Segment | Name (String) | Building block of a memory containing homogeneous data of a specific (ARON) type. Specifies a _Core Segment Type_ which all provided data must comply to. | (Robot) Configuration, (Object) Classes, Known (Object) Instances, ImageRGB | [CoreSegment](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem/core/CoreSegment.h) |
| Provider Segment | Name (String) | Sub-segment of a core segment which contains the data from a single source (e.g. a camera, a method, a component). Can define a _Provider Segment Type_ which extends the _Core Segment Type_. | Primsense, SimTrack, MyGraspPlanner | [ProviderSegment](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem/core/ProviderSegment.h) |
| Entity | Name (String) | A single thing or concept whose properties change over time. An entity has a history / timeline, i.e. a sequence of snapshots storing the entity's properties at a specific point in time. | `image`, `some_object`, `some_object_grasps` | [Entity](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem/core/Entity.h) |
| Entity Snapshot | Timestamp (`armem::Time` aka `IceUtil::Time`) | An entry of an entity's history, i.e. the state of an entity at a specific point in time. Can contain multiple (entitiy) instances. | Image, object instance, grasp hypotheses at a time *t* | [EntitySnapshot](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem/core/EntitySnapshot.h) |
| Entity Instance | Index (int) | One instance of the segment's ARON type. | left/right stereo image (at time t), object (at time t), grasp hypothesis (one of many at time t) | [EntityInstance](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem/core/EntityInstance.h) |
| Entity Instance Metadata | -- | Metadata stored alongside the instance's data. | Further timesteps, confidence | [EntityInstanceMetadata](https://git.h2t.iar.kit.edu/sw/armarx/robot-api/-/blob/master/source/RobotAPI/libraries/armem/core/EntityInstance.h) |
* [Introduction](introduction)
* [Code Generation](code_generation)
* [Visitors](visitors)
* [Readers, Writers and Conversion](conversion)
This diff is collapsed.
# Aron conversion
Aron offers ways to simply convert any aron object into another representation (e.g. from variant to nlohmann::json or vice versa). To do so, it makes use of specific readers and writers. In the following we will only describe the readers, writers and converters for Aron data, not for types (but the principle is the same).
## Readers
An Aron reader is used to get information of an Aron object in a specific representation. Assume you have an nlohmann::json aron object which contains some information (E.g. it is a dict, containing some members, ...). We need this information to create another object in another representation with the same content.
To do so, you only have to implement the armarx::aron::data::ReaderInterface class. It needs one template parameter for your InputType (e.g. here const nlohmann::json).
The interface provides the following pure virtual methods:
```cpp
virtual void readList(InputType& input, std::vector<InputTypeNonConst>& elements) = 0;
virtual void readDict(InputType& input, std::map<std::string, InputTypeNonConst>& elements) = 0;
virtual void readNDArray(InputType& input, std::vector<int>& shape, std::string& typeAsString, std::vector<unsigned char>& data) = 0;
virtual void readInt(InputType& input, int& i) = 0;
virtual void readLong(InputType& input, long& i) = 0;
virtual void readFloat(InputType& input, float& i) = 0;
virtual void readDouble(InputType& input, double& i) = 0;
virtual void readString(InputType& input, std::string& s) = 0;
virtual void readBool(InputType& input, bool& i) = 0;
```
You have to implement the function so that the non-const arguments of the method will be filled with the values of the input. E.g. the implementation of the readString method for the nlohmann::json reader would be:
```cpp
void NlohmannJSONReader::readString(const nlohmann::json& input, std::string& i)
{
if (input[rw::json::constantes::TYPE_SLUG] != expectedType)
{
throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Wrong type in json encountered.", input[rw::json::constantes::TYPE_SLUG], expectedType);
}
i = input[rw::json::constantes::VALUE_SLUG];
}
```
Of course, the way to get the member depend on the way how to construct (writer) the nlohmann::json.
\ No newline at end of file
[[_TOC_]]
# Aron structure
Aron (ArmarX Object Notation) is the ArmarX implementation of variants which can be transferred over the network via ZeroC Ice. Further, Aron is the data representation used in the ArmarX Memory System [ArMem](ArMem/ArMem). We distinguish between:
- type specification vs. data information
- data transfer object (in the following called Aron DTO) vs. its corresponding c++ wrapper (in the following called Aron object). The DTO specification is done in ice so that every Aron object can be transferred via ice.
## Aron Type specification
An Aron type specification defines the static type for an Aron data DTO or an Aron data object. It does not contain any data (e.g. an aron type list only knows the accepted type, not the list members). Since Aron supports maybe types (raw ptr, smart ptr, optional), every Aron type DTO contains a special member. It can only consist of the following types and information (AronVariant means any Type):
```cpp
Object { // dto called armarx::aron::type::dto::AronObject
string name;
AronVariant extends;
map<string, AronVariant> memberTypes;
}
Dict { // dto called armarx::aron::type::dto::Dict
AronVariant acceptedType;
}
List { // dto called armarx::aron::type::dto::List
AronVariant acceptedType;
}
Pair { // ...
AronVariant acceptedType1;
AronVariant acceptedType2;
}
Tuple {
vector<AronVariant> acceptedTypes;
}
IntEnum {
string name;
map<string, int> acceptedValues;
}
NDArray {
int ndim;
type type; // in [uint8, int8, uint16, int16, uint32, int32, float32, float64]
}
Matrix {
int rows, cols;
type type; // in [int16, int32, int64, float32, float64]
}
Quaternion {
type type; // in [float32, float64]
}
Position {
}
Orientation {
}
Pose {
}
Image {
pixelType type; // in [rgb24, depth32]
}
PointCloud {
voxelType type; // in [PointXYZ, PointXYZI, PointXYZL, PointXYZRGB, PointXYZRGBA, PointXYZRGBL, PointXYZHSV]
}
Int { // dto called armarx::aron::type::dto::AronInt
}
Long { // dto called armarx::aron::type::dto::AronLong
}
Float { // dto called armarx::aron::type::dto::AronFloat
}
Double { // dto called armarx::aron::type::dto::AronDouble
}
String { // dto called armarx::aron::type::dto::AronString
}
Bool { // dto called armarx::aron::type::dto::AronBool
}
Time { // dto called armarx::aron::type::dto::AronTime
}
```
## Aron Data specification
Aron data objects and Aron data DTOs are similar structured to type objects and type DTOs. However, there are less classes for data objects and data DTOs. Aron data is completely decoupled from the static types and contains the data members (e.g. an aron data list only contains the list members (as AronVariants) and not the accepted type):
```cpp
Dict { // dto called armarx::aron::data::dto::Dict
map<string, AronVariant> members;
}
List { // dto called armarx::aron::data::dto::List
vector<AronVariant> elements;
}
NDArray { // ...
vector<int> shape;
string type;
vector<byte> data;
}
Int { // dto called armarx::aron::data::dto::AronInt
int value;
}
Long { // dto called armarx::aron::data::dto::AronLong
long value;
}
Float { // dto called armarx::aron::data::dto::AronFloat
float value;
}
Double { // dto called armarx::aron::data::dto::AronDouble
double value;
}
String { // dto called armarx::aron::data::dto::AronString
string value;
}
Bool { // dto called armarx::aron::data::dto::AronBool
bool value;
}
```
Please note that every Aron data object or DTO can be NULL!. The reason is, that if the type supports maybe types and a member is e.g. optional the data must support maybetype as well. If a generated Aron class (We come to the code generation later) has an optional member, this member will be translated into a NULL Aron object and DTO.
## Connection of Aron data and Aron type
Aron data contains less classes than Aron type. Because Aron data objects and DTOs do not check the type of the members (they can be any aron data (AronVariant)), we can only validate an aron data object or DTO if we have the type information. The following mapping describes, how data and types correspond.
```cpp
Aron Type | Aron Data
-------------------------------
Object -> Dict
Dict -> Dict
List -> List
Pair -> List
Tuple -> List
NDArray -> NDArray
Matrix -> NDArray
Quaternion -> NDArray
Position -> NDArray
Orientation -> NDArray
Pose -> NDArray
Image -> NDArray
PointCloud -> NDArray
IntEnum -> Int
Int -> Int
Long -> Long
Float -> Float
Double -> Double
String -> String
Bool -> Bool
Time -> Long
```
If no type object or DTO is available, we can at least derive some information from the data object (e.g. "it is a data dict, so the type cant be list").
To differ between data and type makes it easier to work with these Variants. In most cases, the type information is not relevant. Then you only have to check for the data type.
# Aron data and type objects
As already mentioned, we implemented wrapper classes around the DTO. These classes offer convenience methods and conversions and make lots things easier when working directly with Aron. These classes can be found at aron/core/[data,type]/variant/Variant.h.
The Aron objects have more or less the same structure as the DTOs (see above). Everything is stored as a shared_ptr (e.g. members, elements, acceptedTypes, ...). If you want to implement a method which takes any Aron data object as input, you can use the base class of every Aron data object:
```cpp
void myFancyMethod(const armarx::aron::data::VariantPtr& variant);
```
If you want to check, what a variant really is, you can use the descriptor of the object:
```cpp
armarx::aron::data::VariantPtr variant; // <-- the variant
auto desc = variant->getDescriptor();
switch(desc)
{
case armarx::aron::data::Descriptor::eDict: ...
case armarx::aron::data::Descriptor::eList: ...
...
}
```
If you have a DTO, you dont know the exact type but you want to have a Aron object you can make use of the static construction methods:
```cpp
armarx::aron::data::dto::GenericData dto; // <-- the DTO variant
auto aron = armarx::aron::data::Variant::FromAronDTO(dto);
```
If you know the type, you can use the constructor the specific Aron object.
## Example to create an Aron data dict from scratch
Goal: Have an Aron dict with a list as member "the_list" and some values in it. Then echo the members and their descriptor as a string.
```cpp
using namespace armarx;
// setup aron object
auto dict = std::make_shared<aron::data::Dict>();
{
auto list = std::make_shared<aron::data::List>();
for (unsigned int i = 0; i < 10; ++i)
{
list->addElement(std::make_shared<aron::data::Int>(i));
}
dict->addElement("the_list", list);
}
// echo
auto listVariant = dict->getElement("the_list"); // will return a aron::data::VariantPtr
auto list = aron::data::List::DynamicCastAndCheck(listVariant); // cast and check whether the cast was successful
for (const auto& intVar : list->getElements())
{
auto i = aron::data::Int::DynamicCastAndCheck(intVar);
std::cout << "The value is: " << i->getValue() << std::endl;
std::cout << "The descriptor is: " << aron::data::defaultconversion::string::Descriptor2String.at(i->getDescriptor()) << std::endl;
}
```
Please note that we might add more methods or make the current ones more flexible (e.g. such as nlohmann::json).
# Lessons learned
- There is a difference between Aron data and Aron type
- There is a difference between Aron objects and Aron DTOs
- How are Aron DTOs structured
- How do Aron data and Aron types correspond
- How to use the Aron objects
\ No newline at end of file
[[_TOC_]]
# Visitors
Visitors are a useful tool to define specific methods for specific types without specifying the `switch(): case: ...` again and again. Further, recursive visitors offer a convenient way to iterate through the tree-like structure of any Aron object. (Please note that right now the implementation does not check for cycles!). Again, we will only look at data visitors since the implementation of type visitors is more or less similar.
## Non-recursive Visitors
First, there are "normal" visitors. They are used to get rid of the big switch-case statement when getting an Aron object with unknown type. Further, these visitors can be used to convert an Aron object from one representation into another (see [Aron/Conversion](Aron/Conversion)).
The Visitor Base-class offers the following pure virtual methods which you have to implement:
```cpp
virtual data::Descriptor getDescriptor(Input&) = 0;
virtual void visitDict(Input&) {};
virtual void visitList(Input&) {};
virtual void visitNDArray(Input&) {};
virtual void visitInt(Input&) {};
virtual void visitLong(Input&) {};
virtual void visitFloat(Input&) {};
virtual void visitDouble(Input&) {};
virtual void visitBool(Input&) {};
virtual void visitString(Input&) {};
virtual void visitUnknown(Input&) { throw error::AronException(__PRETTY_FUNCTION__, "Unknown type in visitor."); }
```
`Input` is a template parameter, defining the Input-type (e.g. `const armarx::aron::data::VariantPtr` for a `VariantVisitor` Implementation).
The method `getDescriptor(Input&)` is used for the switch case interally.
As you can see the `VariantVisitor` always gets a generic variant as input in each function. This means that, although the Visitor guarantees that the input is correct, you have to cast the class to the correct type. For widely used Visitors, the Aron library offers convenience implementations (e.g. for Variants and for nlohmann::json inputs). The convenience class for Variants additionally adds overloads where the input is already casted correctly (you can decide which method you want to override).
To use a Visitor, you have to use the function
```cpp
void visit(VisitorImplementation& v, typename VisitorImplementation::Input& o);
```
which takes the visitor and the input as arguments and does the switch-case.
## Recursive Vistors
Recursive visitors are similar to normal vistors but they continue "visiting" until the object is fully visited. For containers (e.g. dicts, lists) they offer two methods each:
```cpp
virtual void visitDictOnEnter(Input& element) {};
virtual void visitDictOnExit(Input& element) {};
virtual void visitListOnEnter(Input& element) {};
virtual void visitListOnExit(Input& element) {};
```
The `*OnEnter` method is called before iterating over all children of the container. The `*OnExit` is called after the iteration.
Further, in order to get the elements of a container, you must implement the methods:
```cpp
virtual MapElements getDictElements(Input&) = 0;
virtual ListElements getListElements(Input&) = 0;
```
Again, Input can be any aron object (e.g. Variant or nlohmann::json).
As for normal visitors, the Aron library offers convenience implementations for Variants and nlohmann::json inputs.
To use the RecursiveVisitor, you have to use the function
```cpp
void visitRecursive(RecursiveVisitorImplementation& v, typename RecursiveVisitorImplementation::Input& o);
```
### Example
Assume you want to count how many objects of each kind you have in a Variant.
```cpp
#include <RobotAPI/libraries/aron/core/data/visitor/variant/VariantVisitor.h>
class CountingRecursiveVisitor : public RecursiveConstVariantVisitor
{
public:
int dicts = 0;
int lists = 0;
int ndarrays = 0;
int ints = 0;
int floats = 0;
int longs = 0;
int doubles = 0;
int strings = 0;
int bools = 0;
public:
void visitAronVariantOnEnter(const data::DictPtr&) override { dicts++; }
void visitAronVariantOnEnter(const data::ListPtr&) override { lists++; }
void visitAronVariant(const data::NDArrayPtr&) override { ndarrays++; }
void visitAronVariant(const data::IntPtr&) override { ints++; }
void visitAronVariant(const data::LongPtr&) override { longs++; }
void visitAronVariant(const data::FloatPtr&) override { floats++; }
void visitAronVariant(const data::DoublePtr&) override { doubles++; }
void visitAronVariant(const data::BoolPtr&) override { strings++; }
void visitAronVariant(const data::StringPtr&) override { bools++; }
};
void countHowMany(const aron::data::VariantPtr& aron)
{
CountingRecursiveVisitor visitor;
aron::data::visitRecursive(visitor, aron);
std::cout << "The aron has " << visitor.dicts << " dicts." << std::endl;
}
```
## Typed Visitors
# Lessons Learned
\ No newline at end of file
...@@ -85,7 +85,7 @@ With the corresponding configuration in ./config/Armar3Config.cfg: ...@@ -85,7 +85,7 @@ With the corresponding configuration in ./config/Armar3Config.cfg:
\section RobotAPI-HowTos-RobotViewer How to inspect the robot's structure \section RobotAPI-HowTos-RobotViewer How to inspect the robot's structure
Robots are usually defined in the Simox XML (https://gitlab.com/Simox/simox/wikis/FileFormat) or in the URDF format. To inspect the kinematic structure, visualizations and physical properties, you can use the <i>RobotViewer</i> tool which is part of the Simox library. In particlular you can visualize all coordinate frames that are present in the robot defintion. Robots are usually defined in the Simox XML (https://git.h2t.iar.kit.edu/sw/simox/simox/-/wikis/FileFormat) or in the URDF format. To inspect the kinematic structure, visualizations and physical properties, you can use the <i>RobotViewer</i> tool which is part of the Simox library. In particlular you can visualize all coordinate frames that are present in the robot defintion.
Start it with the following command: Start it with the following command:
\code \code
RobotViewer --robot path/to/robot.xml RobotViewer --robot path/to/robot.xml
...@@ -96,7 +96,7 @@ Start it with the following command: ...@@ -96,7 +96,7 @@ Start it with the following command:
\section RobotAPI-HowTos-RemoteRobot-Access How to access a RobotStateComponent \section RobotAPI-HowTos-RemoteRobot-Access How to access a RobotStateComponent
The RobotStateComponent provides several methods for accessing the current configuration of the robot and for getting a snapshot of the current state which is compatible with The RobotStateComponent provides several methods for accessing the current configuration of the robot and for getting a snapshot of the current state which is compatible with
models of the Simox/VirtualRobot framework. With these models the whole functionality of Simox (https://gitlab.com/Simox/simox) can be used, e.g. IK solving, collision detection or motion and grasp planning. models of the Simox/VirtualRobot framework. With these models the whole functionality of Simox (https://git.h2t.iar.kit.edu/sw/simox/simox) can be used, e.g. IK solving, collision detection or motion and grasp planning.
See also \ref RobotAPI-RemoteRobot-Overview. See also \ref RobotAPI-RemoteRobot-Overview.
\par Creating a synchronized model (RemoteRobot) \par Creating a synchronized model (RemoteRobot)
......
...@@ -8,6 +8,6 @@ Tutorials related to RobotAPI: ...@@ -8,6 +8,6 @@ Tutorials related to RobotAPI:
\li \ref Component-ArVizExample (Example component for how to use ArViz) \li \ref Component-ArVizExample (Example component for how to use ArViz)
\li <a href="https://gitlab.com/ArmarX/meta/Academy/-/tree/master/tutorials/100_beginner/301_memory_server_and_client_tutorial_cpp">Memory Server and Client Tutorial</a> \li <a href="https://git.h2t.iar.kit.edu/sw/armarx/meta/academy/-/tree/master/tutorials/100_beginner/301_memory_server_and_client_tutorial_cpp">Memory Server and Client Tutorial</a>
*/ */
...@@ -23,7 +23,8 @@ Use this variable if you specify global poses and an empty Agent-string. Empty f ...@@ -23,7 +23,8 @@ Use this variable if you specify global poses and an empty Agent-string. Empty f
\section FramedPose-FramedPositionCreation Creation of new FramedPositions \section FramedPose-FramedPositionCreation Creation of new FramedPositions
To create a new FramedPosition (FramedOrientation, FramedVector and FramedPose work analogously) one needs To create a new FramedPosition (FramedOrientation, FramedVector and FramedPose work analogously) one needs
to know the position, the coordinate frame name and the agent name. to know the position, the coordinate frame name and the agent name.
The coordinate frame is usually the name of the RobotNode, e.g. the tcp of the robot. All nodes of a robot can be inspected with the <a href="https://gitlab.com/Simox/simox/wikis/Examples">Simox tool *RobotViewer*</a>. The coordinate frame is usually the name of the RobotNode, e.g. the tcp of the robot.
All nodes of a robot can be inspected with the <a href="https://git.h2t.iar.kit.edu/sw/simox/simox/-/wikis/Examples">Simox tool *RobotViewer*</a>.
The agent name can be retrieved via the \ref armarx::RobotStateComponent like this: The agent name can be retrieved via the \ref armarx::RobotStateComponent like this:
\code \code
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment