Shop OBEX P1 Docs P2 Docs Learn Events
Need help with Line Following and Object Detection — Parallax Forums

Need help with Line Following and Object Detection

ArchiverArchiver Posts: 46,084
edited 2002-07-14 04:04 in General Discussion
Hi...

I got the Line Follower Module for my Boe-bot and it is following a
black line consistently. I need to now incorporate object detection
with the line follower and was wondering how i can do that.
Basically the task i have to do is to have the boe-bot follow a black
line and come upon four spaces that represent parking spaces. now
three of these four spaces will have objects occupying them and the
boe-bot should be able to detect what spaces have objects in them,
avoid those spaces, and follow a black line into the space with no
object in it and park.

i am thinking about either using the Whiskers that i have from
purchasing the Whisker kit to serve as the sensor to detect if the
boe-bot sees a parked car but i'm thinking this might be difficult if
the spaces are pretty close to each other. also i'm considering using
infrared detectors to detect objects if the parked cars are farther
away from the boe-bot. my question is which would be the best and
easiest to go with? i have no experience programming the BS2 and want
to keep it as simple as possible and incorporate the code to do the
object detection into the code i got when i purchased the Line
Follower module. i've looked at some code that came with the Whiskers
kit called Whisker.bs2 and some in the Robotics manual for use with
infrared and am confused.

what code would you suggest i use? and where in the line follower code
would i put it so that it could handle both needs? I've tried
contacting the Tech Support at Parallax, but they just tell me to look
at the manual that came with the boe-bot kit and obviously i've
already looked at it before i asked. them. I need specifics!

here's the code i'm using now to follow the black line and i want to
put the object detection code into here to run the boe-bot for both
capabilities:

' { $STAMP BS2 }


'
[noparse][[/noparse] Program Description
]
'
' This program is designed to run line follower
contests where the
BOE-Bot will
' start and stop on a "T" in the track. It implements
a controlled
start feature
' using the BOE Reset button. Pressing the Reset
button starts the
BOE-Bot.


'
[noparse][[/noparse] Revision History
]
'
' 01 DEC 2001 - Version 1.0


'
[noparse][[/noparse] I/O Definitions

]
'
LMotor CON 13 ' servo motor connections
RMotor CON 12


'
[noparse][[/noparse] Constants

]
'
LEDon CON 0 ' LF LEDs are active low
LEDoff CON 1

WLine CON 0 ' white line on black
field
BLine CON 1 ' black line on white
field
LFmode CON BLine ' set pgm for black line

MStop CON 750 ' motor stop
LSpeed100 CON 180 ' full speed
RSpeed100 CON 245
Speed075 CON 75 ' three-quarter speed
Speed050 CON 40 ' half speed

Yes CON 1
No CON 0


'
[noparse][[/noparse] Variables

]
'
temp VAR Byte
ledPos VAR Nib ' LED position in lfBits
lfBits VAR Byte ' line follower input bits
lastBits VAR Byte ' last LF input
steer VAR Nib ' steering control
onCourse VAR Bit ' on course flag


'
[noparse][[/noparse] EEPROM Data

]
'
RstValue DATA $FF ' $FF = no run


'
[noparse][[/noparse] Initialization

]
'
Run_Check:
READ RstValue, temp ' get reset value
temp = ~temp ' invert bits
WRITE RstValue, temp ' write inverted bits back
IF (temp) THEN Initialize ' run if inverted > 0

No_Run:
END ' low power mode

Initialize:
PAUSE 500 ' allow hand to release
OutL = %01111100 ' all LF LEDs off
DirL = %01111100 ' make pins outputs

lastBits = %00100 ' assume straight
onCourse = No ' we haven't run course yet


'
[noparse][[/noparse] Main Code

]
'
Main:
GOSUB Read_Line_Follower ' read the Line Follower
IF (lfBits <> %00100) THEN Check_End ' check for
middle sensor
onCourse = Yes ' -- has been on the course

Check_End:
IF (lfBits <> %11111) THEN Steer_Robot ' keep steering
if not at
end
IF (onCourse = No) THEN Straight ' still at start
IF (lastBits <> %00000 ) THEN At_End ' verify end of
course

Steer_Robot:
steer = NCD lfBits ' get highest "on" bit
BRANCH steer,[noparse][[/noparse]Off_Line, Hard_Right, Right, Straight,
Left, Hard_Left]

Save_Last:
lastBits = lfBits ' save last reading
GOTO Main

At_End:
PULSOUT LMotor, MStop ' stop motors
PULSOUT RMotor, MStop
Dirs = 0 ' turn off outputs
WRITE RstValue, 0 ' run again after Reset press
END


'
[noparse][[/noparse] Subroutines

]
'
Read_Line_Follower:
lfBits = 0 ' clear last reading
FOR ledPos = 2 TO 6
OutL.LowBit(ledPos) = LEDon ' turn the LED on
PAUSE 1 ' allow sensor to read
lfBits.LowBit(ledPos) = In9 ^ LFmode ' record the
sensor reading
OutL = OutL | %01111100 ' turn LEDs off
NEXT
lfBits = lfBits >> 2 ' shift bits to zero
index
RETURN


Off_Line:
lfBits = lastBits ' get last known position
GOTO Steer_Robot


Hard_Right:
PULSOUT LMotor, MStop + Speed075 ' full speed on left
PULSOUT RMotor, MStop ' reverse right motor
GOTO Save_Last


Right:
PULSOUT LMotor, MStop + LSpeed100 'full speed on left
PULSOUT RMotor, MStop - Speed050
GOTO Save_Last


Straight:
PULSOUT LMotor, MStop + LSpeed100 'both motors forward
PULSOUT RMotor, MStop - RSpeed100
GOTO Save_Last


Left:
PULSOUT LMotor, MStop + Speed050
PULSOUT RMotor, MStop - RSpeed100 'full speed on right
GOTO Save_Last


Hard_Left:
PULSOUT LMotor, MStop ' reverse left motor
PULSOUT RMotor, MStop - Speed075 ' full speed on right
GOTO Save_Last


Please help. I need to get this going asap. Thanks.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-07-14 04:04
    bump

    please help if you know how to do this. i need to get this
    going asap. thanks.


    --- In basicstamps@y..., "idlereason" <idlereason@y...> wrote:
    > Hi...
    >
    > I got the Line Follower Module for my Boe-bot and it is following a

    > black line consistently. I need to now incorporate object detection
    > with the line follower and was wondering how i can do that.
    > Basically the task i have to do is to have the boe-bot follow a
    black
    > line and come upon four spaces that represent parking spaces. now
    > three of these four spaces will have objects occupying them and the
    > boe-bot should be able to detect what spaces have objects in them,
    > avoid those spaces, and follow a black line into the space with no
    > object in it and park.
    >
    > i am thinking about either using the Whiskers that i have from
    > purchasing the Whisker kit to serve as the sensor to detect if the
    > boe-bot sees a parked car but i'm thinking this might be difficult
    if
    > the spaces are pretty close to each other. also i'm considering
    using
    > infrared detectors to detect objects if the parked cars are farther
    > away from the boe-bot. my question is which would be the best and
    > easiest to go with? i have no experience programming the BS2 and
    want
    > to keep it as simple as possible and incorporate the code to do the
    > object detection into the code i got when i purchased the Line
    > Follower module. i've looked at some code that came with the
    Whiskers
    > kit called Whisker.bs2 and some in the Robotics manual for use with
    > infrared and am confused.
    >
    > what code would you suggest i use? and where in the line follower
    code
    > would i put it so that it could handle both needs? I've tried
    > contacting the Tech Support at Parallax, but they just tell me to
    look
    > at the manual that came with the boe-bot kit and obviously i've
    > already looked at it before i asked. them. I need specifics!
    >
    > here's the code i'm using now to follow the black line and i want to
    > put the object detection code into here to run the boe-bot for both
    > capabilities:
    >
    > ' { $STAMP BS2 }
    >
    >
    > '
    [noparse][[/noparse] Program Description
    > ]
    > '
    > ' This program is designed to run line follower
    > contests where the
    > BOE-Bot will
    > ' start and stop on a "T" in the track. It
    implements
    > a controlled
    > start feature
    > ' using the BOE Reset button. Pressing the Reset
    > button starts the
    > BOE-Bot.
    >
    >
    > '
    [noparse][[/noparse] Revision History
    >
    ]
    > '
    > ' 01 DEC 2001 - Version 1.0
    >
    >
    > '
    [noparse][[/noparse] I/O Definitions
    >
    > ]
    > '
    > LMotor CON 13 ' servo motor connections
    > RMotor CON 12
    >
    >
    > '
    [noparse][[/noparse] Constants
    >
    > ]
    > '
    > LEDon CON 0 ' LF LEDs are active low
    > LEDoff CON 1
    >
    > WLine CON 0 ' white line on black
    > field
    > BLine CON 1 ' black line on white
    > field
    > LFmode CON BLine ' set pgm for black line
    >
    > MStop CON 750 ' motor stop
    > LSpeed100 CON 180 ' full speed
    > RSpeed100 CON 245
    > Speed075 CON 75 ' three-quarter speed
    > Speed050 CON 40 ' half speed
    >
    > Yes CON 1
    > No CON 0
    >
    >
    > '
    [noparse][[/noparse] Variables
    >
    > ]
    > '
    > temp VAR Byte
    > ledPos VAR Nib ' LED position in lfBits
    > lfBits VAR Byte ' line follower input bits
    > lastBits VAR Byte ' last LF input
    > steer VAR Nib ' steering control
    > onCourse VAR Bit ' on course flag
    >
    >
    > '
    [noparse][[/noparse] EEPROM Data
    >
    > ]
    > '
    > RstValue DATA $FF ' $FF = no run
    >
    >
    > '
    [noparse][[/noparse] Initialization
    >
    > ]
    > '
    > Run_Check:
    > READ RstValue, temp ' get reset value
    > temp = ~temp ' invert bits
    > WRITE RstValue, temp ' write inverted bits back
    > IF (temp) THEN Initialize ' run if inverted > 0
    >
    > No_Run:
    > END ' low power mode
    >
    > Initialize:
    > PAUSE 500 ' allow hand to release
    > OutL = %01111100 ' all LF LEDs off
    > DirL = %01111100 ' make pins outputs
    >
    > lastBits = %00100 ' assume straight
    > onCourse = No ' we haven't run course yet
    >
    >
    > '
    [noparse][[/noparse] Main Code
    >
    > ]
    > '
    > Main:
    > GOSUB Read_Line_Follower ' read the Line Follower
    > IF (lfBits <> %00100) THEN Check_End ' check for
    > middle sensor
    > onCourse = Yes ' -- has been on the course
    >
    > Check_End:
    > IF (lfBits <> %11111) THEN Steer_Robot ' keep
    steering
    > if not at
    > end
    > IF (onCourse = No) THEN Straight ' still at start
    > IF (lastBits <> %00000 ) THEN At_End ' verify end of
    > course
    >
    > Steer_Robot:
    > steer = NCD lfBits ' get highest "on" bit
    > BRANCH steer,[noparse][[/noparse]Off_Line, Hard_Right, Right, Straight,
    > Left, Hard_Left]
    >
    > Save_Last:
    > lastBits = lfBits ' save last reading
    > GOTO Main
    >
    > At_End:
    > PULSOUT LMotor, MStop ' stop motors
    > PULSOUT RMotor, MStop
    > Dirs = 0 ' turn off outputs
    > WRITE RstValue, 0 ' run again after Reset press
    > END
    >
    >
    > '
    [noparse][[/noparse] Subroutines
    >
    > ]
    > '
    > Read_Line_Follower:
    > lfBits = 0 ' clear last reading
    > FOR ledPos = 2 TO 6
    > OutL.LowBit(ledPos) = LEDon ' turn the LED on
    > PAUSE 1 ' allow sensor to read
    > lfBits.LowBit(ledPos) = In9 ^ LFmode ' record the
    > sensor reading
    > OutL = OutL | %01111100 ' turn LEDs off
    > NEXT
    > lfBits = lfBits >> 2 ' shift bits to zero
    > index
    > RETURN
    >
    >
    > Off_Line:
    > lfBits = lastBits ' get last known position
    > GOTO Steer_Robot
    >
    >
    > Hard_Right:
    > PULSOUT LMotor, MStop + Speed075 ' full speed on
    left
    > PULSOUT RMotor, MStop ' reverse right motor
    > GOTO Save_Last
    >
    >
    > Right:
    > PULSOUT LMotor, MStop + LSpeed100 'full speed on
    left
    > PULSOUT RMotor, MStop - Speed050
    > GOTO Save_Last
    >
    >
    > Straight:
    > PULSOUT LMotor, MStop + LSpeed100 'both motors
    forward
    > PULSOUT RMotor, MStop - RSpeed100
    > GOTO Save_Last
    >
    >
    > Left:
    > PULSOUT LMotor, MStop + Speed050
    > PULSOUT RMotor, MStop - RSpeed100 'full speed on
    right
    > GOTO Save_Last
    >
    >
    > Hard_Left:
    > PULSOUT LMotor, MStop ' reverse left motor
    > PULSOUT RMotor, MStop - Speed075 ' full speed on
    right
    > GOTO Save_Last
    >
    >
    > Please help. I need to get this going asap. Thanks.
Sign In or Register to comment.