Search code examples
python-2.7nao-robotchoregraphe

Repeated Access to Data in ALMemory on NAO Robot - Data not found


I am using a nao robot with Choregraphe 2.1.4 on windows 10.

In my flow diagram there are several boxes which are using the same data. When I'm using the data for the first time it will be afterwards inserted to the memory with: self.memory = ALProxy("ALMemory") ... self.memory.insertData("dataKey", self.value)

At two positions I need access to the data, so I'm using: self.memory = ALProxy("ALMemory") ... self.value = self.memory.getData("dataKey")

When I run this program (the program doesn't even start), I immediatly get the following error:

[ERROR] behavior.box :_safeCallOfUserMethod:281 _Behavior__lastUploadedChoregrapheBehaviorbehavior_1172060400__root__unknownProgramName_6__redMarkedBox_2: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/naoqi.py", line 271, in _safeCallOfUserMethod
func()
File "<string>", line 12, in onLoad
File "/usr/lib/python2.7/site-packages/naoqi.py", line 301, in __call__
return self.__wrapped__.method_missing(self.__method__, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/naoqi.py", line 371, in method_missing
raise e
RuntimeError:   ALMemory::getData
    ALMemory::getData
Data not found dataKey

In my flow diagram is the second box marked in red.

My question is: how can i get the data a second time from the memory?

I also tried to insert the data a second time to the memory, but it nothing changed. Recently I added outputs and inputs to the impacted boxes to send the needed data to the boxes. But my program is getting confusingly and messy.


Solution

  • Several possibilities:

    • Use ALMemory.declareEvent somewhere at the beginning of your behavior, before the rest (or insert a good default value, which can be good to make sure you always start from a clean slate)
    • Wrap your uses of ALMemory.getData with try/except RuntimeError statements so you can handle the case where the data has not been inserted yet

    You should also pay attention to where in your boxes you do those calls; a boxes' .onLoad() is called when the diagram is loaded, before any input is triggered, so if your code trying to read ALMemory is in there, but the place writing it is in .onStart(), it's no surprise you get this error.