Thursday, June 30, 2011

Transfer files to/from NAO from your program

# This all assumes the default setting of username=nao with robot name =nao.
# Reminder to me -- I need to mkdir the recording folder on nao.

I often want to transfer files to and from my NAO from within my program. To do this without it asking for a password, I have to use public keys.


Example usage:
In Python, I can use the os.system() function to run linux commands.

import os
cmd = 'scp nao@nao.local:/home/nao/recording.wav .'
os.system(cmd)

This would copy the recording I made (for example, using the ALAudioDevice API) to the current directory on my Mac (for example).


How to scp from your computer to NAO without a password:  

1. If you don't already have a public key, generate one:
  • In the home directory of your computer, run ssh-keygen
  • Press enter to name it using the default id_rsa.pub
  • Enter some passphrase (at least 5 characters)

2. Copy the public version of the key to your NAO: 
scp ~/.ssh/id_rsa.pub nao@nao.local:~

3. Log into NAO using ssh nao@nao.local

4. Add the public key to NAO's authorized keys list:
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys


Even cooler!

You can do

cmd = 'scp nao.local:/home/nao/recording.wav .'

without needing to specify the username every time (did you notice it was missing?). This is handy if you're already storing IP='nao.local'.

Adding a default username for nao.local host:

Add the following into ~/.ssh/config:
Host nao.local
        User nao

Note that before "User" you need to put a tab.

Friday, June 24, 2011

Proxy ridiculous!

Here's how to set up the proxies for git and svn.

git
export $http_proxy=proxy.com:8080
git config --global http.proxy $http_proxy

svn
> sudo vim ~/.subversion/servers
http-proxy-host = proxy.com
http-proxy-port = 8080

Thursday, June 23, 2011

Mach-o errors finally fixed

I've been having problems for ages trying to get NAO libraries to play nicely in Python on my Mac (Snow Leopard).

First of all, I'd have to run Python 2.6 by doing:
>> python2.6

And then I'd try to import the naoqi library, and get the error:

Python 2.6.6 (r266:84292, May 17 2011, 11:58:30)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import naoqi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/angelica/Nao/Library/naoqi-sdk-1.10.44-mac/lib/naoqi.py", line 35, in <module>
    import inaoqi
  File "/Users/angelica/Nao/Library/naoqi-sdk-1.10.44-mac/lib/inaoqi.py", line 7, in <module>
    import _inaoqi
ImportError: dlopen(/Users/angelica/Nao/Library/naoqi-sdk-1.10.44-mac/lib/_inaoqi.so, 2): no suitable image found.  Did find:
    /Users/angelica/Nao/Library/naoqi-sdk-1.10.44-mac/lib/_inaoqi.so: mach-o, but wrong architecture
    /Users/angelica/Nao/Library/naoqi-sdk-1.10.44-mac/lib/_inaoqi.so: mach-o, but wrong architecture


The main problem seemed to be making it all work with my MacPorts installation.

The PATH environment variable in my ~.profile had been modified by my MacPorts installation to look something like:

export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:$PATH

I deleted this line from my .profile and opened a new terminal. Now the PATH was not being overridden by my .profile setting, so when I did

>> which python
I got
>> /usr/bin/python

More importantly, I can import my Nao library again! <3

h22:~ angelica$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import naoqi
>>>