NAOqi Core - Overview | API | Tutorial
ALMemory is a centralized memory used to store all key information related to the hardware configuration of your robot.
More specifically, ALMemory provides information about the current state of the Actuators and the Sensors. For further details, see: NAO - Actuator & Sensor list.
ALMemory can also be used to store and retrieve named values, and act as a hub for the distribution of event notifications.
ALMemory is a mutexed and unordered boost map. The map contains variant (ALValue).
Mutex are read/write mutex and for performance, can protect:
For example:
The notifications are managed by a threadpool (in local) or by a unique notification thread (in remote).
An Event is a MicroEvent which stores his history into ALMemory. They are basically the same, but MicroEvent is faster.
You can access to event history using ALMemoryProxy::getEventHistory().
Furthermore a Module can autostart when someone subscribe to an Event. This feature is accessible using ALMemoryProxy::declareEvent() with two parameters.
ALMemory is thread safe for normal operations. Reader and writer can access variable at the same moment except when you use ALMemoryProxy::getDataPtr().
ALMemory can store and retrieve variant (ALValue):
type | C++ | Python | Java |
---|---|---|---|
integer | int | Python integer | int |
boolean | bool | Python boolean | Boolean |
float | float | Python float | Float |
List | vector<ALValue> | [] | Java array [] |
String | std::string | Python string | String |
Binary | ALValue | String | byte[] |
Variant | ALValue | Use python type | jnaoqi Variant |
To access to a value stored in ALMemory, use:
The function ... | Providing ... |
---|---|
ALMemoryProxy::getDataPtr() | Fast pointer access. Warning: it’s not thread safe nor atomic. |
ALMemoryProxy::getData() | Thread safe access. It can be used either when your module is local or remote. |
To store values in the memory, use ALMemoryProxy::insertData().
To subscribe to events, use:
The function ... | To subscribe to ... |
---|---|
ALMemoryProxy::subscribeToEvent() | an event. |
ALMemoryProxy::subscribeToMicroEvent() | a microEvent. |
For further details, see the following example: Creating events.
To generate events, use the following functions:
The function ... | To ... |
---|---|
ALMemoryProxy::raiseMicroEvent() | insert a value and notify subscribers. |
ALMemoryProxy::raiseEvent() | insert a value, notify subscribers, store value history and timestamp (internal). |
ALMemoryProxy::declareEvent() | link a module to a variable. If a module subscribes to variable, the module starts his process once. For example, subscribe to FaceDetected automatically starts the module ALFaceDetection. If all subscribers unsubscribe, the module stops. |