Is the Arduino platform better than the Basic Stamp for UAVs?

Jordi has opened my eyes to the Arduino platform, which is being described as a "Basic Stamp killer". Is it a good candidate for autopilots? Well, let's look closer.

Arduino is an open source embedded processor platform, based on the ATMega168 CPU, which has more memory than the Stamp and is a lot cheaper. There's proper development software available and SparkFun has a full line of dev boards and other accessories. Its programming language looks like C but should be easy enough to learn for people who know Basic.

It started as an Italian project (it's named after an Italian king) and still has a European flavor, so that may explain why we in the US don't know it well. But Jordi, in Mexico, had done some very interesting work in exploring its potential as an autopilot platform.

His main project is the "Arducopter" (shown at right), which has resulted in some very nice code, such as this navigation routine.

In his comments, Jordi (BTW, he's just 21) described some of the cool things he's doing with it, which I'll simply quote with links here:

"This is my first test with Boarduino (a breadboardable version of Arduino) controlling servos and using an accelerometer from a Nintendo Wii. Right now I'm using Gyros and Kalman filters. I even wrote code to read PMM signals, the GPS is finished and working pretty well, the IMU is in beta, and I'm developing an altimeter using I2C technology and high quality pressure sensors."

Here are some links he provided:
I'm intrigued. I don't see anything here we can't do with Basic Stamps with a little fiddling, but I have to admit that certain projects look like they would be easier with the Arduino, mostly thanks to its greater memory and full range of variable types, including floating point. Anybody else looking seriously at Arduino?

Views: 3290

Comment by Gareth Farrington on February 22, 2008 at 1:11pm
If you re going to use a separate board to control servos then I agree that it is irrelevant to the platform choice. Its is another part to add but if it keeps the overall cost and complexity down (because you don't need a faster controller) then its certainly a win.

One of my goals is for this to be easy for others to tinker with so I would like the source to be easy to understand. Using the Wiring platform and language makes it a lot more accessible.

I though that the PWM outputs on the Arduino and Wiring were driven in hardware? I.E. you set the PWM width and they keep doing that for you. I thought the real CPU hog was going to be reading the channels from the receiver since you basically have to build your own PWM decoder in software.

I'm looking at Servo.cpp from the Wiring examples but not totally clear to me yet.

So how is all that actually accomplished?
Comment by Gareth Farrington on February 22, 2008 at 4:50pm
I read at least one good paper on driving servos with the Arduino and they are driven by the digital out pins. It said the PWM pins on the Arduino were basically useless for driving servos because the frequency they ran at was too high.

So is that what you guys are all doing, driving servos off the digital out pins in software?

What about reading PWM from the Rx, is it done the same way with digital ins?

3D Robotics
Comment by Jordi Muñoz on February 22, 2008 at 8:00pm
Ok to control servos is very easy, you can use any digital PIN to generate a PWM, you moust put the pin high between 500 (full left) to 2500 (full right) microseconds, you must pulse every 20 miliseconds, here is an example:

// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(nowPulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse

I used this code to control servos in the arducopter, here is the full example and code for pulse servos:
http://dma.ucla.edu/senselab/node/386

Actually i wrote a better version to pulse 13 servos at the same time and consume the same cpu power as pulse only one (i used a parallel pulse trick), but i lost the code.... =)

If you want to read or generate a PPM (Pulse position modulation), this include all the servos position in one single signal... If you want to learn more about PPM enter here:
http://www.hooked-on-rc-airplanes.com/pulse-position-modulation.html

OK i wrote a code to read PPM signals coming from a buddy cable or you can hack your RC receiver to read it (just works in futabas and walkeras):
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1199165055

If you need help to intercept PPM signals from your receiver, read this:
http://paparazzi.enac.fr/wiki/index.php/Other_Hardware#R.2FC_Receiver


Anyway i don't going to use it in my final version...

And here is a good exampe to generate PPM:
http://diydrones.com/profiles/blog/show?id=705844%3ABlogPost%3A22327

BTW, is not useless, because you need a lot of power to process the IMU data and other stuff.

Nice day, and good luck
Comment by Gareth Farrington on February 22, 2008 at 8:33pm
Cool! i have been looking at this all day and I figured out the Parallel Pulse thing just a little while ago.

Basically you set all servo pins to HIGH and then turn them off at he right time. It should only take 2ms to run as many servos as you like. Over a second thats 100ms or 10% of the execution time. If you use an interrupt and return between the setting HIGH and 1ms later when you need to start turning pins off it will only use 5% of the CPU time.

If your building an RC receiver you probably know this trick already. Maybe thats how they work??? We need to find out. If thats the case then we can optimize the reading of PWM data too.

We set an external interrupt to one of the Rx input pins. Once it goes HIGH we loop over all the pins with a digitalRead and record the times when they go to LOW.

If that really is the case then we could do 6 channels in & out for about 10-15% of the CPU time. Not bad. It probably isn't that simple but its worth writing some test code to find out.

I'm not keen to hack the Rx to get PPM signals. I fly Spektrum anyway so it wont work with my gear anyway. Did you know they use a real micro controller on their Rx? Reading PWM signals from the Rx gives the best chance of it working with all R/C gear.

Thanks for the help. Good luck with your project!

3D Robotics
Comment by Jordi Muñoz on February 22, 2008 at 10:11pm
That this the exactly way how the parallel mode works!!! Great!!! =)
No problem, if you do something related with this, please share it here =).

Thank you!
Comment by Gareth Farrington on February 23, 2008 at 11:33am
I ordered a Wiring board and an SD card holder to do some testing.

After thinking it over I would guess that the R/C receiver manufacturers care more about accuracy and latency than execution speed. After all, they only have to drive servos so it would be a waste not to use the whole CPU to do the job.

They probably send one servo pulse at a time so they can get the pulse length perfectly accurate.

I haven't seen any boards that can offload the reading of PWM so first I will focus on writing a PWM read driver for 6 to 8 channels. That should be enough for any Micro UAV.

If that is all the CPU we want to dedicate to control there is always the Pololu servo board to offload the servo driving. So its a problem that we don't have to solve.

First up will be a program to characterize the output of the Rx so we can learn more about them. I expect there will be differences by brand and maybe even model.

Code will be available for others to test with as well.
Comment by James Hall on February 23, 2008 at 12:46pm
Found this odd video on the Arduino

http://blog.makezine.com/archive/2008/01/intro_to_the_arrrrduino_b.html

3D Robotics
Comment by Jordi Muñoz on February 24, 2008 at 7:58pm
About the "accuracy and latency" you need to read several PPN's frames an then average it, and make a code that is able to recognize bad frames and discard it. When i was making some test's i figured out that the receiver sends 1 frame about every 50 to 100 microseconds, and you need to refresh data in servos every 20 miliseconds, so you have a lot of ppm's frames to average before pulse any servo. =)

Good Luck..

3D Robotics
Comment by Jordi Muñoz on February 24, 2008 at 7:59pm
Sorry i mean ppm's, no PPN's...
Comment by Gareth Farrington on February 25, 2008 at 8:37am
So are you reading the PPM signal off the Rx now? This is what Paparazzi does. They also dedicate a chip with more power than an Arduino just to do PPM decode and PWM output.

I saw some code you posted that had a function to get the ticks from Timer0 so you could calculate the uSec width of the Servo PWM signal.

I'm not sure yet but i think that timer might be a source of error. Its ticking too slowly (I think its using the /64 prescaler). It depends on the timing but you could get 8 uSec fluctuations between frames.

Most current R/C gear supports 1024 steps. Thats about 2 uSec accuracy.

Some other things about that code don't add up to me. Specifically I don't think there are 256 ticks per millisecond on the Arduino. I think I found the post where you got the function from. I'll try and post something in the forum tonight.

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2014   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service