Modified RC Vehicle

From Hive13 Wiki
Revision as of 11:27, 19 August 2011 by Paul (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Property "ProjectImage" (as page type) with input value "Image:Rccar assembled.JPG|300px" contains invalid characters or is incomplete and therefore can cause unexpected results during a query or annotation process.

Hive13 Project
Modified RC Vehicle
[[Rccar assembled.JPG|200px]]
Status: Inactive
Start Date: August 9, 2009


This will be a project to modify an existing RC vehicle to have a micro-controller for a brain and use various sensors to navigate through a cluttered terrain.

We will start off simple with just turning to avoid obstacles as it moves forward, but I see this as a platform that we will be able to expand on for future projects.

Current Plan

I figure for the first set up we will use two distances sensors mounted on the front right and front left of the vehicle. By polling the distances reported from the sensors we should be able to sense if the vehicle should turn to the right or left to avoid the obstacle.


This is essentially how the main navigation loop works. Some stuff has been tweeked, but this is a good psuedo-code representation.

leftDistance = leftSensor.value();
rightDistance = rightSensor.value();

safeDistance = 40 cm
minDistance = 20 cm

if( rightDistance < minDistance || leftDistance < minDistance )
    while(GetRightDistance() < minDistance || GetLeftDistance() < minDistance)
        delay(5); // Check the distance every 5ms
if( rightDistance < safeDistance || leftDistance < safeDistance )
    if( leftDistance < rightDistance )


Since tearing apart the body of the vehicle, I have found out a few things. I decided that I would get more flexibility in the long run if I scrapped the current circuit board and wired it up directly to the Arduino Motorshield.

The internal mechanics are fairly basic, but have some odd foibles that made the turning logic more complex than I expected. Here are the basic mechanical parts for the vehicle:

  • Rear drive motor
  • Rear differential gearbox that allows the wheels on either side to stop spinning while letting the other side continue to turn.
  • Front steering hobby servo motor.

I have almost completely scrapped the cars original steering motor setup and replaced it with a hobby servo motor.

The drive motor is fairly simple, it can run forward or reverse and hooks up to a 2-speed gearbox. The speed is controlled via a mechanical switch accessible from the outer body of the car. I have been running it in the lower gear so that the car moves a bit slower and has more time to react to obstacles.


The brain of the project will be based around an Arduino micro-controller. The Arduino will take input from various sensors and use that information to turn the vehicle.

Current electronic parts list:

  • Arduino
  • Arduino Motor shield
    • To control the various servos and motors without burning out the Arduino.
  • 2x Reflective Optical Sensors (IR Distance Sensors, range 10 cm - 80 cm)
  • Alternate power source for the motors
    • 7.2v rechargeable batteries
  • 9v Battery for the arduino
  • Motors

Arduino Details

  • Pins In Use:
    • A0 - Left IR Sensor input
    • A1 - Right IR Sensor input
    • D9 - Steering Servo control output.
    • D3 - Drive Motor control
    • D4, D7, D8 and D12 - Reserved for Motor Shield control.
  • Available Pins
    • A2-A5 - Analog Input // Output
    • D1, D2, D5, D6, D10, D11, D13

Future Plans

We have several hackable PocketPC's at the space, maybe we can set up some kind of webcam on it and do some smart navigation. Or possible set up some kind of radio beacon in the space and we could have it so we could tell the robot to navigate to different beacons attempting to avoid obstacles.



  • Extend the sensors a little bit further to the left // right so that they cover the wheels.
  • Figure out how exactly all the parts will fit inside the truck body, especially the batteries.
  • Re-write the navigation code for use w/ servos

Work Log

This section is for people to post a log what they have done on the project.

New Work Log

July 24th, 2010

New steering servo arrived from HobbyKing. It is amazing. It is very quick and strong, however I am now having issues w/ the sensors.

July 14-20th, 2010

Etched the Shield design, soldered it together, and tested it. It works great.

July 12th-14th, 2010

RCCar ArdShield.png

New chips have arrived for the motor shield and it works great. Servo has been mounted in the chassis for several weeks now, and now works. Circuit has been designed and tested for providing sufficient current for the servo motors and allowing for easy plugging in of the sensors. I think I will add some indicator LED's for debug purposes as well as Rev 2.0 of the board.

I think I am going to try etching the current board tomorrow.

Old Work Log

August 6, 2009 - Opened it up

First I worked on just wiping off the outside of the vehicle since it was coated in a layer of dust. After that I opened up a pack of batteries and put them in the car. After flicking the switch on I noticed that the "on" indicator LED flickered on/off. After a bit of fiddling it was clear that the 9v battery was a bit loose so I wedged it in with some paper. With the paper wedged behind the 9v battery the LED indicator stayed on nicely.

I then proceeded to take out the numerous screws holding the body together. Once all the screws were out the body came apart pretty easily. The vehicle's wheels are held onto the bottom by a removable hub. With the body removed I was able to see that the inside is coated in a layer of dirt and dust that is going to take a bit to clean out.

With the body removed it exposed a circuit board. I spent a little bit of time poking around on the board and determined that the Forward / Reverse motors are just regular motors and by shorting out the logic circuits on the chip I am able to easily make it run forward and backwards. However, I think the steering is done by a stepper motor, or possibly a servo, which can't be controlled just by shorting out the circuit board.

I was going to see how much power the motor was getting, but the fuse in my multi-meter is broken at the moment.

--Paul 13:18, 6 August 2009 (UTC)

August 9, 2009 - Parts hath been ordered

I was able to put in an order to both Mouser and Adafruit for parts I will be using in this project:

Total shipping charges ~$13
Total Cost: ~$57

--Paul 02:18, 10 August 2009 (UTC)

August 10, 2009 - Teardown

Rccar disassembled.JPG

I spent this evening taking the insides apart more fully. Last week I just took the case off and took a look at was inside. This week I worked on cleaning off the circuit board and taking a look at the motors.

The vehicle has 2 motors, both of which look like they are standard DC hobby motors.

  • Steering motor
    • The steering motor is a bit interesting, it connects to a gearbox that then turns both the front steering mechanism, and it goes into this strange sensor pad arrangement to let the circuit board know how far the motor has turned. I was hoping that this would be either a stepper motor or a servo. There are two problems with the current setup if I want to hook into it.
      1. The first problem is that I took apart the gearbox... and now I can't get it back together exactly right. oops.
      2. The second problem is that the RC car's circuit board used the gearbox sensors to detect when to stop turning the motor, and I currently do not know exactly how that setup worked.
        • I got the Motorshield for the arduino, and I will have to see if I can maybe just ignore the sensor reports. What I am supposed to do with the motorshield is adjust the speed of the motor, if I adjust the speed down far enough, I might be able to hold the steering to the left // right without strippping out the gears in the turning mechanism.
    • However, if using the motorshield fails, I might need to buy a servo to control the steering.
  • Drive Motor
    • This is pretty cool, it looks like a hobby motor hooked up to a gearbox, but this is a 2-speed gearbox. The speed was controlled by a switch on the outside of the vehicle. In anycase, the really cool part of this is that it has a differential gearbox setup as well.

-- Paul 01:38, 11 August 2009 (UTC)

August 12, 2009 - Cleaning... Part 1

Rccar CleanDirty.JPG

I spent several hours today using a paintbrush, a sponge, warm water, and Simple Green to brush / scrub / rinse as much caked on dirt and grease off the vehicle. I got through all of the detachable internal parts, but still have to do the outside shell and the front motor.

While dismantling and cleaning the truck, I had a few ideas for how to customize the body and make it look "cool".

  • I think I am going to also work on removing all of the decals that are currently on the body, they are a bit cheesy and I think I might also try my hand at doing some airbrushing // stencil work on it.
  • The headlights on it are transparent orange plastic, I could probably attach LED's to the back to make the headlights light up. Maybe make 'turn' signals to blink as it turns.
  • The body has a large fake plastic engine that sits on the hood, it could be fun to run a red LED up into it so that the intake holes glow red.

In any case, next time @ the space I will be working on cleaning out the actual drive gears and the chassis

--Paul 17:07, 13 August 2009 (UTC)

August 13, 2009 - Motorshield Assembly

Rccar CompletedMotorshield.JPG

All of the parts I ordered just arrived today, so I spent today working on assembling the motorshield. I also realized that I have forgotten to order the 3 pin wire that makes it easy to connect to the IR Sensors, however I am hoping to be able to salvage something from the space.

Plans for the next stop at the space include:

  • Testing out the motors with the motorshield
  • Figure out how I am going to wire up the sensors. (need some 3 pin adapter or something, maybe direct solder onto the board?)
  • Finish cleaning out the vehicle case and gears.

--Paul 14:05, 14 August 2009 (UTC)

August 15, 2009 - Motorshield Playing

A few things of interest today. The RC Car that I am using used to run off of a 9v battery and 4x 'C' 1.5v batteries. I am hoping to use a spare 7.2v rechargeable battery I have from a different RC car. The Arduino Motorshield has built in support for using an external battery pack to power the motors, so I will be using the 7.2v battery there.

Today I hooked up both the front steering motor and the rear drive motor to the Arduino and experimented with driving them. I was able to get both motors turning at various speeds and directions while connected to the motorshield and the external battery pack.

After figuring out that I could get the steering motor to turn left // right I was planning on just using timing to turn left // right, however Timon was looking at the circuit board in the gearbox and I think we have managed to figure out how to use it to determine the position of the motor. There are 5 wires that go into the sensor pad:

  1. Wire 1: Source "High" voltage
  2. Wire 2: Source "High" voltage
  3. Wire 3: When "High" motor is either all the way left, or all the way right.
  4. Wire 4: When "High" motor is in the middle.
  5. Wire 5: When "High" motor is either all the way right, or all the way left.

I also did a little bit more cleaning on the cars drive gears and the base of the chassis. I still need to clean the top of the car.

--Paul 22:40, 16 August 2009 (UTC)

August 17, 2009 - Final Cleaning & Sensor Setup

Rccar sensorTesting.jpg

I started out today by finishing up the cleaning, washed the tires again, then washed the top of the chassis. Looks nice now, but my hands are dried out...

After the cleaning I moved on to working on the IR distance sensors. It is essentially this sensor without the handy wire. I got them for $8 each from here. So I had to figure out some way to wire them up. I decided to try my hand at soldering on some wires to the back of the connection pins. It went fairly well. I soldered 3 wires onto each sensor then spent the next hour or so testing them out.

My original plan was to swap back and forth between the sensors, however the logic I/O pins don't quite deliver enough juice, and the beams of the IR LED's are fairly focused so I don't think I will need to do the swapping.

Plans for the next visit include:

  • Possibly using a Dremel tool to gut the inside of the old RC to free up some more room for electronics.
  • Testing out a program to tie everything together. So far I have done motor tests and sensor tests, now time to do some motor // sensor tests.
  • Test out the 5 wire sensor for the front motor.

--Paul 04:07, 18 August 2009 (UTC)

August 18, 2009 - Steering Motor Tests

Rccar frontengine.JPG

I did a few things today. Earlier today I worked on coding up a rough draft of the Arduino navigation code, however my findings tonight are going to require I rethink a few areas.

After the weekly meeting I hooked my steering motor back up to the motor shield and then wired up the 5 sensor wires to the arduino. As per my previous thoughts on the project I hooked the two left most wires up to a 5v source, and I wired the next three wires up to pins 2, 5, 6 (chosen because they will not interfere with the motor shield). I tested out my original theory of how the sensor wires worked, and found it to be flawed. It seemed that when I had the motor all the way left, or all the way right, I was always getting a test result of "1 1 1" (right middle left). By luck after one of my tests the motor stopped in the middle, and I noticed that I was getting a result of (0 1 0). So I decided to run the motor at the lowest possible speed, and check the sensor status every 100ms, this was the result with redundant numbers trimmed out:

Left Middle Right
1    0      1    Left
0    0      1    Mid-Left
0    1      0    Middle
1    0      0    Mid-Right
1    0      1    Right

Looking at the numbers now, I wonder if I somehow screwed up the middle sensor, because it looks like it is always "HIGH" and never goes "LOW". However, now this gives me something to go on to determine what position the motor currently is in. The only annoying thing is that both "far left" and "far right" seem to mirror each other.

Looking at the sensor pad, I am not sure how much sense any of this makes though, especially with regards to the "Middle" pin.

--Paul 05:12, 19 August 2009 (UTC)

August 20, 2009 - More Steering Motor Tests

I started off tonight by trying out some code I wrote yesterday, but I immediately ran into some problems. First off, my battery was low so I slapped it in the charger. While that was charging I dismantled the front engine and cleaned it thoroughly. Before fully assembling it, I sprayed some white lithium lubricant onto the front gears. After the cleaning and lubing the front motor runs much, much better.

After the battery finished charging I started testing out some of the code I wrote. I am having some odd problems. The way the turning code is working is getting kind of complex.

For example, to turn the motor right:

  1. First check to see if we are already turned right, if we are, exit the function.
  2. Check to see if we are either "Far Left" or "Left"
    1. If we are, then turn the motor until we reach the middle.
  3. Now Check to see if we are stopping at the middle (part of my "Center the wheels" routine)
    1. If we are not, then finish turning the motor to the right.
  4. Set the steering position variable to "Far Right"

The problem is that when I turn off the motor, it has some inertia, so if I stop it at the "middle" if the motor is going fast, it will coast on over to the "right" position, or "Far Right" position. Which then if I try to turn the motor right again, causes the engine to be in an "undefined" state. At least that is what I think is going on. I am going to refactor my code tomorrow.

However, after trial and error I got the steering working about 97% of the time, so I wired up the sensors and the drive motor and started seeing how everything worked together. I ran into more problems here... For some reason the turning logic is triggering even when the distance sensors are not reporting a close obstacle.

Things added to the TODO list:

  • Re-factor the code
    • This includes re-thinking the turn logic from the ground up.
    • Average out the last 3-4 distances readings to prevent crazy output.

-- 15:10, 25 August 2009 (UTC)

August 25, 2009 - One step forward, Two steps back

Short update for now. While playing around with a couple of stepper motors I fried my motor shield (hopefully just my motor shield). If I also somehow damaged my arduino hopefully I can borrow someone elses for this weekend. I have a replacement motorshield on order along with a servo motor, they should be here on thursday. If the steering motor falls through I can fall back onto the servo.

The one step forward was that I learned a little bit more about the steering sensors, the middle pin was always "HIGH" because the sensor wires were bent a little bit making them touch two or more pads at a time. I bent them back into shape, but could not really test them because the motor shield is out of commission.

Plan for Tuesday is to do a little more troubleshooting with the motor shield (friend is coming down to the space with me and he has a nice multimeter and more electrical knowledge). -- 15:10, 25 August 2009 (UTC)

August 27-29, 2009 - Project Assembled

Well, no pictures again this week because I left my camera at the space, but there has been some pretty major progress. On the 26 (wednesday) I spent the evening working on code for the Arduino, but I had no way to really test it out.

On Thursday my new Motor Shield arrived from Adafruit Industries, so I spent most of the evening up until about 9:30 soldering it together. After I finished that up I did some work soldering longer leads onto the motors and the sensor pad in the steering motor. With that done I headed home for the night.

On Friday I worked on putting all the parts required for movement back together. I put all the motors back into their housings, screwed their covers down, put the wheels back on, and screwed their hub covers back on. I also coated everything with the white lithium lubricant. Thank god for my glasses because at one point I sprayed the stuff into a gear and it splashed back on my face, completely covering my left lens of my glasses. I checked the can for warnings, and in big letters on the back it says, "WARNING: MAY CAUSE EYE IRRITATION!". So note to self: Be more careful with the spray can. Right before I left I hooked the motors up to the arduino, put the battery packs on it (9v for arduino, 7.2v for the motors) and wrote up a simple program that made the car drive forward. It worked great, woohoo! We had a mobile platform for the arduino!

So now Saturday rolled around, I had not yet mounted the two IR sensors, so that was the first project. I grabbed some stuff from my house for this: my drill bits, a dremel, a strip of wood, and my assorted container of oddball screws, nuts, and bolts left over from computer repairs. Without pictures this is kind of hard to explain, but I basically drilled through the wood, through the plastic of the front bumper, and then used a couple bolts I found in my container to bolt the sensors to the wood, to the front bumper. I worked for about 3 hours getting the sensor mount set up so that they angled slightly outward.

Then I got to work coding again. I had written up pretty much everything EXCEPT the turn logic. In a previous incarnation of the code I had some troubles working out the turn logic. The front motor has 7 wires coming out of it. Two connect to the DC motor that operates the turning mechanism. The DC motor feeds into a gearbox that moves an arm left and right to turn the vehicle. The gearbox also feeds back to a sensor pad that uses 3 of the wires to give information about the current position of the motor. I have dubbed these three wires, Pin1, Pin2, and Pin3. There are 5 states the sensors will report, they are as follows:

101 - All the way right OR All the way left (super annoying)
001 - Mid-Right
010 - Middle
100 - Mid Left
101 - All the way right OR all the way left (grrr)

As you can see, all the way left, and all the way right have the same sensor readout. So that is the first problem. To remedy this I keep track of what position I last moved the motor too, and if it loses track, I have a set of code that will re-center the motor if it does not know if it is turning left or right. Which brings me to the next major problem. When the steering motor turns, it builds up inertia in the gearbox. So as I try to center the motor, I am watching for "010" to pop up on the sensor, when it does, I shut off the steering motor. HOWEVER, due to the inertia, the motor will just glide on over to the right or left, leaving me in an "unknown" state. The sensors are reporting that the motor is either Left or Right, but the code state says its in the middle. So, my re-centering code gets called, which tries to move the motor back to a "known" state, aka, the middle. This creates an endless loop that makes the car drive like a drunken sailor. As it drives along it swerves back and forth, occasionally it actually makes it back to the navigation code and will attempt to avoid an obstacle, which makes it turn the wheels, which then inevitably sends me back into the harmonic looping between "TurnLeft" and "TurnRight" as it tries to center the wheels.

The highlight of last night was when I was demoing the drunken sailor driving and it smashed head long into a couch. Since it was stuck the steering motors actually managed to center the tires, which then let me drop back into the navigation code, which realized, "OH SHIT! I am stuck!" and then backed the car up, steered away from the obstacle, and then proceeded to drive along and almost take out someone's beer cup. (Maybe the Arduino just wanted to get a bit more drunk?).

I have a couple of ideas for fixing the "Drunken Driver" problem. I know I need to refactor the steering code to better account with un-expected sensor values, but a possible quick fix might be to do one of (or more) of the following:

  1. Turn off the steering motor at "Mid-right" or "Mid-Left" rather than actually at the middle, so that when the motor spins, it will stop in the "middle". I don't like this idea because sometimes, for instance, if the car is stopped, the steering motor is less likely to coast past the middle.
  2. Immediately do a lower powered "reverse" of the steering motor upon reaching the middle to counter the effects of the inertia.

--Paul 20:33, 30 August 2009 (UTC)

August 31, 2009 - Steering and Sensing Frustration

Well, despite saying that I was not going to touch it today while I was at the space I ended up spending about 2 hours screwing around with the different steering settings. I started off by screwing with the steering settings some more, and decided to give it some leeway when it comes to centering the motor and just check to make sure it was in either the middle, midLeft, or midRight position. This means that the car is currently not really driving in a straight line anywhere, but at least it was getting into the sensing routines.

Which then led me to my next problem, it seems that the steering sensors are not exactly positioned that well, so they are not picking up obstacles until it rams them. So I had a bit of a humourous moment when it drove into a wall, backed up, rammed the wall, backed up, rammed the wall, etc... I let it go about 5 times before I stopped it.

I think I am going to start putting some status LED's on the top breadboard for common states the machine is in, such as "Turning Left" "Turning Right" "Backing up" and so forth. It will make it easier to see what exactly is going on with the machine.

So my current plan is this:

  • I am going to sit down with a pencil and paper and work out the different problems the truck can get into, then plan out the code. I think I might also pull the steering motor back out and run it through some tests to try out various methods for making it actually stop when I want it too.

--Paul 04:06, 1 September 2009 (UTC)

September 1, 2009 - ITS ALIVE!

After the meeting I decided to give the steering algorithm another hammering. I commented out my code in the "loop()" statement and replaced it with a fairly simple series of steps:

  • Turn Left
  • Turn Middle
  • Turn Right
  • Turn Middle

I then watched the steering motor as it slid past the middle into the "midLeft" "midRight" range. I started tweeking my "Stop Steering Motor" function, which essentially does the following:

  • Find the direction the steering motor is going
  • Set it to go the opposite direction at X speed.
  • Wait for Y milliseconds.
  • Release the motor so it stops moving.

I found a speed that was slower than the turn speed (turn speed is about 150 out of 255, the "stop motor speed" is 100 / 255), and then I started tweaking the length of time that the reverse motor speed is applied. Through trial and error I determined that reversing the motor for 70ms @ 100/255 would stop it dead center.

My next problem I had been having is that the turn // reverse sensor distances were too short, so I set the turn sensor to trigger a turn @ 50 (distance sensors range from about 5 (infinity) to 500 (10 cm) back down to about 250 (0 cm)) and to reverse @ 150. This was a change from turn @ 250, and reverse @ 300.

In any case, I took it out to the shop floor, set it down, and it went zooming forward, straight for the pillar, then swerved quickly to the right, then sped towards the dirty room wall, swerved to the left, it started heading for the door to the hallway, saw the door, and did a quick turn to the right, straight into the other door, where it got stuck. I then proceeded to spend he next 2 hours playing around with letting it drive itself around the room. It revealed a few things I would like to change and there are still a couple bugs in my code that cause it to get stuck from time to time, but overall, I think the steering problems are worked out for now. --Paul 06:00, 2 September 2009 (UTC)

September 5, 2009 - Code Monkeying...

I have spent the last couple days working on cleaning up my code and playing with the bot our on the Hive floor. Since the last time I was here quite a lot of stuff has shown up out on the floor which has provided some more obstacles for my robot to crash into. It seems to prefer the whole, "Drive straight for an obstacle, turn at the last second and smash into obstacle #2

September 10, 2009 - Oops

Latest version of my code killed something big time. The distance values which should be between [0 - 500] were coming out as 16,000ish, which is utterly impossible by any normal means. I think that I might have broken something with my sprintf(...) calls that I use for debugging. I will work on it again tonight, in the mean time, here is a link to a video of my car driving around the hive. Sorry for the bad quality, my camera is still missing :( .

Obstacle Avoidance Car