Halfdone Development
Something of the week

My Better Mindstorm Line Follower

I was recently playing with my mindstorm kit again and thought I would do a quick post about it. Mindstorm are basicly computer controlled Legos. It's expensive at $200 but very neat in a geeky way. One of the main reasons I'm trying to learn electronics is so I connect it to my computer and program it to do stuff. With these legos you can do cool stuff without needing to know electronics.

I've had it for over a year and haven't used it much but I started getting back into it. Biggest issue is that it only comes with two motors and it doesn't come with nearly enough pieces. I resently bought another motor but I still need to pickup a big bucket of legos (I don't have any from my childhood anymore).

One of the simple things you can do (and comes with directions) is a line follower. A wheeled robot just follows a black line on a large piece of paper. the programming for something like this is easier then you would expect. If the light sensor sees dark (the line) then turn right, if it light (no line) turn left. Assuming the line doesn't turn too sharply it will follow the EDGE of the line with a series of continuous left and right turns.

I desided to make it a bit harder in that instead of a simple oval that comes with the kit I make a swiggly line with more curves, some of them pretty sharp, more then the typical turning radius of the bot.

Original Line Path New Line Path

To solve this problem I had to get the bot to compansate with a sharper spin if it wasn't turning fast enough. A Turn just moves one of the wheels while a spin turn the wheels in different directions so it spins in place. The way I solved it was to see see if the bot is stuck on the line too long (more then 0.4 seconds) because it can't turn fast enough it will then do a spin in place for 0.4sec.

The way that you program the PBX Brick (the lego microprocessor) using lego's software is kinda interesting. You drag'n'drop visual lego bricks that do things like spin left, turn right, check sensor, loop, ...etc. It's great for kids and easy to do but it can quickly become a pain if you do anything too complex. For someone like me that is use to writen code it takes some getting use to but the general idea is simular. Instead of IF-THEN-ELSE it has IF-YES-NO. Even does events which doesn't quite work the way you would expect. Here is the "code" for my better line follower:

Line Follower Lego-Style Code

If you look at the actual saved program in notepad you can actually see that it looks like a typical writen program, kinda like C (include statemtents) and some VB (var statements):

program test {
    
    #include <RCX2.h>
    #include <RCX2MLT.h>
    #include <RCX2Sounds.h>
    #include <RCX2Def.h>
    var SpinRight = 0
    event timer1_timer1Event when timer1 > 4
    sensor light2 on 2
    light2 is light as percent
    
    main {
        ext InterfaceType "kRoverBot"
        rcx_ClearTimers
        bbs_GlobalReset([A B C])
        start TimerWatcher0
        rcx_Priority( 8)
        trigger timer1_timer1Event
        SpinRight = 0
        forever {
            if SpinRight = 10{
                clear Timer1
                bb_SpinRight(A, C, 40)
                SpinRight = 0
            }
            else
            {
                if light2 > 44{
                    clear Timer1
                    bb_TurnLeft(A, C, 1)
                }
                else
                {
                    bb_TurnRight(A, C, 1)
                } 
            } 
        }
    }
    
    
    watcher TimerWatcher0 monitor timer1_timer1Event
    {
        rcx_Priority( 8)
        SpinRight = 10
    } restart on event
}
  

Here is a 1.35meg video of the bot following the line. Because I didn't have paint and was using a sharpie to draw the line I only made the line the right thickness where it needed it. I need to pickup some paint. The paper is about 3.5x2 feet.

Line Follower Video (1.35meg, divx 5.11)

Also next time someone remind me to do it on the floor so I don't have to us this camera setup.

Page last modified: June 20th, 2005 - 5:15pm Boston, USA time.