A simple demo of how to read RC signals and drive servos with Arduino

Most autopilots have the ability to read signals from a RC receiver and drive servos. For instance, in the case of ArduPilot, we read the current throttle setting when the autopilot is engaged (so we can maintain that setting, although we'll later nudge it up and down to maintain altitude) and we drive the rudder servo and ESC. In the case of BlimpDuino in RC mode, we read the throttle and left/right commands from the RC receiver and translate them into commands to the motor drivers (the vectoring thruster servo is connected straight to the receiver and doesn't have to go through the autopilot at all).

In Arduino, you read RC signals by using the PulseIn command, and you drive servos with the servo.write function added by the servo library. The problem is that PulseIn waits for the next pulse, and the more channels you're reading the more time your CPU is spent waiting. A good rule of thumb is that each PulseIn, without modification, takes about 30% of your CPU time, so you can see that about two channels is the max. However, the form of the function is pulseIn(pin, HIGH, timeout) and you can adjust "timeout" to minimize the waiting time and improve that effeciency. I've been playing around with 50000 (it's in microseconds), but your mileage may vary. Anybody having better luck with a different value?

Anyway, if you want to see how this works, here is a simple demo that just reads two RC channels and mirrors the commands with two servos. It's just like regular RC, but it's all going through the Arduino (so it can take over and go into autonomous mode anytime you want). Just read the comments in the code and plug the RC channels and servos into the right pins in your dev board (a Decimila and ProtoShield--don't forget the breadboard--work great). Here's a picture of my setup:

Views: 33837


3D Robotics
Comment by Chris Anderson on June 16, 2008 at 9:04am
While I figure out the most effecient way to read RC signals, I modified the code to drive blimp motors rather than servos. The code below drives two channels of a TI L293D motor driver chip from atmega pins D6 and D7. It's for steering (differential thrust) and throttle (total thrust).

So to fly the blimp in RC mode, channel one (steering) drives differential thrust on the twin blimp motors, channel two (up/down) drives the vectoring thruster servo directly from the RC receiver, and channel three (throttle) dictates the total power to the blimp motors. So two channels are handled by Arduino, translating RC command to motor signals, while one is straight RC.

[UPDATE: I posted the wrong code and I'm not near my PC to get the right one (I'm in Munich on my way to Milan for a day). I'll repost when I get home]

3D Robotics
Comment by Chris Anderson on June 18, 2008 at 12:14am
Here's the correct code: RCTest.pde

I'm running it on a dev board with a boarduino right now, so I can get the RC channels in and choose which motor driver channels to use. But the next version of the Blimpduino board (coming out in a day or two) will be designed for RC in and vectoring thrusters and will run this code natively.

Comment

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

Join DIY Drones

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service