Learn Python 2 course over the last few weeks. I have to admit that I started learning Python with big misgivings over the language. I especially don't like the way Python plays fast and loose with variable types, allowing you to arbitrarily assign a thing (integer, float, string, etc) to a variable and then assign a different kind of thing to the same variable; very different to the strongly typed languages I have used since student days: Algol 60, Algol 68, Pascal and C. However, there are things I do like: the use of indentation as part of the syntax for instance, and lots of nice built in functions like range(), so x = range(0,10) puts a list ('array' in old money) of integers from 0 to 9 in x.
So, having got my head around Python I finally made a start with the robot on Thursday last week. I didn't get far and it was *very* frustrating.
Act 1: setting up on my Mac
Act 1: setting up on my Mac
Attempting to set things up on my elderly Mac air was a bad mistake which sent me spiralling down a rabbit hole of problems. The first thing you have to do is download and unzip the NAO API, called naoqi, from Aldebaran. The same web page then suggests you simply try to import naoqi from within Python, and if there are no errors all's well.
As soon as I got the export path commands right, import naoqi resulted in the following error
Reason: unsafe use of relative rpath libboost_python.dylib in /Users/alansair/Desktop/naoqi/pynaoqi-python2.7-184.108.40.206-mac64/_qi.so with restricted binary
According to stack overflow this problem is caused by Mac OSX system integrity protection (SIP).
Then (somewhat nervously) I tried turning SIP off, as instructed here.
But import naoqi still gives a different error. Perhaps its because my Python is in the wrong place, the Aldebaran page says it must be at /usr/local/bin/python (the default on the mac is /usr/bin. Ok so I So, reinstall python 2.7 from Python.org so that it is in /usr/local/bin/python. But now I get another error message:
>> import naoqi
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
A quick search and I read: "this error shows up when a module tries to use a python library that is different than the one the interpreter uses, that is, when you mix two different pythons. I would run otool -L <dyld> on each of the dynamic libraries in the list of Binary Images, and see which ones is linked to the system Python."
At which point I admitted defeat.
Act 2: setting up on my Linux machine
Once I had established that the Python on my Linux machine was also the required version 2.7, I then downloaded and unzipped the NAO API, this time for Linux.
This time I was able to import naoqi with no errors, and within just a few minutes ran my first NAO program: hello world.
from naoqi import ALProxy
tts = ALProxy("ALTextToSpeech", "220.127.116.11", 9559)
whereupon my NAO robot spoke the words "Hello world". Success!