Running Python on your NXT

Discussion specific to projects ideas and support.
janosch_graef
Posts: 3
Joined: 13 Dec 2011, 23:55

Running Python on your NXT

Post by janosch_graef »

Hi,

I started to write a new firmware which runs python. Actually it should only run compiled python programs (the ones from CPython) due to memory restrictions. I'll use PyMite, a python VM for embedded systems, which already has nice support for AT91SAM7S256. For the base OS and hardware drivers I'll use NxOS since it has very clean code and it's easy to create new kernels with it.
I'll also try to keep the USB/Bluetooth interface compatible with the one of the LEGO firmware and I'll use the same file formats for image, sound, melody files, etc.
Nevertheless I don't really know how fast this will run and how big programs could be. So this will be rather experimental. But I'm very optimistic and for as a python fan I just can't wait to run some python code on my NXT :)

Preliminary project name is "PythoNXT" short for Python on NXT. At the moment I haven't done very much, except setting up a development environment and writing a simple test program combining PyMite and NxOS. Now I first have to wait for LEGO to replace my NXT, since my display is broken.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: Running Python on your NXT

Post by mightor »

Very cool, I look forward to seeing what you'll do with this project!

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Running Python on your NXT

Post by HaWe »

can you pls explain with a few words which advantages (and disadvantages) Python has got compared to NXC or Java?
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: Running Python on your NXT

Post by linusa »

janosch_graef wrote:But I'm very optimistic and for as a python fan I just can't wait to run some python code on my NXT :)
Yeah, great attitude. Really liking this idea! :thumbsup:. Make sure to keep us posted!
doc-helmut wrote:can you pls explain with a few words which advantages (and disadvantages) Python has got compared to NXC or Java?
Biggest difference: Python is a weakly typed language (opposed to Java, C, NXC). Variables and function parameters don't get type information from the code, so simple example: You can pass a string or an integer. While you lose the compiler as safety net (no type checks), you gain flexibility.
This results in a flexible thing called "duck typing". If something acts like a duck, let's assume it's a duck. So if a method expects an object and calls its ".quack()" function, you can pass anything that has a .quack() function. You can even bind a quack-function dynamically to an object.

Another big pro is the "batteries included" principle: Huge standard library, well documented, always available (comparable to .net or Java).

Biggest disadvantage: Performance. It's slow. In Python you tend to write nice & compact code, but it's difficult to get a feeling for performance or "to write fast code" (but that's just my 2 cents).
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
janosch_graef
Posts: 3
Joined: 13 Dec 2011, 23:55

Re: Running Python on your NXT

Post by janosch_graef »

linusa wrote: Yeah, great attitude. Really liking this idea! :thumbsup:. Make sure to keep us posted!
Development is delayed at the moment until I've got a new NXT (display broken). At the latest I'll start coding in February when semester break begins. Eventually, I can borrow another NXT from a friend until I got a new one, then of course I could start coding ealier.
linusa wrote: Another big pro is the "batteries included" principle: Huge standard library, well documented, always available (comparable to .net or Java).
Of course I won't port all modules of CPython to the NXT. I'll port some standard modules: io, os, sys and of course I'll write a module for controlling the NXT (nxt.motor, .sensor, .usb, ...). And later I'll possibly write some modules like navigation, behaviour, AI, etc.

If anyone wants to contribute to the project, I'll setup a GIT repository or even a Gobby server.
tcwan
Posts: 186
Joined: 30 Sep 2010, 07:39

Re: Running Python on your NXT

Post by tcwan »

janosch_graef wrote:Hi,

Preliminary project name is "PythoNXT" short for Python on NXT. At the moment I haven't done very much, except setting up a development environment and writing a simple test program combining PyMite and NxOS. Now I first have to wait for LEGO to replace my NXT, since my display is broken.
Hi,

I'm using NxOS as the base for writing Assembly Language code on the NXT. Currently it is hosted on GitHUB as https://github.com/tcwan/nxos-armdebug.
I've developed a firmware-based ARM instruction Debugger for the NXT, which is present in the nxos-armdebug project. If you host your code on GitHUB, I'd be interested in tracking your progress, and it'd make code exchange easier. I've merged in most of the NxOS variants hosted on Github into my code base.

With nxos-armdebug, you can use the USB connection (via the Fantom Drivers + nxt-python 2.2+ http://code.google.com/p/nxt-python/) for debugging with GDB.
if you're interested in finding out more please contact me.

Unfortunately I don't think I can contribute actively to your project right now, Python is cool but I'm still trying to flesh out the ARM assembly stuff for teaching my university level course on ARM assembly language programming.

(There's not been any update to the repository for the past 3 months due to teaching commitments, I hope to resume after the start of the new year).
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: Running Python on your NXT

Post by schodet »

Great project, I also thinks that NxOS is a good base for new firmwares.

I look forward to see the first steps!
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
jmarotta
Posts: 1
Joined: 27 Jan 2012, 22:07

Re: Running Python on your NXT

Post by jmarotta »

Howdy!
I look forward to seeing the results of this - I've become a recent Python convert.

I should note - I'm having some trouble finding Bluetooth drivers for Python on my 64 bit Windows 7 desktop. You may find yourself writing a driver :).

Joe
metadot
Posts: 2
Joined: 05 Feb 2012, 15:16

Re: Running Python on your NXT

Post by metadot »

I'm sorry to say, but you are about to try something impossible. The NXT doesn't have enough RAM to run a Python interpreter.

I used to work for several years on a Python interpreter port to a mobile device. We tried hard to squeeze it as small as possible, but even then it was hundreds of kilobytes at a minimum. The NXT has 64 kB.
metadot
Posts: 2
Joined: 05 Feb 2012, 15:16

Re: Running Python on your NXT

Post by metadot »

After checking out the PyMite link, I sit corrected. Interesting!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests