Line Follower Basics Available?

Wink setup, hardware, basic programming. User to user support.
wclift
Posts: 32
Joined: Sun Feb 07, 2016 6:10 am

Line Follower Basics Available?

Postby wclift » Thu Feb 11, 2016 6:40 pm

Does anyone have the basic information on Wink line following sensors? This information doesn't seem to be available in the standard tutorial packets yet.

Kevin
Posts: 181
Joined: Tue Jul 28, 2015 12:56 am

Re: Line Follower Basics Available?

Postby Kevin » Thu Feb 11, 2016 6:57 pm

If anyone wants a line following example, contact me through the contact form at the PG website. I'll send you what we used for the KS videos. When I get to that part in the lessons, we'll be re-writing this code to make it more clean. What we have isn't super pretty but it works and you can tune it if you're interested. I didn't want to post it outright because I didn't want it to confuse and/or scare people. :)

User avatar
sil
Posts: 40
Joined: Thu Oct 01, 2015 1:04 am

Re: Line Follower Basics Available?

Postby sil » Fri Feb 12, 2016 1:55 am

Take a look in the Ringo code area where i posted my simple line following example. I haven't adapted it for Wink yet but it should be simple to follow if you want to try it yourself. The process I used is based on Ringo which only has two IR sensors underneath.

I started by writing code to read the two sensors and output to the serial port so I could look at the values via the arduino software, now they have the serial plotter this helps immensely. I would place ringo in random locations on my running surface to see the "background" values, and I made a "pad" of the line material to similarly obtain values for the line Ringo would see. This allowed me to be confident that Ringo could "see" the line differently to the background. From this process I had a threshold value where i was confident the running surface would never return a value lower than this threshold and any value below the threshold is either the line or off the edge of the desk.

So my approach in the code loop is to read the left sensor and right sensor in turn then compare them to the threshold value, if one sensor detects the drop (ie the line) then i speed up one motor to turn ringo back to the line again. Simple but its fast and works, and i'm confident about my posted code, its been reliable on different tracks I've made. Its probable not the most elegant code and no doubt the sensor check could be reduced to a function where you call the sensor rather than duplicate the code with different variable names, but thats a future project for me or anyone wanting to play with my code.

My poor Winks are being ignored, I play with my Ringo too much. But the code I posted should work if you change the read sensor numbers the the appropriate numbers for Wink, (I believe Wink has four in a row under the front so use the numbers for the leftmost and rightmost sensors only and ignore the middle two to start with, and i think Wink should line follow happily ( I can see myself trying it this weekend).

I do recommend you have a try, line following sounds like it need complicated decisions but its really simple, I started from nothing except the Ringo guide and avoided looking at plumgeek's code so it didnt influence me and found it a simple exercise and worthwhile doing. Forget the shape of the line, its width can matter though. A piece of black electricians tape on a table top is all you need to start with. I think Wink's IR sensors are much closer than Ringo's so I dont know what width of tape would best suit to start. That also might mean line following needs to be a reversed approach to what I took for Ringo: that is treat the line value as a background and look for a change in value the indicates Wink is seeing the table surface and turn her back to the line.

There's no right or wrong way to approach line following. If you find a method that has your bot following a line thats great. Then you end up wondering why it ran off the line or how to get it to run faster or take tighter turns , let your imagination run wild and try lots of things and enjoy it all the way! :)

User avatar
sil
Posts: 40
Joined: Thu Oct 01, 2015 1:04 am

Re: Line Follower Basics Available?

Postby sil » Fri Feb 12, 2016 7:34 am

Sorry, disregard the above. I've been trying to adapt my code but failing, i think i'm not reading the sensors correctly and it seems some command have a different case between ringo and wink, eg Motors() vs motors(). Back to the drawing board for me.

wclift
Posts: 32
Joined: Sun Feb 07, 2016 6:10 am

Re: Line Follower Basics Available?

Postby wclift » Fri Feb 12, 2016 7:41 pm

I got some example Beta code from Kevin, on request. That provided the key information to start playing with. For line following, Wink has four IR light sources and two IR light sensors mounted in an arc across the bottom front edge, with some capacitors placed strategically between. There is an "outer" and an "inner" light source placed on each side of each light sensor...one set on the left and one on the right. You have the ability to turn on either or both sources next to each sensor, and then sample. From some basic testing I did last night, it seems like the light source on each side allows the sensor to see the mat/floor on that side of the sensor better. So, for example, you might enable the outer sensor to detect the approach of a line from the side.

If the line is narrow enough to "straddle", I imagine you can use the sensors on each side, perhaps with the inner lights, to stay straddling the line. And perhaps using the inner lights vs. the outer lights might enable tight following of a narrower or wider line. I haven't had nearly enough time to play!

So, the example code will get you started. But I don't yet know the intended theory of how it was best intended to use this number of light sources and sensors. I believe this will come as Kevin releases more of the line-follower example lessons.

Just as enough taste to get one going, using LOW/HIGH to turn the sources off and on:

Code: Select all

  digitalWrite(LineLeftOuter,LOW);       //make sure all IR light sources are off before we begin
  digitalWrite(LineRightOuter,LOW);
  digitalWrite(LineLeftInner,LOW);                 
  digitalWrite(LineRightInner,LOW);
  delayMicroseconds(100);

  LeftLineSensorValueOff=analogRead(LineSenseLeft);    //ReadLeftLightSensor();
  RightLineSensorValueOff=analogRead(LineSenseRight);


The idea is to turn all the lights off. Then turn a light on, wait 100us, then read the sensor. From there, all the other algorithms apply. You'll need to find a trip threshold, deal with sensor randomness through some averaging, and start thinking about stopping on black, then maybe some proportional motor control, then maybe a PID...someday when I find some time!

User avatar
sil
Posts: 40
Joined: Thu Oct 01, 2015 1:04 am

Re: Line Follower Basics Available?

Postby sil » Sat Feb 13, 2016 3:18 am

Wclift, thanks, been experimenting some more and getting meaningless values to use, looks like i'm just missing the LOW switch.

--------

Ok i've had a play, the pads underneath Wink are dragging too much on my test track but i've modified my Ringo code as simple as i needed to see it work. So its horrible code but works. Feel free to play with it.

BTW, I started my line following coding by using a difference value between the sensor with IR lights on then off, but found its not needed. It makes sense for visible light but IR isnt just a black and white representation of colours . As a photographer i've played with infrared photography in the past and there are challenges to "seeing" the line depending how its made. Anyway if you test the values you might reach the same conclusion. Neither my code nor plumgeeks are the best, there are many ways to achieve the same result, some are dependant on assumptions about the line, i've got more advanced methods just not ready to release them yet. I'm aiming for my bots to explore and line following to be part of that process (think seams of minerals in an exposed surface). Would be interested to see your take on the problem when you get something running :)

I've had success with detection confidence by keeping a running average of each sensor so its not reacting to sensor fluctuations that reflect a false positive or false negative condition, also got an edge detection in there too to stop the bot going over the edge of my track table (um, board on a box). For me optimisation is much later down the track once i had a solid final revision ready. Am looking forward to the WInk lesson on line following, seems it needs a different approach to Ringo i think and better potential for collision detection in the mix. I'd love to end up with a 24hr lemans track with my Winks racing the circuit, have them react to each other on track and turn on headlight when i turn off the lights for the night running. So many possibilities from these critters.

Anyway, here's my quick and very dirty line following code for Wink, for now. Enjoy or ignore :)


Code: Select all

/*


*/

#include "WinkHardware.h"
/* set up hardware */
void setup(){
hardwareBegin(); //initialize Wink's brain to work with his circuitry
playStartChirp(); //Play startup chirp and blink eyes
RestartTimer();
delay(2000); // 2 sec delay before start
}

/* declare variables */
//int leftOn, leftOff, rightOn, rightOff, rearOn, rearOff;
//int leftDiff,rightDiff, rearDiff;
int speedleft, speedright;



void loop(){

digitalWrite(LineLeftOuter,HIGH);
digitalWrite(LineRightOuter,HIGH);


eyesWhite(0);

speedleft = 50;
speedright = 50;

motors(speedleft, speedright);

// use motors() to turn using multiplier

if (analogRead(LineSenseLeft) < 800)
{
leftGreen(50);
rightGreen(0);
motors(speedleft*1.2, speedright*3.5);
}

if (analogRead(LineSenseRight) < 800)
{
rightGreen(50);
leftGreen(0);
motors(speedleft*3.5, speedright*1.2);
}

} //closing curly of the “loop()” function





TKLG13
Posts: 3
Joined: Wed May 02, 2018 3:43 pm

Re: Line Follower Basics Available?

Postby TKLG13 » Thu May 03, 2018 5:07 pm

Thanks for the share. I am going to play with the code to see if I can get it running my little bot.


Who is online

Users browsing this forum: No registered users and 1 guest