NAOqi Core - Overview | API
ALPreferenceManager allows managing the robot preferences.
Robot preferences are used to store, among other, all the settings for the applications running on the robot.
Robot preferences are stored both locally in a database, and in the Aldebaran Cloud; ALPreferenceManager ensures the consistency between the different copies.
Note
Your robot must be associated to your Aldebaran Robotics user account in order for preferences to be synchronized and saved in the. See Aldebaran Robotics Web Services. Otherwise preferences will only be stored locally, and won’t be available from Cloud.
A preference is defined by its:
For instance, if you are developing a chess application, you could have the following preferences:
On the robot the preferences are stored in an SQLite database under path `` /home/nao/.local/share/PreferenceManager/prefs.db``. You are advised not to modify this file directly since it must be consistent with the copy of the preferences stored in the Cloud.
import sys
import time
from naoqi *
NAO_IP = "nao.local"
Dummy = None
memory = None
# Create a dummy module, just to subscribe to events emitted by PreferenceManager
class DummyModule(ALModule):
""" Dummy module """
def __init__(self, name):
ALModule.__init__(self, name)
global memory
memory = ALProxy("ALMemory")
memory.subscribeToMicroEvent("preferenceAdded", "Dummy", "", "onPreferenceAdded")
memory.subscribeToMicroEvent("preferenceChanged", "Dummy", "", "onPreferenceChanged")
memory.subscribeToMicroEvent("preferenceRemoved", "Dummy", "", "onPreferenceRemoved")
memory.subscribeToMicroEvent("preferenceDomainRemoved", "Dummy", "", "onPreferenceDomainRemoved")
def onPreferenceAdded(self, event, value, message):
print "Preference added: " + str(value)
def onPreferenceChanged(self, event, value, message):
print "Preference changed: " + str(value)
def onPreferenceRemoved(self, event, value, message):
print "Preference removed: " + str(value)
def onPreferenceDomainRemoved(self, event, value, message):
print "Preference domain removed: " + str(value)
def main():
myBroker = ALBroker("myBroker", "0.0.0.0", 0, NAO_IP, 9559)
global Dummy
Dummy = DummyModule("Dummy")
# Play with preference manager
pm = ALProxy("ALPreferenceManager")
pm.setValue("com.apps.chess", "level", "hard")
pm.setValue("com.apps.chess", "treedepth", "10")
pm.setValue("foo.bar", "foo", "bar")
pm.setValue("com.apps.chess", "level", "easy")
print "com.apps.chess - level: " + pm.getValue("com.apps.chess", "level")
pm.removeValue("foo.bar", "foo")
pm.removeDomainValues("com.apps.chess")
print "com.apps.chess - level: " + str(pm.getValue("com.apps.chess", "level"))
time.sleep(1)
myBroker.shutdown()
sys.exit(0)
if __name__ == "__main__":
main()