Lego RCX/NXT robotic programming with Pi.

Drop in for a chat and a cup of tea

32 posts   Page 1 of 2   1, 2
by Fduquette » Sat Dec 31, 2011 8:25 pm
There are a few linux mash-ups for the Lego Mindstorms robot educational programming software inlcuding an interesting Java app, LeJOS (http://lejos.sourceforge.net/).

It would be interesting to use the raspberry to program the brick or lash it to a lego plate, connect it to the robot and run it off the robot's power supply. The older rcx kits are limited with inputs and old OS, but if the machine carried a Pi, anticipating eventual integration of wireless, then the Pi increases robot possibilities in robotic curriculum objectives, projects , competitions, etc. When the Pi's are released, Im going to give it a whirl.

One could make a cover or case for the Pi using 2 Lego baseplates (maybe 8x16) and some 1x(x) beams and bricks of varying lengths to provide spaces for the attachments, put some strips of adhesive foam on the interior sides of the baseplates to shock-proof it, and there you have it, recipe for a Lego Pi.
Posts: 3
Joined: Sat Dec 31, 2011 7:26 pm
by ghans » Sun Jan 01, 2012 10:38 am
Sounds very nice.
Note that lejos is dependant of Java , and OpenJDK , AFAIK , was very slow when tested. JamVM + Classpath should be ported . Furthermore , are you only using NXTs ? The old ones need a serial port ( yay soldering ) for programming .
NQC and NXC are also goog choices as lejos alternatives because the tools IMO could be easily crosscompiled now.

Greetings,
ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Posts: 4601
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany
by tonycollinet » Sun Jan 01, 2012 2:04 pm
Seems to me, if mindstorms is of interest, we should be looking at how to interface the modules (motors, sensors etc) directly to the Pi. Is there any documentation available regarding the electrical interfaces?

I guess the alternative might be direct control of the motors/sensors via the NXT brick over blutooth (EDIT: Or USB), but this seems a little un-necessary.

EDIT SOME MORE: and yes, there is some hardware info:

http://mindstorms.lego.com/en-.....x#Advanced
Posts: 38
Joined: Sat Dec 10, 2011 4:12 pm
by ghans » Sun Jan 01, 2012 2:38 pm
The Mindstorms bricks just fit into LEGO parts. The R-Pi does not.
There are cheaper , and equally capable robotics platforms available , but most require soldering and you cannot build your robots from legos with them.

The NXT and lejos communities have many examples where the power of a PC and a NXT combined does really exiting things.

You can easily program the R-Pi in a high-level language and let it interface with the original NXT firmware / language or a custom combination !

Are the NXT motors / sensors better designed / engineered for general robotic tasks ? Is their ease to use superior compared to other solutions when it comes to flexibility ? I would really like to do some projects with them , if this is so . The MIndstorms Kits have amazed me for long because they give you the impression everybody can do robotics.

The R-Pi + LEGO motors / sensors cobination would be a real enabler for me and hopefully other people then.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Posts: 4601
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany
by Fduquette » Mon Jan 02, 2012 9:39 pm
ghans said:


Sounds very nice.
Note that lejos is dependant of Java , and OpenJDK , AFAIK , was very slow when tested. JamVM + Classpath should be ported . Furthermore , are you only using NXTs ? The old ones need a serial port ( yay soldering ) for programming .
NQC and NXC are also goog choices as lejos alternatives because the tools IMO could be easily crosscompiled now.

Greetings,
ghans


Yay soldering, I'll have to dig up my +3 reading glasses for that one. Interesting observations on the speed of Java. The Pi for robotics would demonstrate its adaptability, the Pi is not quite a "destination" like a complete laptop and os/software, its more a route to a specific application. One might object that using a laptop with developed software makes more sense, but it lacks the self-containment that a "legoed" Pi. IN another forum, there is a small screen (for rear-facing car cams) that also could be lego-plated and connected to the Pi / robot.It would be a stretch, but as an input device, voice commands to program NXC/NQC? It avoids the clunky keyboard/mouse attachment and the nxt series has a "sound sensor", not sure if it can be adapted to voice interaction
Posts: 3
Joined: Sat Dec 31, 2011 7:26 pm
by bitcrafter » Mon Jan 02, 2012 10:32 pm
Ghans said

Quote.on

Are the NXT motors / sensors better designed / engineered for general robotic tasks ? Is their ease to use superior compared to other solutions when it comes to flexibility ? I would really like to do some projects with them , if this is so . The MIndstorms Kits have amazed me for long because they give you the impression everybody can do robotics.

The R-Pi + LEGO motors / sensors cobination would be a real enabler for me and hopefully other people then.

Quote.off

I've got a NXT/Mindstorms kit. It's designed for ease of use and to be educationally robust.  That suits me well, I'm better at software than hardware. I'm just an everyman when it's robotics.

A design example: The motors come equipped with built in rotation sensors. you can (high level) ask motor to rotate 1, 2...n revolutions. You can't (easily) get inside to rewire the motor, or to paint over the transparent part(s) of the rotation sensor.  So Lego Mindstorms kit may not always offer the best robotic solution, but you (probably) won't break components trying to solve a problem.

You may (like to) know that the signalling between  the brick  and (sensors and motors)  adheres to I2C standard. I2C is mentioned in the forums as supported on the pi.

So the pi could control the sensors and motors with i2c .  Power to the motors is a different issue. I have not thought about that.  Mind you, it should be possible to rig up bluetooth between the pi and the brick and communicate that way too.

You are not limited to the lego blocks programming language on the brick.

Hope this helps.
Posts: 5
Joined: Sun Dec 11, 2011 11:48 am
by ghans » Tue Jan 03, 2012 8:59 am
@Fduquette
Voice recognition ON the NXT would IMHO nearly impossible to achieve .

There IS a 10+ years old example of RCX + lejos + Java VR software + Java Voice Output software around on the lejos pages.

Should be very easy to adapt to your needs/ enviroment.

@bitcrafter

Thanks for the info ! This is good news.
Personally , i will stick to use the Mindstorms brick over infrared / Bluetooth . Its a LEGO brick . It can"t get easier than that : - D .

ghans

PS: There is a more powerful version of lejos for NXT on their pages , and i recently saw the thread on the misuse of a Kinect cam .
Freenect has a Java JNA binding ! I didn"t even know that you could connect a Kinect to a PC ! This gives me crazy ideas !
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Posts: 4601
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany
by ghans » Tue Jan 03, 2012 9:15 am
PPS:
@Fduquette
As for the small screen , do a forum search.
The cheap ones require soldering some kind of extra ciruit . I would prefer one with RCA input , but those seem either too expensive or not easily available.
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Posts: 4601
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany
by waptug » Fri Apr 27, 2012 12:14 am
So excited to get some Pi's to build in with my NTX's .   I'm thinking remote mobile

Telemetry devices sending environment sensor info via wifi or if linux drivers available then possible celluer usb modem to internet. Also mobile cam setups to transmit video via internet.
Posts: 1
Joined: Thu Apr 26, 2012 10:48 pm
by Jaseman » Fri Apr 27, 2012 8:10 am
I can't believe I'm saying this - Because I ABSOLUTELY LOVE Lego.

When you look at the price of those NXT sets, you are looking upward of £200.  In contrast the OWI USB Robot from Maplin £29.99.  It might not be quite as easy to assemble as the Lego equivalent, but there's no soldering required, and you would learn valuable skills from the challenge of getting it up and running.

That said - the possible mobililty of the Raspberry Pi (Running it from batteries) does make this an interesting proposition.... For the rich kids.
Posts: 302
Joined: Tue Jan 10, 2012 12:59 pm
by practisevoodoo » Thu May 10, 2012 2:01 pm
NXT++ allows you to control the NXT directly from C++ and the older releases support linux. I've used this method to control an NXT directly from a netbook stuck on top of a lego base so there is no reason that it shouldn't work for a Rpi.
Posts: 19
Joined: Thu May 10, 2012 12:52 pm
by Joefish » Wed May 16, 2012 11:41 am
My thoughts are that if you already have a NXT with its motors and sensors, there's not much to be gained from getting the Pi involved.

Where you could make gains is in using the Pi to control the LEGO Power Functions motor system, either by driving a few power controller chips via the GPIO and a second 9V power supply, or by emitting the IR control codes for the PF Remote Control (which are also described in public documents).

There's another thread on using the Pi as a universal remote by twisting two infra-red LEDs onto the audio out and replaying samples of IR control codes. Doing it via GPIO would be preferable, but may be harder to do in software because of the high-frequency timing required.

There is a NXT sensor that you could hook up that has its own buffer and signal generator for playing back the IR codes, but it costs more than the Pi. Again, it would need an I2C connection.
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am
by robthebloke » Thu May 24, 2012 2:57 pm
I've actually rewritten Anders mindstorms NXT bluetooth C++ library (and fixed a load of bugs, updated the code to include the newer colour sensor, added xbox 360 joypad support, and added the ability to write 24bit images). Everything works without a hitch on linux, and so it should be *relatively* straight forward to get running on the Pi. I've only just received conformation that my Pi order is being processed, so I should get one within the next week or two. Rest assured, putting together a Pi version of the lib is high on my agenda ;)

I wouldn't bother with the linux port found on Anders webpage, there are more bugs in the bluetooth code than I can remember.

You'll need a bluetooth dongle (there is next to no information on the USB protocol used by the NXT).

The C++ code depends on the joystick and bluetooth libraries, so assuming they're available, and you've got bluetooth up and running, it should be childs play to compile it for the Pi....

I'll bookmark this thread and report back once my Pi turns up (hopefully within the next 2 weeks)
Posts: 8
Joined: Fri Mar 09, 2012 1:30 pm
by robthebloke » Thu May 24, 2012 3:09 pm
Ok, so I'm going to add another post to clear up a bit of confusion present in this thread. In a nutshell, there are 3 ways to use the Pi with the lego NXT. They are:

1. You can use the Pi to issue commands to the NXT brick, it's sensors, and the motors, via the use of a bluetooth connection. (this is what the C++ lib I've been working on does).

2. The NXT provides support for any third party sensors, or devices, that implement the I2C protocol. In theory, this means you could connect 2 wires to the NXT *somehow*, and you could then connect the R-PI to one of the sensor input ports on the NXT. This approach would mean that the NXT is controlling the Pi (the opposite way around to the previous solution).

3. The NXT mindstorms software will not work on the Pi (Win32 and Mac only). If you want to write programs for the NXT from the Pi, then your only real choice is to replace the default OS on the NXT brick, with something like LejOS, or RobotC. This should allow you to use the open source compilers (e.g. RobotC) to create your own executables to run on the brick, which you can upload via bluetooth.
Posts: 8
Joined: Fri Mar 09, 2012 1:30 pm
by Joefish » Sat May 26, 2012 1:55 am
LEGO distribute their firmware source code as open-source (though they have a habit of lagging behind the current firmware release).
They also have an arrangement with IAR by which you can download a free copy of the official development environment to build your own image from the source code. It's limited to outputting a 128MB binary, which is 50% of the Flash on an NXT and roughly what the standard firmware uses.
You can simply pad out the resultant binary to 256MB with 0xFF and it'll treat the rest as an empty file system, or merge your binary with one of LEGO's if you want to keep the demo and default files (which includes the startup sound).
So you could hack the standard firmware. Although one of the replacement OSs may be a better starting point.
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am
by Stateside » Wed May 30, 2012 1:39 pm
ghans wrote:You can easily program the R-Pi in a high-level language and let it interface with the original NXT firmware / language or a custom combination !

The R-Pi + LEGO motors / sensors cobination would be a real enabler for me and hopefully other people then.

ghans


nxt-python is a python driver/interface for the Lego Mindstorms NXT robot.

Support for 24 different sensors, including 8 from HiTechnic and 11 from MindSensors. See nxt/sensors/init.py for a complete list in python-syntax format.

http://code.google.com/p/nxt-python/
Posts: 66
Joined: Sun May 13, 2012 12:26 pm
by Stateside » Wed May 30, 2012 1:53 pm
A compilation of software that works with Lego Mindstorms NXT robot.

http://www.teamhassenplug.org/NXT/NXTSoftware.html
Posts: 66
Joined: Sun May 13, 2012 12:26 pm
by floydbloke » Wed Jun 06, 2012 12:07 am
robthebloke wrote:I've actually rewritten Anders mindstorms NXT bluetooth C++ library (and fixed a load of bugs, updated the code to include the newer colour sensor, added xbox 360 joypad support, and added the ability to write 24bit images).

I'm very interested in this and will be even more so when it's up and running on the Pi.
It's not quite clear to me from your post Rob whether your 'new and improved' library is what gets downloaded from the pages linked above, or do I need to download it from somewhere else (assuming you've made it publicly available of course),
Posts: 16
Joined: Mon Aug 29, 2011 12:25 am
by jweob » Tue Jul 17, 2012 10:56 am
I can confirm that nxt-python works with the pi. I have the pi plugged in with the USB cable and can read out from sensors and control motors with python. I am using debian squeeze.

I am very excited about integrating Rpi and nxt. Yes nxt is not cheap but it is re-usable and quick - as a total linux beginner I would not have been able to integrate 4 sensors and 3 servos, a screen and sound into the Rpi in less than 2 hours!

I am already using SSH/VNC to get into the Pi without a monitor/keyboard and have a battery pack to power the pi. All I need now is to set up my USB wireless dongle and I have a wireless rover that I can drive around my flat from any computer. Then I'm going to get a webcam working on the second USB socket so I can see a rover's eye view while I am driving. NXT has three servos so adding a claw on the front will be very straightforward and then I have something that could conceivably bring me a beer from the kitchen without me leaving my desk (assuming the beer is at ground level).
Posts: 13
Joined: Sun Jul 15, 2012 1:56 pm
by flypig » Mon Jul 23, 2012 4:24 pm
I've only just noticed this thread, but like jweob can also confirm that a Raspberry Pi with nxt-python is dead easy to set up and get working. Using the pi to interface with the NXT brick potentially makes it much easier to use, even if theoretically it doesn't bring much that the brick can't already do.

It does mean you can plug a monitor/keyboard straight in to the robot and develop 'on the device', which is nicer and more immediate than having to upload programs separately.

Using nxt-python is also nice, since you can type in commands at the python console which the robot acts upon straight away.

Here's a brief summary of my experience: http://www.flypig.co.uk/?page=list&list_id=363&list=blog
User avatar
Posts: 6
Joined: Tue May 29, 2012 9:19 pm
Location: Liverpool
by Hexark » Sat Jul 28, 2012 5:53 pm
I've had a first thought of this too. I have a much older robotic, the RCX. I'm more interested in connecting the sensors(motors, light sensor, touch sensor) to the GPIO and doing a simple programme for it. But the hard part is, how much voltage can each sensor take in?
Posts: 6
Joined: Sat Jul 28, 2012 4:03 pm
by holmez » Mon Jul 30, 2012 8:56 pm
Hexark wrote:I've had a first thought of this too. I have a much older robotic, the RCX. I'm more interested in connecting the sensors(motors, light sensor, touch sensor) to the GPIO and doing a simple programme for it. But the hard part is, how much voltage can each sensor take in?


I was wondering about using the older RCX motors/sensors with the GPIO. They have 2 pin connections, so the motor is simply +/- or -/+ (would require a bit of supporting electronics - I'm waiting for the 4th MagPi which discusses ways of connecting motors to the GPIO). The touch sensors are simply switches, so a 10k resistor is all that is required. The problem is the light sensors which are variable resistors, and hence provide an analog signal, whereas the GPIO works with a digital signal.
Posts: 31
Joined: Sat Mar 31, 2012 6:39 pm
by slowpace » Fri Aug 17, 2012 4:20 pm
I just built a bulky robot using NXT, OWI USB Robot, a battery pack, and a webcam...

http://www.youtube.com/watch?v=hDOHEZ_FYv8

It's a bit bulky, there are many batteries around, but it does the work.
Posts: 3
Joined: Thu Aug 16, 2012 2:28 pm
by jtg007 » Thu Aug 23, 2012 1:41 am
I am in the middle of a project using RasPi and NXT, using Python. NXT-Python (http://code.google.com/p/nxt-python/) is a pretty open-ended tool that doesn't require any custom firmware on the NXT, it just sends commands straight to the brick via USB or Bluetooth.

So far it's mostly been time spent getting used to the structure, but I have made simple functioning programs work.

Anyone else using this?
Posts: 1
Joined: Thu Aug 23, 2012 12:34 am
by thomasd538 » Thu Sep 20, 2012 3:18 pm
How is your raspberry pi, python, NXT project coming along?
I am teacher in the US and I have NXTs and awaiting a shipment of Raspberry Pi computer to arrive Friday.
Tom
Posts: 10
Joined: Thu Sep 20, 2012 3:01 pm