Picaxe Line Tracking Mouse

daniel.sutton

New Member
hi im doing a short course on electronics and i made a dick smith line tracking mouse.

http://www.dse.com.au/cgi-bin/dse.storefront/480311200885400a273fc0a87f9c0649/Product/View/K1235

instead of using the components provided i used my picaxe 8m.

http://picaxe08.orconhosting.net.nz/Photos/Projects/Mouse_08M_Bot.jpg

as seen by previous posts in archive 22 dirt cheap robot

http://www.picaxeforum.co.uk/search.php?searchid=91980

i typed up some code but it doesnt seam to work.

main: low 0
low 1
wait 5

start: if pin0=0 and pin1=1 and pin2=0 then fwd
low 0
low 1
goto start

fwd: high 0
high 1
if pin0=1 and pin1=0 and pin2=0 then right
if pin0=1 and pin1=1 and pin2=0 then right
if pin0=0 and pin1=0 and pin2=1 then left
if pin0=0 and pin1=1 and pin2=1 then left
goto fwd

left: low 0
high 1
pause 50
if pin0=0 and pin1=1 and pin2=1 then fwd
if pin0=1 and pin1=0 and pin2=0 then fwd
goto left

right: high 0
low 1
pause 50
if pin0=0 and pin1=1 and pin2=0 then left
if pin0=0 and pin1=0 and pin2=1 then left
goto right


Any ideas?
 

hippy

Ex-Staff (retired)
Can you give some hint as to in what way "it doesnt seam to work" ?

Does it do anything or nothing ? Does it sometimes work, sometimes not ? Does it only ever turn left ?

Have you tested the buggy can move forward and turn left and right without the line tracking part of the code included ?

Have you checked the pin0, pin1 and pin2 inputs give the values you are expecting when the motors are turned off and the sensor is moved across the line it will be tracking ?

When turning left or right would it not make sense to include a check to see if it should turn right or left in case it misses the indicated change to be going forward ?

What happens if the pin values change between consecutive IF statements ?

You can optimise your code for simplicity and speed, for example ...

Code:
fwd:
  high 0
  high 1
  Do
    if pin0=1 and pin2=0 then right
    if pin0=0 and pin2=1 then left
  Loop
 
Last edited:

marcos.placona

Senior Member
He's using an 08M but then using "IF pin0" ... no, that won't even compile.
Ahh sorry, I misread his comment. I thought he was affirming that pin0 was output only, and just only on 08m.

I didn't really think it through when I read the comment. My fault :)
 

hippy

Ex-Staff (retired)
Well I missed the "IF pin0" entirely ... evidence if it's ever needed that the more a poster tells us exactly what the problem is the better chance of the issue being spotted and resolved quickly with less time wasted all round.

Not an attack on you daniel, it's applicable to everyone and first time posters are always deserve some slack. PS : Welcome to the forum.
 

daniel.sutton

New Member
Hey sorry guys

hey sorry for the mis communication.
"it doesnt seam to work" was in reference to the code in the programming editor.
i did some research and a) yes pin0 is output.
so i did some playing around with the code and heres what i got so far

thanks for your help with the whole pin0 bug.


'Picaxe08M Pins
'Pin 0 = Output only
'Pin 1 = Input / Output
'Pin 2 = Input / Output
'Pin 3 = Input only
'Pin 4 = Input / Output




symbol left_motor = 0 'pin0
symbol right_motor = pin1
symbol left_sensor = pin2 'logic "1" = black line (non reflective) Logic "0" = no line (reflective)
symbol centre_sensor = pin3
symbol right_sensor = pin4


let dirs = %00000011 'Ports 0,1 =outputs Ports 2,3,4 = inputs
let pins = 0



main: if left_sensor = 0 and centre_sensor =1 and right_sensor = 0 then fwd 'If left and right sensor off but middle sensoron go foward.
if left_sensor = 0 and centre_sensor =0 and right_sensor = 0 then left 'If left, middle, and right sensor off then search.
if left_sensor = 1 and centre_sensor =1 and right_sensor = 0 then left 'If left and middle sensor on but right off gosub left.
if left_sensor = 1 and centre_sensor =0 and right_sensor = 0 then left 'If left sensor on but middle and right senso off gosub left.
if left_sensor = 0 and centre_sensor =1 and right_sensor = 1 then right 'If left off but middle and right on gosub right.
if left_sensor = 0 and centre_sensor =0 and right_sensor = 1 then right 'If left and middle sensor off but right sensor on gosub right.

fwd:
high 1
high 0
goto main

left:
low 0
high 1
goto main

right:
high 0
low 1
goto main
 

BCJKiwi

Senior Member
The caveats - No experience with robots, Haven't studied the logic in great depth.
There are 8 possibilities and only 6 are tested
0 0 0 tested
0 0 1 tested
0 1 0 tested
0 1 1 tested
1 0 0 tested
1 0 1
1 1 0 tested
1 1 1

Also there is 1 fwd, 3 left and 2 right!

There is no stop or reverse.

Wouldn't fwd require both 0 and 1 to be high?

Just ignore if this is all off beam.
 
Top