Shop OBEX P1 Docs P2 Docs Learn Events
RedEye: A linescan imager-based BOE-Bot line follower — Parallax Forums

RedEye: A linescan imager-based BOE-Bot line follower

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2013-02-28 06:34 in Robotics
The Parallax/TAOS TSL1401-DB is a vision sensor that sees in one dimension using a 128x1 array of light sensors, along with an imaging lens. It is an ideal sensor to use for line following robots, because its positional resolution is so fine. This project shows how to implement the TSL1401-DB for line following using a BOE-Bot as the robotic platform.

For this project, you will need the following: Prepare the two LEDs as shown below. Trim and insert the two unconnected leads into the TSL1401's top mezzanine connector, according to the pin callouts in the photo:

attachment.php?attachmentid=65429

Next, mount the TSL1401-DB to the BOE-Bot using the L-shaped brackets and standoffs, as shown in the photos below:

attachment.php?attachmentid=65430

attachment.php?attachmentid=65431

Then, plug the DB-Expander into the solderless breadboard and wire to Vdd, Vss, and P0-P3 as shown here:

attachment.php?attachmentid=65432

Here's a chart to summarize the connections (DB-Expander pinouts -> BOE pinouts):
  • +5V -> Vdd
  • Vdd -> Vdd
  • A -> P0
  • B -> P1
  • C -> P2
  • D -> P3 (IMPORTANT: Make this connection with a 75-ohm resistor, not with the blue wire shown in the photo.)
  • Gnd -> Vss
Connect the TSL1401-DB and DB-Expander together using the DB extension cable.

Plug the ServoPAL into servo headers 12-13. Connect the right-hand servo to the forward ServoPAL header; the left-hand servo, to the rear ServoPAL header.

Now, enter the tsl1401_follower.BS2 program (attached below) into your BASIC Stamp II. Before running this code to follow a line, flip the BOE-Bot's power switch momentarily into the #2 position, then back to #1. You should see the LEDs flashing on and off. Position the BOE Bot over a white sheet of paper, and adjust the LEDs so that they illuminate a wide swath directly under the TSL1401-DB's lens as evenly as possible.

Now you're ready to try line following. I used 1/2" flat black crepe masking tape available from McMaster-Carr (#76265A41). 3/4" electrical tape may also work, but you should adjust the line constant to 16 for best results. Lay out a track on light-colored flooring, and give it a whirl. You can view a video of my results here:

····www.phipi.com/redeye/redeye_video.wmv

(NOTE: Because of the low frame rate, the constant flashing of the LEDs looks rather more sporadic in the video. Also note that the patterned floor does not affect performance.)

-Phil

Post Edited (Phil Pilgrim (PhiPi)) : 5/28/2010 5:26:03 AM GMT
606 x 685 - 93K
600 x 533 - 43K
755 x 561 - 63K
695 x 472 - 76K

Comments

  • WhitWhit Posts: 4,191
    edited 2009-11-29 13:43
    Cool project Phil! Thanks for posting this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Whit+


    "We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney
  • Let's Go!Let's Go! Posts: 124
    edited 2009-12-07 14:40
    phil,

    thanks for sharing the really great information and illustration.

    jim

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The smarter I get, the more I understand I don't know!
  • PIRISPIRIS Posts: 5
    edited 2010-06-10 00:36
    Hi! thanks for the project.

    Could you expliain the algorithm used to detect the line?

    I'm using this sensor with a freescale microcontroller but I don't know how to detect the line.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-10 01:51
    Each pixel will either be bright (1) or dark(0). Say you're looking at a light-colored line on a dark background. The line will correspond to the "1" pixels in the field of view. The center (i.e. average) position of the line in the field of view will be the average of all those pixel positions corresponding to "1" pixels. That's what the subroutine AvgPix in the attached PBASIC program computes.

    -Phil
  • ratronicratronic Posts: 1,451
    edited 2010-06-10 02:52
    Phil, can I ask where you got those cool tires for your bot, and I'm going to try this with with my 1401 line sensor on my propeller powered boe bot.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-10 03:26
    Dave,

    Regarding the "tires": those are actually rubber lens focus rings that I got years ago from Universe Kogaku. With a bit of stretching, they fit the BOE Bot wheels perfectly, although there is some lateral slippage. I really ought to glue them on.

    -Phil
  • ratronicratronic Posts: 1,451
    edited 2010-06-10 03:29
    Ok, thanks Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • PIRISPIRIS Posts: 5
    edited 2010-06-15 02:45
    Thanks Bill!, I'm not familiar with PBASIC but, basically what you do is the following:

    1. Read each pixel from sensor and then you use the A/D converter of the microcontroller and storage the information (1 or 0) in an array.
    2. Compute the average (this part is sort of confusing????)
    3. Accomplish a control action.

    I'm sorry I'm a newbie but, I will appreciate your help. Thanks.
  • PIRISPIRIS Posts: 5
    edited 2010-06-15 17:09
    Can I ask what are the SI and clock frequencies?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-15 17:30
    The period between SIs is dependent on the exposure time. For CLK, according to the PBASIC manual, it's 16KHz (i.e. the SHIFTOUT frequency).

    -Phil
  • PIRISPIRIS Posts: 5
    edited 2010-07-03 19:35
    Hi! again I've attached a 10ms SI signal and a 60us CLK signal for continuous imaging but so far I don't have any output signal. What do you think it's going on??
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-07-03 20:16
    I'm not sure what you mean by that. Please post your entire program.

    -Phil
  • edited 2010-09-16 09:27
    Hi, I have ordered couple of TSL1401 cameras to be used for a line scan robot. I have problem figuring out the timing diagram. how do u set exposure. and how is the device initiated. thank you.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-09-16 10:49
    That information is given in the TSL1401R-LF datasheet, which you can download here:

    http://www.taosinc.com/Productfamily.aspx?id=3&SD=lsa

    -Phil
  • sweetlyphesweetlyphe Posts: 4
    edited 2011-11-03 17:21
    hey guys im a noob and was wondering how i could get the camera to switch from dark/light to light/dark. any help is appreciated.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-11-03 19:20
    Simple. In the code there's a line which reads:
    which    CON DARK       
    

    Change it to read:
    which    CON LIGHT
    

    -Phil
  • sweetlyphesweetlyphe Posts: 4
    edited 2011-11-30 17:46
    Thanks, i should have specified in my post that i was trying to figure out how to break the program up to be able to follow a dark line, then switch to follow a light line. I've figured that part out and now im trying to see how fast i can get it to go using the stock servos. i'v made some 4.75" wheels and some 8" wheels. i cannot get it to follow the track smoothly and if it get even the littlest bit off it just gets confused and either goes in circles or drives off the track. Ive tried to adjust all the values in the program to get try and tell the servos to turn less because it seems that when the program tells the servo-pal to correct according to the pixle average and the larger wheel diameter is over correcting the boe bot. Do you have any ideas on how i can either gain more speed with the stock wheels/ servos or what i need to adjust in the program to be able to use the larger wheels. Also, if i got some high speed continuous servos, would the "stock" program still work correctly? If you would like i can upload the program for you to look at....

    Any advice is appreciated

    Thanks
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-11-30 18:22
    The forward speed of any line-following robot will be limited by the response time of the sensor and of the microcontroller that does the sensing and control. Trying to move too quickly will cause the bot to overrun its sensing capability and to lose track of its position relative to the line it's supposed to be following. You may well be hitting a hard speed limit.

    -Phil
  • sweetlyphesweetlyphe Posts: 4
    edited 2011-11-30 19:22
    but there must be a way to change the values to make the servos function at full speed?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-11-30 19:55
    Sure, the servos could run faster. But if they did, they would overrun the sensor's ability to track the line. There's only so much the BASIC Stamp can do, given it's processing constraints and the time required to sense the line and compute a timely response.

    -Phil
  • sweetlyphesweetlyphe Posts: 4
    edited 2011-12-08 17:10
    Phil,

    Hey man i got another question for you. So im trying to get the bot to follow a black line on a white board, and then switching to a white line on a black board. I have the program broken down to make the bot do that. now i trying to get the bot to follow the black/white line, then using a whisker to sense a barrier that will in turn control a seesaw mechanism. i think i need to rework the program because i cannot figure out how to get the bot to stop line scanning/moving to do the other operation. I also am wondering if the speed is being held back because the program is constantly checking if it needs to run the white on black or black on white line scan. i think i need to figure out how to change the WHICH CON LIGHT to WHICH CON DARK depending on the CNT variable. Not only do i want the bot to be able to change from dark line on white background to black line on dark program, but i also want to have other mechanical operations during the line scan. let me know what you think..

    thanks
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-10 18:14
    So the past couple of weeks I've been playing around with the TSL1401 and the Propeller BOE. So it's only natural that I revisit an existing project and update it for the Propeller BOE. Here's Phil's Red Eye linescan BOE-Bot reborn as Green Eye linescan Propeller BOE

    Here's the source code and the BS2 functions used in the port of Phil's code:

    tsl1401_follower.spin
    BS2_Functions.spin

    When porting PBasic watch out for the order of operations and the operators >= and <=. Holy smoke did that cost me some time.
  • leroyvleroyv Posts: 1
    edited 2013-02-27 23:04
    Hello,

    I’m a real newbie and I want to understand the code on the first page,

    You set the constant line on a ½” but how do you get to that number?
    You shift 22 >> 1 so that means 11 = ½” en above the program you said 16 = ¾”
    But how do you get to the these numbers?
    22? 11= ½” and 16=3/4”.

    If there is someone who can answer this question I would be great full.


    Leroy
  • Martin_HMartin_H Posts: 4,051
    edited 2013-02-28 06:34
    Phil wrote the PBasic code, but I reverse engineered it for the Spin port. The line width constant is related to the camera field of view and how high it is mounted above the ground. I imagine Phil just measured the line width to determine the value. I did the same and I measured my tape at 17 pixels wide at the mounting height.
  • ercoerco Posts: 20,253
    @PhiPi This is an AWESOME thread and project. My first time seeing. Don't know how I missed it since it has been brought up several times.

    But I do know exactly how I missed your original November 2009 post. My twins were born October 2009 and I was a sleep-deprived zombie for a year. :)

    Really neat. I'm about to use this sensor for the first time and your fine work is an excellent starting place, much obliged. This padawan has much to learn from Jedi PhiPi. Unlearn the relay ways I have learned, I must.
  • Thanks for bringing this thread to the top. Now I need to dig out my TSL1401 and redo this project or a similar project with another robot. I spent a whole hour last night working on robots, so there's hope.
    erco wrote: »
    But I do know exactly how I missed your original November 2009 post. My twins were born October 2009 and I was a sleep-deprived zombie for a year. :)

    In my case my kids were born in 2000 and 2002, but only 22 months apart. So my wife and I spent almost three years as sleep-deprived zombies. I really don't remember anything between 2000 to 2003.
  • ercoerco Posts: 20,253
    Good to hear, Boss! You're back, along with Amanda and Duane. Let us tremble these walls!
Sign In or Register to comment.