Python & LEGO Mindstorm control...
t-meyer at ihug.co.nz
Wed Mar 30 02:13:00 CEST 2005
> I have a question re the use of Python to control a robot
> built with the LEGO Mindstorm system.
> This is to help my 11yr old with his increased interest in
> 'programming' and 'robotics'... If not feasible, he wants to
> use the graphical-tool that comes with it...
> Would you suggest:
> 1. Using LegOS (http://legos.sourceforge.net/) and writing/using py
> extensions from a Linux-box, OR
BTW, this should be BrickOS (http://brickos.sourceforge.net/).
> 2. Using LeJOS (http://lejos.sourceforge.net/) and writing
> Jython utils.
> Wanted to incorporate Python somehow, as it may be quite
> appropriate for his age. Will have to help quite a bit in either
> case, tho... but was wondering which is a more treaded path...
I've used the graphical environment that comes with Mindstorms in
conjunction with CPython. Basically I have a Python extension that can send
IR signals (well, a 0-255 number) to the RCX. In the graphical environment
I can design a program to respond to the IR signals (pretty simple stuff),
and in a Python script I can put more complex behaviour that interacts with
other things and sends out the appropriate IR controls.
(Essentially, the graphical environment is used for strict RCX control -
turning motors on/off, reading sensors, etc, and the Python environment is
used for everything else).
I found this a good way to do things (although part of that is the nature of
the larger project), and suspect it may be in other cases, too. It does
mean you can avoid C/C++ (apart from creating the extension in the first
place) and Java, and don't need to replace the firmware, as with LeJOS.
The extension is a fairly simple adaptation of some NQC code (NQC is
licensed under the MPL). I can wrap it up and give it to you if you'd like,
or just describe what I did. If you wanted to do a lot more work, you could
wrap a great deal more of the NQC code and have a CPython extension that can
really control the RCX without using the graphical environment or
BrickOS/LeJOS. I think starting off with the graphical environment is
generally good, though.
More information about the Python-list