Ove's PIC microcontroller pages

My first robot


 

The backround

I promised my son when he was 10 years old to do a robot we could play with. I had allready done a PCB card and had the schematic, the hex-file and the basic-stamp code, at hand from the magazine Elector. The project was called "the Wobbler". The problem was when I, at last 2006, tried to buy the atmel processor needed. It wasn't easily found nearby or even on the Internet.

Instead of searching and asking I decided to take the bull by the horns and do it all from the beginning, and also learn some more about assembler programming and PIC's instread of Atmel. Don't ask me why I got stucked with Microchips circuits. It just happened and I had some other schematics and projects available.

The Building

It's nothing fancy but it works and have been the education start that I needed to get going with some projects that I really want to do.

First i bought some IR diodes and Fotodetectors. I arranged it like the next two pictures show. The small black thing to the right of the IR diode is the detector. The IR diodes are on all the time so it's not any batteryoptimizing involved in this first attempt. The code is polling if the inputs from the detectors are high 4 times per second. Easy to begin with.

You can also see the nice ball-joints on the robot arms. Yes it is Lego and Bionicle. Good for DIY robotprojects.


The "motherboard" of the robot is a former 16C84 development board. I didn't manage to get anything done before both the 16c84 and the 16F84A was obsolete. Anyway, at last I did get to do something with the 16F84A I had laying around.

Some more hardware are the motors which is from old penrecorders from a petrochemical industry where I work. We no longer use penrecorders but ABB Master to control and log the process. They where small and equipped with nice planetary gearboxes which made about 1 1/2 turn per second with 9 volt. I use two H-bridges for driving them. Here is the Datasheet for the Toshibas TA8050P I also use the breakfunction in the code shown last on this page.

The software

I have got the idea for the robots function from the basic stamp code which "The wobbler" used. But before i understood I had to study some assembler and also I got to study an old Basic compiler for the 16C84, which I bought several years ago. At that time to no avail. (It's now free on the link above and useful, try it) I didn't understand it to well and thought it was to complicated together with the time I had to spend on this hobby. So, to rest with it three more years ...

But this autumn 2006 all of the keys matched and I have produced and learned more then I had expected from myself, and in shorter time. This is not common for me. If you are like me you know... If something can go wrong it will and eventually you get tired and the projects stop midways. I also have another problem... I have to many interrests. :-)

Anyway I have upgraded with a new Basic compiler which is under development and supported. This basic code is from this new basic compiler I use. The one which is included in OshonSofts PIC simulator IDE

' robot 1
' written by Ove Tegnér alias Radioman
' using The Basic compiler which follows the software
' PIC Simulator IDE

Define CONF_WORD = 0x3ff1
Define CLOCK_FREQUENCY = 4

Symbol leftir = RA0
Symbol rightir = RA1
Symbol leftfrwd = RB0
Symbol rightfrwd = RB1
Symbol leftrew = RB2
Symbol rightrew = RB3

Dim surroundings As Byte 'create 8 Bit variable
surroundings = 0
'Initialize variable. Left and Right IR eye see nothing.

TRISA = %11111111 'make all pins on Port A inputs.
PORTA = %00000000
'make all pins low
TRISB = %00000000
'make all pins on Port B outputs.
PORTB = %00000000
'make all pins low

main:

leftfrwd = 1 'go ahead forward left
rightfrwd = 1
'and right motor
WaitMs 250
'time between checking ir

If rightir Then 'can right eye see something ?
surroundings = 1
'yes it can .
Endif

If leftir Then 'can left eye see something?
If surroundings = 1 Then
'have right eye already seen something?
surroundings = 3
'yes, Then both eye see something
Else
surroundings = 2
'if right eye didnt see anything, then only the left did .
Endif
'If variable still is 0, Then the first Case
Endif
'in the Select Case structure further down will be True .


Select Case surroundings

Case 0 'Right or left IR eye didn't see anything.
Goto main
Case 1
leftfrwd = 0
'Right eye see, turn left.
WaitMs 500
'Stop left motor for some time .
leftfrwd = 1
'straight ahead again
Case 2
rightfrwd = 0
'Left eye see, turn right
WaitMs 500
'Stop right motor for some time .
rightfrwd = 1
'straight ahead again
Case 3
leftfrwd = 0
'Stop, both eyes see an obstacle in front .
rightfrwd = 0
'both motors stop .
WaitMs 1000
'he is thinking what To do :-)
leftrew = 1
'Reverse left and
rightrew = 1
'right motors.
WaitMs 1000
'reverse away from obstacle a fair amount .
rightrew = 0
'turnaround, left motor reversing
rightfrwd = 1
'and right motor forward .
WaitMs 1250
'turnaround 180 degrees .
rightfrwd = 0
'Stop
leftrew = 0
'both motors
WaitMs 1000
'thinkin what To do, maybe go ahead forward again?
EndSelect
surroundings = 0
'Reset variable after select case maneuvers
Goto main

The compiled assemblercode are not that funny to look at :-)

This code should be fairly easy to convert to another compiler (which you can get free up to 2k) The mikroelektronika mikrobasic. Offcourse You have to fiddle with the "waitMs" timers to get it going with your motors and likings.

If anyone have any use for this code and got a kick of this skeleton code to do his own first robot, feel free to use it and please give me a note on it. :-)

If you have come this far and are speaking swedish you should also read the Diary on this project at the swedish Elektronikforumet.

At last the movie

Here you can see the movie of the first tests of this robot. There are some embarrassing comments you have to listen to. If your not from Sweden it should be OK :-)

My first robot

 


Made by BinaTech and Ove Tegnér, Copyright 2006 BinaTech

Last updated:
Back home PIC Start Index PIC Start Index