Shop OBEX P1 Docs P2 Docs Learn Events
Laser guided BOE bot project — Parallax Forums

Laser guided BOE bot project

ArchiverArchiver Posts: 46,084
edited 2001-10-13 14:42 in General Discussion
As part of a school project, I'm attempting to build a laser guided
pinewood derby car using a BOE bot full kit.

The designator is a normal laser pointer that projects a plane
instead of a beam, and the car is designed such that the two photo
resistors in the kit ride on either side of the beam.

when the beam hits one of the photoresistors, I need the car to steer
away from the resistor, so the beam moves back between the two
sensors.

so far, my program looks like this:

'declaration
left_photo var word
right_photo var word

'init

output 2
freqout 2, 2000, 3000
low 12
low 13

'main
main:

high 3
pause 3
rctime 3,1, right_photo

high 5
pause 3
rctime 5,1,left_photo


pulsout 12, 750 'center servo
pause 100
if abs(left_photo-right_photo) >50 then check_dir 'set dead band
goto main:
check_dir:

if left_photo > right_photo then right_pulse
if left_photo < right_photo then left_pulse

'nav

left_pulse:
pulsout 12, 625
pause 100
gosub update_photo
if left_photo < right_photo then left_pulse
if left_photo > right_photo then right2
goto main

right_pulse:
pulsout 12, 825
pause 100
gosub update_photo
if left_photo > right_photo then right_pulse
if left_photo < right_photo then left2
goto main

left2:
pulsout 12,825
pause 200
goto main

right2:
pulsout 12,625
pause 200
goto main

'----subs


update_photo:
high 3
pause 3
rctime 3,1, right_photo

high 5
pause 3
rctime 5,1,left_photo
return

It doesn't work all that reliably, and it has a tendency to make the
servo lock in either the far right or far left position.

Am i conplately screwing up somewhere?
thanks for the help.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-10-12 05:15
    I'm no expert but I think you will have a problem getting the servo to
    respond well enough with pulsouts spaced at least 100 milliseconds apart.
    try a small for next loop with your pulsouts and put a 20 MS pause in the
    loop. I modified your code a bit. See if it is closer to what you want.

    Original Message
    From: drew_123456@y... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=kHMXEBoV-UjGH2sKPjt9TBpA3rBHZmgAMASQktZpN6K57UHn9n6RfDpdzvKSB_C3lCpG__HPO3MnYytFRQ]drew_123456@y...[/url
    Sent: Thursday, October 11, 2001 11:23 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Laser guided BOE bot project


    As part of a school project, I'm attempting to build a laser guided
    pinewood derby car using a BOE bot full kit.

    The designator is a normal laser pointer that projects a plane
    instead of a beam, and the car is designed such that the two photo
    resistors in the kit ride on either side of the beam.

    when the beam hits one of the photoresistors, I need the car to steer
    away from the resistor, so the beam moves back between the two
    sensors.

    so far, my program looks like this:

    'declaration
    left_photo var word
    right_photo var word
    i var byte
    'init

    output 2
    freqout 2, 2000, 3000
    low 12
    low 13

    'main
    main:

    high 3
    high 5
    pause 3
    rctime 3,1, right_photo3
    rctime 5,1,left_photo

    if abs(left_photo-right_photo) >50 then center_pulse 'set dead band
    if left_photo > right_photo then right_pulse
    if left_photo < right_photo then left_pulse
    goto main

    'nav

    left_pulse:
    for i = 1 to 5
    pulsout 12, 625
    pause 20
    next
    goto main

    right_pulse:
    for i = 1 to 5
    pulsout 12, 825
    pause 20
    next
    goto main

    center_pulse:
    for i = 1 to 5
    pulsout 12, 750 'center servo
    pause 20
    next
    goto main


    It doesn't work all that reliably, and it has a tendency to make the
    servo lock in either the far right or far left position.

    Am i conplately screwing up somewhere?
    thanks for the help.


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-12 05:35
    This version has a state machine to keep you from sending redundant info to
    the servo. (Of course this will not work if the servo wanders when it is not
    receiving commands.) Play with the for next loops to fine tune. Use just
    enough loops to get the steering servo to the correct position.


    'declaration
    left_photo var word
    right_photo var word
    i var byte
    state var nib
    'init

    output 2
    freqout 2, 2000, 3000
    low 12
    low 13

    'main
    main:

    high 3
    high 5
    pause 3
    rctime 3,1, right_photo3
    rctime 5,1,left_photo

    if abs(left_photo-right_photo) >50 and state <>3 then center_pulse 'set dead
    band
    if left_photo > right_photo and state <>2 then right_pulse
    if left_photo < right_photo and state <>1 then left_pulse
    goto main

    'nav

    left_pulse:
    for i = 1 to 5
    pulsout 12, 625
    pause 20
    next
    state = 1
    goto main

    right_pulse:
    for i = 1 to 5
    pulsout 12, 825
    pause 20
    next
    state = 2
    goto main

    center_pulse:
    for i = 1 to 5
    pulsout 12, 750 'center servo
    pause 20
    next
    state = 3
    goto main
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-13 14:42
    Hello Drew,
    Your concept is interesting, but I see a little problem with it: each
    steering correction results in sideways slippage of the wheels and increased
    friction, which will result in the car's velocity being decreased (exactly
    the opposite effect of what you desire). Determining the exact amount of
    steerage to apply is problematic; and you have no way to determine as to
    when the car's steerage is centered.

    Consider this improvement:
    Salvage a small stepper motor from an old 3 1/2" floppy disk drive. (see
    the Basic Stamp I Application Notes, 6:A Serial Stepper Controller). To the
    shaft of the stepper motor, affix a small circular PCB (maybe 1" in
    diameter) on which you've mounted a photoresistor (I'll call this PR1 for
    now) off-center, and cut a radial slot or drilled a small hole opposite the
    photoresistor. Shine a stationary LED through the slot or hole, and mount a
    stationary photoresistor (PR2) on the opposite side of the PCB disk to
    detect the LED through the hole. On the motor side of the PCB, etch or cut
    two circular traces, and fabricate pickups from narrow strips of brass to
    supply sensing lines to PR1.

    The laser designator's beam is projected with the plane in the Y axis
    (vertical), exactly centered on the track. The number of steps per
    revolution of the motor is fixed. PR2 provides a method of determining when
    the disk is in a known position; a synchronization pulse to your Stamp
    program, so to speak. As PR1 travels through it's circular path, your Stamp
    program samples the amount of light detected at each step; if the light is
    strongest when PR1 is at the highest or lowest portion of it's travel (on an
    imaginary vertical line intersecting the center of the motor's shaft), then
    the car's steering should be exactly centered; otherwise your program could
    determine how much and which direction the wheels should be adjusted.

    Using this method provides you with a way of determining the exact amount of
    steerage to be applied to the car's wheels, and will minimize speed losses
    due to friction.

    Hope this helps... on to victory!
    Steve
Sign In or Register to comment.