Arduino + Lego NXT

Video: Arduino + Lego NXT = Arduway - YouTube
Hope you enjoy :slight_smile:

Now that is impressive well done. :smiley:

The last 30 seconds of the video is just black, is that right? :-?

Nice! Thanks for sharing :slight_smile:

I'm proud to announce that the library I've created, arduino2lego, is now on Sourceforge:

Since it's not well commented, if you have any questions about hardware/software, just ask and I'll be glad to explain what I've done :wink:

PS: the video is all black at the end... sorry...
Does anyone know how to crop it without losing comments, views?

I'll bite. How are you measuring the tilt? A accelerometer, a gyroscope or both? Or, are you doing it with distance sensors?

Tom

The tilt is measured by a gyroscope (Epson).
The gyroscope tells angular speed so integration is needed to obtain actual angle.

Datasheet(s):
http://ndap3-net.ebz.epson.co.jp/w/www/PDFS/epdoc_qd.nsf/f5af260ddc5fb8ed49256a9c001d58b2/6c3c798debd98cfe492571f1000ff2dc/$FILE/XV-8100_E082.pdf
http://www.epsontoyocom.co.jp/english/product/Sensor/set01/xv8100cb/index.html

and how do you correct the drift ?

PS great work!

The drift is not evident in the first moments of functioning so it was satisfying enough for our purpose.
I tried anyway to correct it (to make the robot stand up hours and hours) using a band-pass filter (instead of an integrator) but it was not working as well as one would expect.
...Are you aware of any other method?

It would certainly be better not to have to integrate: this would avoid the integration drift.

As a conclusion... if you're thinking of creating your own Arduway think of replacing the gyroscope with a compass that directly returns the angle.

..Are you aware of any other method?

To do it right, it sounds like you need an accelerometer, too. David Anderson provides a pretty detailed description of how he did this on his nBot web site

He explains, "The gyroscope and accelerometer are combined with complementary filters to provide an inertial reference sensor. The ADXL202 accelerometer provides accurate static tilt information, when the robot is not accelerating. The gyroscope can be integrated to provide accurate dynamic tilt information, but the integration tends to drift over time. Combining the two sensors provides a robust inertial measurement."

But, there are apparently a number of different ways to make a balancing robot. I've heard of at least one person who managed to do it using distance sensors to figure out the tilt based on the distance of the sensor to the ground.

That's interesting!
Very nice idea (and very nice implementation!).

In my opinion an angle sensor can be enough (it certainly is enough in Matlab simulations).... and it is certainly less expensive than two sensors (BTW, I'm saying that because cheapness was one of the aim of the project).

The robot works pretty well even with only a gyroscope... if you start your own project keep in mind that an angle sensor (or maybe gyro + accelerometer) is better.

you've been blogged:

http://arduino.cc/blog/?p=89

/d

Thank you very much! :slight_smile: :slight_smile: :slight_smile:

Well done,
Its a really nice project and great platform for control scheme design.

I have one question if you don't mind me picking your brain. How did you do the numerical integration? On the arduino itself? or integrate the signal before the arduino a/d?

If on the arduino what algorithm did you use? and what time step did you use?

Thanks and well done again.

David

The integration happens inside Arduino.
I preferred not to do hardware integration because I hoped that software could give me more flexibility.

I chose the fastest sampling time I could, which is 4 ms (--> 250 Hz).
I first used the rectangle method for integration but now I've preferred the trapezoid method to minimize the error: what I've found out is that most of the error comes from (1) the sensor and (2) ADC approximation.

Anyone going to replicate this robot should use an angle sensor (maybe I2C based) instead of a gyroscope; integration is bringing avoidable error.

Thanks,

I'm think I'm going to have to do integration for another project. (control of a flexible link). So nice to see its possible with the arduino. :slight_smile:

David

this is awesome.

Where can i find how to connect this motors to the arduino? or how it works the protocol used by NXT

I'm making available my thesis as a free download (CC license) here:
http://trive.dyndns.org/tesi_web.pdf.
(Please report if the link gets broken)

Unfortunately it's in italian (description of NXT connectors is on page 59-60) and it's mostly about the theoretical part of the problem.

What you need to do to drive NXT motors is to:

  • understand NXT connector, which has 6 wires:

  • Motor signal 1 (from 0 to 9V)

  • Motor signal 2 (from 0 to 9V)

  • Ground

  • Encoder power (5v)

  • Encoder signal 1 (0 to 5V)

  • Encoder signal 2 (0 to 5V)

  • hack your NXT connector (you can do that using a RJ-12 connector)

  • use a L293D to give enough amperage to the motors (you cannot drive them directly from Arduino)

  • use a 9V voltage stabilizer to power the L293D: it must handle enough amperes (1 or more reccomended).

  • use an interrupt to handle the encoder signal (if needed): you can download my code and look at the out() function.

This is exactly what I am planning to do, I am glad I found this as my guide. Thansk for sharing.

And that would be my first robot.

Your link to tesi_web.pdf is broken. Have you published your circuit and other details anywhere else :'(?