Pages

click here

Saturday, November 5, 2011

Robotic Car with Microcontroller


Robot Cars
I wish I could say I had a half-million dollar budget to put towards a Stanford styleGrand Challenge vehicle, but I'm afraid I've already earmarked that money for thermoptic camouflage and bionic calf implants.

Still, it seems like you just can't be a self respecting hacker these days unless you have an autonomous Humvee or two.

So, I decided it would be a worthwhile project to create a smaller scale robotic car. After a quick treasure-hunt under the sofa cusions and a trip to Radio Shack, I had everything I needed. This project looked to be as easy as taking toys from a baby.

Here's a video of the robot car in action (right click and save).  Keep reading and I'll show you how you can start making your own.




Overview

In this article, I'll go over the basic design of the robot RC car. I'm saving some of the nitty gritty details for a second post. This will give all you readers some time to come up with a better way of doing things, and it will give me time to beg our palrobogeek to assist me with some CAD drawings of the motor control circuit. 

Ingredients

You really just need three things to build the base platform for your robot RC car:
  • programmable microcontroller
  • cheap RC car
  • motor control circuit

If you have one of those nice, servo controlled, proportional speed and steering cars, you can probably skip the motor control circuit and interface directly with the control servos on the car. We're going the cheap route with this howto, though, so we'll be using a very simple RC car and bypassing its circuitry, controlling its motors directly.



The Brains

I chose to use the Basic Stamp for this project because, well, that's what I had handy. You could just as easily use a PICAXE, and OOPic, or maybe even a small embedded PC with a parallel port.

The design I settled on requires 4 I/O ports to control the motors. In the future you'll need more ports to handle sensor data or perhaps a GPS device. It all depends on how elaborate and complex you intend to make your control system. The number of I/O ports available and program storage space will probably determine what you choose for your robot's noggin.



The Brawn

robot_car_2.jpgThe car I'm using has 2 motors: a smaller on that controls the steering, and a larger one that drives the rear wheels. They both are run off a 6 volt supply.

Since I stole this car from a baby, I wanted to make this mod as minimally invasive as possible. All we really care about are the 2 motors and the battery, so I ended up just soldering 6 wires: two to each of the motors and two to the battery connectors. The electronics are completely bypassed and it can still function as a normal RC car when the rest of our setup is disconnected.



The Messy Details

Unfortunately, the Basic Stamp can't source enough power to drive the car's motors directly. Instead, I needed to power the motors directly from the car's battery and use the microcontroller to switch the power to the motors.

Initially this had me thinking about using relays. A little current on the microcontroller side of the relay opens and closes the higher power circuit on the motor side of the relay.

One thing I wanted to be able to do, however, was control the speed of the motor. An easy way to do this is using Pulse Width Modulation, turning the I/O pin off and on quickly to limit the power delivered to the motor over time. 

steering_control_circuit.jpgThe problem is that I don't think the response time on a relay is fast enough to do this reliably. We need to move away from electro-mechanical switches.


I ended up going with a modified h-bridge circuit, similar to Steve Bolt's design. With this transistor based circuit, you can use 2 I/O pins to control the motor.



H-Bridge Modifications

When you supply enough current to the base of a transistor, it becomes saturated and the resistance on the collector drops to almost nothing. In this way, you can use a relatively small amount of current on the base to enable a lot more current to flow through the collector pin.

I found that the Basic Stamp wasn't able to provide enough juice to saturate the transistors in the h-bridge. No-saturation equals increased resistance, which also equals poor motor performance and hot smoking transistors.

drive_control_circuit.jpg
So, where 1 transistor is good, 2 are better. I was able to solve the problem by replacing each transistor in the circuit with a Darlington pair. Basically, each transistor gets a buddy that amplifys the input current to its base pin.

The other alteration I made was to add protection diodes. When the motor is spinning and unpowered, it can generate electricity spikes that can force current the wrong way through the transistors and damage the circuit. The protection diodes allow a path for this electricity to bypass the transistors (and the rest of the circuit).



Preliminary Results

I wrote a quick program to drive the robot around and it seems to work really well.

I'm looking forward to hearing your comments and suggestions. I'll post a part 2 soon with updates, a circuit diagram, and a starter program that you can run on your own vehicle. 

No comments:

Post a Comment