NAOqi Sensors - Overview | API | Tutorial
This Python example shows how to retrieve the values in ALMemory. It gives the values of the total weight on both feet until foot contact is lost.
# -*- encoding: UTF-8 -*-
from naoqi import ALProxy
import time
IP = "127.0.0.1" # set your Ip address here
PORT = 9559
# ====================
# Create proxy to ALMemory
memoryProxy = ALProxy("ALMemory", IP, PORT)
footContact = True
footContact = memoryProxy.getData("footContact")
while (footContact):
footContact = memoryProxy.getData("footContact")
leftFoot = memoryProxy.getData("leftFootTotalWeight")
rightFoot = memoryProxy.getData("rightFootTotalWeight")
print ("Total weight on left foot: %.2f kg, on right foot: %.2f kg" % (leftFoot, rightFoot))
time.sleep(1.0)
print("Foot contact lost")
Another possible application is to implement a module with a callback on the event “footContactChanged” (see Event subscription for information on how to do so).
It is also possible to access sensors values directly, such as in the following example: sensors_getFsrValues.py.
# -*- encoding: UTF-8 -*-
from naoqi import ALProxy
IP = "127.0.0.1" # set your Ip address here
PORT = 9559
# ====================
# Create proxy to ALMemory
memoryProxy = ALProxy("ALMemory", IP, PORT)
# Get The Left Foot Force Sensor Values
LFsrFL = memoryProxy.getData("Device/SubDeviceList/LFoot/FSR/FrontLeft/Sensor/Value")
LFsrFR = memoryProxy.getData("Device/SubDeviceList/LFoot/FSR/FrontRight/Sensor/Value")
LFsrBL = memoryProxy.getData("Device/SubDeviceList/LFoot/FSR/RearLeft/Sensor/Value")
LFsrBR = memoryProxy.getData("Device/SubDeviceList/LFoot/FSR/RearRight/Sensor/Value")
print( "Left FSR [Kg] : %.2f %.2f %.2f %.2f" % (LFsrFL, LFsrFR, LFsrBL, LFsrBR) )
# Get The Right Foot Force Sensor Values
RFsrFL = memoryProxy.getData("Device/SubDeviceList/RFoot/FSR/FrontLeft/Sensor/Value")
RFsrFR = memoryProxy.getData("Device/SubDeviceList/RFoot/FSR/FrontRight/Sensor/Value")
RFsrBL = memoryProxy.getData("Device/SubDeviceList/RFoot/FSR/RearLeft/Sensor/Value")
RFsrBR = memoryProxy.getData("Device/SubDeviceList/RFoot/FSR/RearRight/Sensor/Value")
print( "Right FSR [Kg] : %.2f %.2f %.2f %.2f" % (RFsrFL, RFsrFR, RFsrBL, RFsrBR) )