Aldebaran documentation What's new in NAOqi 2.4.3?

ALMemory - Tutorial

NAOqi Core - Overview | API | Tutorial


Introduction

This tutorial explains how to use the ALMemory module.

Inserting Data

from naoqi import ALProxy

try:
  # create proxy on ALMemory
  memProxy = ALProxy("ALMemory","localhost",9559)

  #insertData. Value can be int, float, list, string
  memProxy.insertData("myValueName1", "myValue1")

  #getData
  print "The value of myValueName1 is", memProxy.getData("myValueName1")

except RuntimeError,e:
  # catch exception
  print "error insert data", e

Getting Data

from naoqi import ALProxy

# create proxy on ALMemory
memProxy = ALProxy("ALMemory","localhost",9559)

#get data. Val can be int, float, list, string
val = memProxy.getData("myValueName1")

Raising an event

from naoqi import ALProxy

# create proxy on ALMemory
memProxy = ALProxy("ALMemory","localhost",9559)

#raise event. Data can be int, float, list, string
memProxy.raiseEvent("My event", "data")

Subscribing to an event

Using qi

To take advantage of qi, see the following tutorials, subscribing to a memory event is explained there:

Using NAOqi

"""
with sample of python documentation
"""

from naoqi import *
import time
check = 0


# create python module
class myModule(ALModule):
  """python class myModule test auto documentation: comment needed to create a new python module"""


  def pythondatachanged(self, strVarName, value):
    """callback when data change"""
    print "datachanged", strVarName, " ", value, " ", strMessage
    global check
    check = 1

  def _pythonPrivateMethod(self, param1, param2, param3):
    global check


broker = ALBroker("pythonBroker","10.0.252.184",9999,"naoverdose.local",9559)


# call method
try:

  pythonModule = myModule("pythonModule")
  prox = ALProxy("ALMemory")
  #prox.insertData("val",1) # forbidden, data is optimized and doesn't manage callback
  prox.subscribeToEvent("FaceDetected","pythonModule", "pythondatachanged") #  event is case sensitive !

except Exception,e:
  print "error"
  print e
  exit(1)

while (1):
  time.sleep(2)