[pypy-dev] Python on the Lego NXT

Stargaming stargaming at gmail.com
Sat Feb 9 21:04:03 CET 2008

Hi PyPyers,

Lego has been developing robotics for quite a while now. Their latest
robot is the "Lego Mindstorms NXT." Unfortunately, its programming
capabilities are quite restricted_ -- with the standard firmware_ (open
source, BTW), state of the art programming is done in a C-like
language, NXC_, translated to an assembly-esque language, NBC_.

Now I want to use Python rather than NXC, but it currently only works
via a socket_ (which requires USB or Bluetooth) and live bytecode
instructions. I figured this could be possible with PyPy.

Previous advice I got from #pypy pointed out that this is indeed an
application where PyPy could be used but the Python interpreter *might*
be too heavy for this little machine. I have asked_ an unofficial Lego
Robotics mailing list as well (no reply yet).

There are several layers one could translate Python code (or rather
flow graphs?) to: Either NXC, a language pretty close to C. Chances are
high that translation to this layer might be trivial (tokenize Python
and generate NXC instructions), no PyPy involved at all. The next layer
is NBC, assembly code for the standard compiler. This can be compiled
to NXT bytecode_, which is rather close to real PC opcodes (not Python
bytecode, unfortunately). See my posting to the Lego Robotics mailing
list for detailed descriptions of these proposals.

As already stated in the Lego ML, translating the whole Python
interpreter might be too heavy for the NXT_ brick's storage (see below,
one quarter MB). Translating every program itself (and thus, writing
them in RPython), might be too expensive (considering translation
time). Writing a firmware just seems crazy.

My question: Do you think this would be a Good Thing to do with PyPy?
While I wrote these two postings, the idea of just tokenizing Python
and generating NXC began looking better with every second. Is there any
obvious solution I'm missing?

Sorry-for-the-slight-OT-ly yours,

Hardware_ details: Processors

  * Atmel 32-bit ARM processor
    * 256 KB Flash
    * 64 KB RAM
    * 48 MHz
    * (handles USB/Bluetooth, display/sound)
  * Atmel 8-bit AVR co-processor
    * 4 KB Flash
    * 512 Byte RAM
    * 8 MHz
    * (handles raw I/O)

Quick glossary:

      Not eXactly C, C-like programming language for the NXT
      Next Byte Code, Assembler-like language for the NXT
      The robot itself :-)

.. _restricted: http://www.teamhassenplug.org/NXT/NXTSoftware.html
.. _firmware: http://mindstorms.lego.com/Overview/OpenSource.aspx
.. _NXC: http://bricxcc.sourceforge.net/nbc/nxcdoc/index.html
.. _NBC: http://bricxcc.sourceforge.net/nbc/
.. _socket: http://home.comcast.net/~dplau/nxt_python/index.html
.. _asked:
.. _bytecode:
.. _NXT: http://mindstorms.lego.com/Overview/NXTreme.aspx 
.. _Hardware:

.. All mentioned brands belong to their respective owners. ;)

More information about the Pypy-dev mailing list