Search code examples
c++roboticsnao-robot

Reading sensors in real time NAO robot


I'm working with a real time application with the robot NAO and i need to read the joints sensors fast, the function getData from ALMemory is too slow. I have seen the example with the modue almemoryfastaccess but i have an error when i run the .exe.

I have read about the almemoryfastaccess module but when i try to connect to the sensors with the function ConnectToVariables(getParentBroker(), fSensorKeys, false) i recieved the following error in the function getDataPtr: "uncaught error pointer serialization not implemented". Does anyone have work with this?. Thanks.

I can't you getData from ALMemory because is too slow for my application.

The code is something like this. It compiles well but when I run the .exe the error appears:

enter image description here

#include <almemoryfastaccess/almemoryfastaccess.h>
#include <boost/shared_ptr.hpp>
#include <string>
#include <vector>
#include <alcommon/albroker.h>
#include <qi/log.hpp>

using namespace AL;
using namespace std;

boost::shared_ptr<AL::ALMemoryFastAccess> fMemoryFastAccess;
vector<string> fSensorKeys;
fSensorKeys.clear();
fSensorKeys.resize(3);
fSensorKeys[0] = "Device/SubDeviceList/HeadPitch/Position/Sensor/Value";
fSensorKeys[1] = "Device/SubDeviceList/HeadYaw/Position/Sensor/Value";
fSensorKeys[2] = "Device/SubDeviceList/LAnklePitch/Position/Sensor/Value";
fMemoryFastAccess->ConnectToVariables(getParentBroker(), fSensorKeys, false); //in this line the error appears.

Solution

  • This "fast access" API only works when your module runs in the same process as NAOqi.

    When running your code from a remote client (your Windows PC here), it is not possible to achieve real-time data collection.

    There are alternatives:

    • cross-compile your module and have it loaded by NAOqi. You'll create a library instead of an executable (see the use of qi_create_lib here). Sadly I do not know how to find the cross-toolchain. You might need to contact the support.
    • you can poll the data less frequently (say every 100ms) by using ALMemory::getListData
    • you can poke for the module called ALMemoryWatcher by running qicli info --show-doc ALMemoryWatcher on the robot. It captures real-time data, but you are meant to collect the data by batches at a lower frequency.