Picaxe code for line follower

linefollower_0.3gp (1409615Bytes)
ALL_MY_LINEDANCERS.zip (7444Bytes)

tHIS POST IS A MESS. iT IS EDITED SEVERAL TIMES AND MAKES NO MORE SENCE. i HAVE NO TIME TO DO MORE ABOUT IT: bOTTOM LINE IS THAT THERE IS ATTACHED A ZIP-FILE WITH ALL i EVER DID INlINE-SENSORING FOR pICAXE!


 

Chris the carpenter asked for picaxe code to line follower.

First you have to hook up the sensors to the analouge in. That is a chapter for itself, but in the end you will have a value for each sensor; 0-255

I have tried some different line-sonsors, once JIP and I was playing around with them.

Opposite what JIP believes in, I think that a man only needs 2 sensors to make it work.

Fur fun, I made the smallest routine I could. I cannot remember the correct syntax, but it goes something like this:

main:

readadc 0, b0
readadc 1,b1

pulsout 0, b0
pulsout 1, b1

goto main

It actually worked quite fine! The more white on one side, the more throttle. Only, motors only ran with 50% in average, which is not optimalk ;)

So I wrote some other code, and looking at it now, I cannot find head or tale in it, I must admit - but you asked for it, Chris, and here it is. Erh - here is some code, I made a thousand versions.

The line-follower on the picture & video does have 4 sensors, but that was just because I was testing what that line-sensoring-thing was all about, only 2 spaced just a little wider than the black line is used. Erh.. the code, I can see is using 4 .. Whatever - it is so goddamn easy to make that code, use mine as an example, my robot no longer exists ;)

As you can see, even if the robot is held in one side, it just insists on stauing on track, and there is no wobbeling on straight tracks - mision completed IMHO ;)

DSC00058.JPG



symbol tolerence = 25

main:

readadc 0, b0
readadc 1, b1
readadc 2, b2
readadc 3, b3

if b1 > b2 then gosub H
if b1 < b2 then gosub V

goto main

H:
b4 = b1-b2
if b4 > tolerence then
low 5: low 4
low 7: high 6
else
gosub L
end if
return

V:
b4 = b2-b1
if b4 > tolerence then
high 4: low 5
low 6: low 7
else
gosub L
end if
return

L:
high 4: low 5
low 7: high 6
return


Yeke! Google video does not like videos from my old phone, pretty slow framerate it makes out of it. So I also attach as a file, see below - you should download it before viewing - on my PC I get the movie in ascii if I just click

 

Hey Frits,Of course you can

Hey Frits,

Of course you can do line following with only 2 sensors - you can even do it with one sensor. What I said to you back when we were doing line following (I still am by the way) was that I believed that fast and smooth line following needs more than two sensors and here is why:

If you want smooth line following you should have sensors that are distanced no more than about the width of the line to follow from each other or your robot will probably zig-zag along the line. This can be done using only two sensors but at a cost in speed. If your robot goes very fast it is likely to lose the line during a sharp turn and this is why I would add more sensors with the same distance between them as the original two sensors. The wider your line sensor array is the faster you can go without the line slipping away from the sensors.

My typical line following scheme is something like:

  1. read sensors
  2. update sensor values according to some calibration since no two sensors are completely the same and will read different values on the same spot
  3. measure line position relative to line sensor center - if using analog sensors this can be interpolated between sensors
  4. use measured position in a PD-regulator that will compute a regulation term
  5. update motor outputs (or servo outputs) using regulation term

When I get my Robot Hansen put back together and get the line following to work properly at home, I will submit the code for the line following.

Your line follower does seem to work quite nicely though. You should have entered DTU robocup with that thing. I’m sure it would have done a lot better than Robot Hansen :-).

- Jimmy