# Rebel, first attempt at building a robot.

Line following, Driving around free with obstacle avoidance

This is a first attempt at building a robot. For now it is able to follow a line, and to drive around free with obstacle avoidance. In the near future I will program it to follow someone/thing, and in the far future I will try to let it solve a maze. ie. find it's predefined goal in a maze. The programming bit wasn't the hardest for me as I am studying Computer Science. It was the electronics that I really had to dive into. But in the end that was also not the hardest. I really enjoyed building my first robot and I think many will follow.

The parts that I used for this robots are:

1. Mini Bot Board II
2. Atom Basic Pro
3. 2x Continous rotation servo
4. 1x 180 degree servo
5. Ping))) Ultra Sound sensor
6. Tracker sensor (3x Infrared sensors)

I am already busy in designing a wooden chasis for it. So the Rebel II is already being desinged. I hope I can soon upload some videos of it running. Also I will make the source code available if someone is interested.

Tell me what you think of it? some suggestions for improvement, critisism, all is welcome.

UPDATE:

added 3 videos. In the first video rebel is following a line. In the second one it is navigating around and avoiding obstacles. In the third video, at the end, the batteries fell off and he dragged his guts around :P

## Comment viewing options

As you can read here  you can use normal servo lib, in pin 3, 5, 6, 9, 10, and 11, not only 9 and 10!!!

Am i wrong?

Unfortunately, as far as I know that's not right. PWM just means toggling the voltage between on and off at a certain rate to end up with a voltage in between -- if you've got 5V and you want to get 2V, you just need to switch the line HIGH for 2/5 of the time and LOW for 3/5 of the time. But the total length of the cycle can vary. You could use 50ms (HIGH for 20ms and LOW for 30ms) or 10ms (HIGH for 4ms and LOW for 6ms), etc. As long as the ratio is 2/3, you'll end up with an average voltage of 2V. Most microcontrollers that offer PWM seem to use really really short cycles, in the microsecond range.

Servos also use PWM for their signals, but they need a specific type of PWM --  namely, the total length of the cycle has to be 20ms. If you look at the documentation for analogWrite that you linked to, they mention that the frequency of the Arduino's PWM signal is about 490 Hz, which means that one cycle lasts 1/490 of a second, or about 2ms. So the pulses would be about 10 times too fast for the servo to understand them.

That's why they wrote the Servo library, which manually outputs the PWM pulses at the right rate when you call Servo::refresh(), and the ServoTimer1 library, which uses the Arduino's hardware timers to maintain the PWM pulse in hardware, but the Arduino only has 2 hardware timers, connected to pins 9 and 10, so you can only use that library on those two pins.

With all that said, I've never actually tried hooking up a servo to one of the other PWM pins and trying to control it, so I guess I don't know for a fact that it wouldn't work. But I figure that if it did work that way, they probably wouldn't have bothered to write those other libraries :)

Dan

Nice :)

/ Fritsl

nice bot you really have an advantage with the computer science. programming is all a little difficult for me.

im going with the most basic stuff. im looking forward to some movies. good luck

Cool, I thought it could walk at first, looks like legs :D

Have you got a picture from the side?

AtomBasic!?! Can you dump some code? Like, how do you turn the servo? How is the tracker sensor made? Prefab? From where, which (programming) interface?

Thanks for sharing it, and welcome to the club of us who creates life :D

(You ask for critisism - but without video and / or pictures from the side it is very hard to judge.. But it looks cool :D I would like it for cristmas as it is, just to try some code on it etc)

/ Fritsl

I will try to make more pictures tomorrow and also shoot some videos. The track sensor is indeed prefab for me as a non-electronic guy, never soldered anything, this seemed the best solution imho. I will try to make one myself one day, as I understand more of the electronics. AtomBasic is almost the same basic language (with slight differences) as the basic language for the picaxe, and/or basic stamp microcontrollers.

To make a servo turn you would write (servo on pin 0):

servopin CON P0

Main:
Pulsout servopin, 4800
Pause 20
Goto Main

With this code the continuous rotation servo would go full speed forward, and the normal servo would turn totally left. Turning totally right (or driving backwards) would be a pulslength 1000 and centering (or stopping) is 3900. I think this code is almost Identical to that of the picaxe (except for the pulslenghts of course).

Thank you for your reaction, your robots are a great inspiration for me, and your site is really great!

"Lead, Follow, or run around like crazy"

lol - are you a "non-electronic guy" :D I am happy that my robots are inspiring, thanks!

Regarding the code for the servo....

I KNEW IT!!

You will have to keep pulsing to get the servo going! So everything else has to wait!

Picaxe does this itself. I start to realize why I get so much street credit for such navigation as http://letsmakerobots.com/node/254

It is in fact not me who is a genius, it is just because I use Picaxe; You can never do that kind of thing with any of the other systems..

With Picaxe you just write

servo 0,  150

main:

'Do funny stuff

goto main

- And so, while you are doing funny stuff, the Picaxe keeps that pulse going.. Just untill you turn off the pin (pin0 = 0) - or turn the servo somewhere else (servo 0, 225)

It is almost like multitasking. Yes, I said it; Multitasking in Picaxe!

PS: I am also a "non-electronic guy"! Don't let it stop you, we can get pre-made everything ;)

/ Fritsl

i don't wanna be bad Fritsl, but Arduino do the same.. while you do funny code, servo keeps the same pulse =P

thats why i got tired of Basic Stamp II..!!!

About the robot, it really looks cool, (my ultrasounds sensors never more arrive T_T i wanna play with them like everyone doing =] )

Its a good idea of use that metal parts from Mecano (its like lego but with metals) i need to search for it.. maybe i have something arround..

Can't wait to see the movies, Contratulations

As I'm sure you know, the Arduino does support the same ability if you use the ServoTimer library, but it can only do it on two pins, 9 and 10. If you use the regular Servo library, you can control servos on any pins you want, but you have to call the Servo::refresh() function at least every 50ms, which is not really much better than the Basic Stamp way of doing it. From what I understand, on the Picaxe you can control more than two servos with those servo commands. Is that right, Picaxers? If so, then the Picaxe is still a step ahead in that respect :) But if you only have one or two servos to control, then the Arduino does just as well.

Dan

Indeed it took me some time to get the navigation as smooth as you in http://letsmakerobots.com/node/254 but with some "smart" programming, and trial and error I managed to get the same results.