06/10/2012

IPython on Android ~ Rise of the Robots

When we think of robots, we think of humanoids, or bots on wheels, or manipulators ~ stuff that moves ~ but all Android devices are little robots, they just don't normally move around by themselves. They come with a wide range of sensors for gathering information about their environment, decent processors and RAM to handle those sensors, and access to the Internet.

If you look into things a little, it becomes pretty obvious that Android development has always had an eye on robotics, and there's a number of projects that have already used Android devices as a robotics platform.

I've personally been playing with Lego's NXT robotics kit. By installing SL4A and nxt-python on my Android device, I can write Python scripts that run on the Android and control the NXT over Bluetooth. These scripts can easily access the Android and NXT APIs. With the Android mounted to the NXT robot, you have a very nice platform for exploring robotics with Android, NXT and Python.

There's a number of other similar projects out there, notably CellbotsThere's also a number of projects that attach an Android to stuff like weather balloons and rockets and so on.

What's missing from this picture is the IPython Notebook. With IPython Notebook on Android, you could simply install an apk from Google Play, open the app, provide a password to protect your server, then fire up an IPython Notebook server that can be made available to any browser on the same local network, or made public.

Being able to run IPython Notebook on Android and interface with it through any modern browser, gives you the powerful features of the Notebook, running on the Android device itself. This removes the need to be holding the Android device while it's working, which is important if its attached to a rocket, but it also provides Android with a serious, fully capable, Python IDE.

One guy appears to have already got IPython Notebook running on Android, with the apk-python project, but only on one particular tablet that has access to packages that most devices wont have. Still, it's a promising start, and PY4A have already packaged a bunch of C based Python libraries for easy installation on Android, including Twisted.

IPython Notebook is ideal for managing and programming Androids, and Android is a great platform for exploring robotics.

I hope IPython on Android is just a matter of time.

02/10/2012

Python Powered Android Robots on NXT

There's a wide range of options for hacking NXT robots. One in particular, nxt-python, is the most popular with Python fans.

nxt-python is good, but it runs on a regular machine and controls the NXT over Bluetooth, which means the robot is never more than ten meters from its life-support PC.

There's another project, Cellbots, which allows you to control an NXT robot from an Android device, but not program it in Python, though I think they have something like this in the pipeline.

I wanted this ability today.


I mostly wanted to mount my phone to my NXT robot and program the whole contraption, in Python, with the program running on the Android device itself. This way, the phone would run the program, which would have local access to the Android API, and be able to simultaneously control the NXT parts using the phone's Bluetooth hardware.


It worked. My phone is now a self-contained robot.


This phone has tracks to roam around on, a colour/light sensor to scan the ground with, touch sensors to know when it's collided with stuff and an ultrasonic range finder. With the phone's internal organs, including sensors for tilt and acceleration, geo-location and compass, as well as web access, telephony and two cameras, it's a pretty cool little robot.


If anyone's interested in doing something similar, it's twenty minutes work.



Set Up


You first grab SL4A, Scripting Layer 4 Android, from their site.


http://code.google.com/p/android-scripting/

Once that's installed, grab the Python interpretor from within SL4A. This will give you another 'app' called Python For Android, PY4A, on your phone. You normally run Python scripts through SL4A, but you will need to open PY4A separately for certain things.


Now download nxt-python onto your phone from their Google Code page, making sure to grab the zipped version.


http://code.google.com/p/nxt-python/downloads/list

Once you have the zip file on your Android, extract it into any directory, the downloads directory the zip file is in already is as good a place as any as you'll be able to remove all this fur soon anyway. There's free apps that handle zip files in the Play store.


Now you have it extracted, you need to move the nxt directory that is within the main nxt directory to your Python extensions directory. That is to say, if you open the directory, called nxt, that you just extracted, within it is another directory called nxt. Its path should look something like


/sdcard/download/nxt/nxt

You need to move this directory, putting it inside


/sdcard/com.googlecode.pythonforandroid/extras/python

That's nxt-python sorted. You also need the PyBluez module, compiled for ARM, for nxt-python's Bluetooth code to work. Fortunately, you can just grab a copy from the PY4A website.


http://code.google.com/p/python-for-android/downloads/detail?name=PyBluez-0.19-py2.6-linux-armv.egg

Once you have the PyBluez module on your phone, open the Python for Android app from your apps list and hit Import Modules. Select the PyBluez module and it'll be installed for you.


All done. Open SL4A, import nxt, and start hacking.


If you have any trouble, mail me, I'll be happy to help out.