Showing posts with label Mac. Show all posts
Showing posts with label Mac. Show all posts

Monday, August 10, 2020

Back to robot coding part 1: hello world

One of the many things I promised myself when I retired nearly two years ago was to get back to some coding. Why? Two reasons: one is that writing and debugging code is hugely satisfying - for those like me not smart enough to do pure maths or theoretical physics - it's the closest you can get to working with pure mind stuff. But the second is that I want to prototype a number of ideas in cognitive robots which tie together work in artificial theory of mind and the ethical black box, with old ideas on how robots telling each other stories and new ideas on how social robots might be able to explain themselves in response to questions like "Robot: what would you do if I forget to take my medicine?"

But before starting to work on the robot (a NAO) I first needed to learn Python, so completed most of the Codecadamy's excellent 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

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-2.1.4.13-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", "164.168.0.17", 9559)
tts.say("Hello, world!")

whereupon my NAO robot spoke the words "Hello world". Success!

Monday, July 13, 2009

Installing Player/Stage on OS X with MacPorts

Back in 2006 I wrote about installing the excellent Player/Stage robot simulator under Linux, and the problems caused by dependencies (i.e. other packages that need to be installed first, before you can then install Player/Stage). Wouldn't it be great, I wrote, if there were a universal installer programme that would sort out all of these dependencies.

I should explain that since that post I've switched from Linux to OS X, running on a MacBook Pro, and have only just got round to installing Player/Stage. I was very pleased to discover that my plea for a universal installer has been answered by the (almost) excellent MacPorts.

I say almost excellent because installation wasn't completely glitch free.

Here's what I had to do to install to Mac OS X 10.5.7 (Leopard)

1. Download and install XCode (MacPorts depends on it)

2. Download and install MacPorts, install details here

3. In a terminal window run MacPorts with
$ sudo port install playerstage-stage playerstage-player

And wait an hour or so - it takes awhile. However, compilation of playerstage-player fails library not found for -ljpeg. To fix this as detailed here:

4. sudo port install python_select && sudo python_select python25

then re-run step 3.

5. But before you can run Player/Stage there's another fix needed, as detailed here.

sudo ln -s /usr/X11/share/X11/rgb.txt /usr/X11R6/lib/X11/rgb.txt

And that's it. Player/Stage installed.

Friday, October 26, 2007

A Mac with new spots: installing Leopard

A day off sick with a head cold and painful sinuses had one consolation. I had a little time this afternoon to install Leopard - the new version of Mac OS X (which interestingly arrived this morning before it had been officially launched at 6.00pm this evening).

How did the installation go? Well I'm happy to report that it was remarkable for being unremarkable. Just two minor comments: firstly, there was a very long pause (5 minutes perhaps) at the start of the install process proper, when the time remaining said 'calculating' and there was no apparent hard disk or DVD activity - I was beginning to have doubts about whether all was ok before the process sprang into life again (note to Apple: any kind of long and worrying pause like this really should still have some sort of progress indicator no matter how simple). Secondly, the time remaining calculation appeared to have difficulty making its mind up. Initially it said something over three and a half hours and then revised its estimate downwards over the next 30 minutes or so. In the end it took about an hour and a half from start to finish, and that included a long time for install disk verification.

First impression? Well it's fine. It's an operating system which means - in my view - should not be the main event but just get on and do its thing in the background while letting me get on with my work. It looks very nice of course, but so did Tiger. Cosmetically not such a big difference, especially for me since I place the dock on the left rather than at the bottom. (Ergonomically it makes more sense there because a left mouse movement to reach the dock is far easier than a down hand movement.)

The main new feature that I am immediately and gratefully using is called 'spaces'. It is basically the same thing that Linux window managers have had for years - which I have missed since switching (back) to Mac - that means I can open applications across four virtual screens and then quickly switch between them. This is great for me because when writing I like to have Firefox open for web searches, OpenOffice for drawing diagrams, Preview to read pdf papers, BibDesk and TeXShop for the actual writing. A single screen gets pretty crowded. (Of course what I'd really like is a bank of LCD displays so I can see everything at once but - for now - spaces will have to do.)

What else? Well the ability to instantly search and then - again with almost no delay - view the search results with 'cover flow' and the use 'quick look' to review what you find in more detail is terrific. The way that quick look opens everything from powerpoint presentations to movies and allows you to skip through the files with the left and right arrow keys but also scroll up and down individual files is just great. For the first time in 33 years of using computers I really think I don't need to remember filenames anymore. Given that this is still a good old fashioned traditional Unix file system underneath, Leopard is probably as close as you can get to feeling like an associative 'contents addressable' file system.

----------------------------------------------------------
*Footnote: I returned to Mac earlier this year after a 20 year separation. The first computers at APD (that we didn't design and build ourselves) were 128K Macs in 1985. Lovely machines with a proper windows OS (while the PC was still running DOS) that were used from everything from word processing and accounts to technical drawing.