ALMemory - Tutorial

NAOqi Core - Overview | API | Tutorial


Introduction

This tutorial explains how to use the ALMemory module.

Note

The tutorial is written in Python.

InsertData

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

getData

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")

Raise 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")

Subscribe to event

"""
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) # forbiden, 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)