Shop OBEX P1 Docs P2 Docs Learn Events
Need Some Assistance — Parallax Forums

Need Some Assistance

LondonguyLondonguy Posts: 2
edited 2006-04-22 15:43 in BASIC Stamp
Hey all, any help with my program would be greatly appreciated, as i am a beginner with this stuff.

anyways for a college project i am required to build a robot that can follow a track, as well as avoid objects on this track.

What i have used is two IR emitters/recievers and two line tracker sensors.· I was succesfully able to hook up these sensors, and have them read either 0 or 1 depending on the condition.· However when i wrote the movement programming the robot seems to be slow and confused, and does not do as it is required.·· I have thought of programming the robot to re check the sensors after each condition is met, (ie robot moves to avoid sensor) but still the robot.· Does anyone have an sample coding regarding this type of robot?··· also im curious if there is any way to save the last movement, so that if the robot has to move off the track to avoid object(s) thus making the line tracker sensors both "read off the track", then the microprocessor will remember the last movement and be able to return to the track..· Thanks for any help

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-22 15:07
    First of all, if the processor has too many sensor tasks; it will slow the response. A balance must be achieved or a co-processor must offload some of the burden.

    Second, some IR sensors are power hungry and using an array of such will starve the BOT.

    Third, whiskers or bumpers are always a good idea as IR responds differently to different colors and may actually miss some of what you hope for it to see.

    Having said that, it is obvious that we could use more specific information.

    What IR sensors are you using?
    Where are you getting your code for them?

    It may be to your advantage to post the program here.
    Experienced people can then tell you what might improve upon it.

    Cheers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Ken GraceyKen Gracey Posts: 7,387
    edited 2006-04-22 15:18
    Londonguy,

    You can do this all with a BASIC Stamp, without a coprocessor. I suggest you first develop your pseudocode in plain ol' English. For example:

    Generate IR and look for reflection
    Steer the robot towards the line
    Check for obstruction in front of the robot
    If obstruction is encountered, back up, turn
    If no line, drive until line is seen
    Once line is found, center it under sensors

    I think a CASE..SELECT statement could manage most all of your project.

    The problem you are having is likely one of timing. You indicate that the robot is slow; are there DEBUG statements in the code? Are you trying to do everything state-machine style between servo pulses?

    Ken Gracey
  • LondonguyLondonguy Posts: 2
    edited 2006-04-22 15:43
    This is what i have done, its a garbled mess of code that ive scavenged from other parallax projects and programming guide..· as you can see im a beginner lol.· this code is pretty rough, and its probably why im having such a problem gettin the results i want.· Im sure the problem is in the movement code since my sensors seem to be working properly

    '
    [noparse][[/noparse] I/O Definitions ]
    LLinePwr PIN 9 ' left line sensor power
    LLineIn PIN 8 ' left line sensor input
    RLinePwr PIN 7 ' right line sensor power
    RLineIn PIN 6 ' right line sensor input


    '
    Variables

    counter·········· VAR···· Word
    sub_count········ VAR···· Byte
    irdetectleft····· VAR···· Bit
    irdetectright···· VAR···· Bit
    lLine VAR Word ' left sensor raw reading
    rLine VAR Word ' right sensor raw reading
    lineBits VAR Nib ' decoded sensors value
    lbLeft VAR lineBits.BIT1
    lbRight VAR lineBits.BIT0
    '
    Movement Code
    FREQOUT 4, 2000, 3000 ' Signal program start/reset.


    DO
    ·GOSUB Readirsensors·· '0 clear 1 object
    IF (irDetectLeft = 1) AND (irDetectRight = 1) THEN···· ' Both IR pairs detect obstacle
    · GOSUB rev_pulse
    · GOSUB turn_left·································· ' Back up & turn left
    ···································· ' go forward and turn right to
    ··································· 'back on track.
    ELSEIF (irDetectLeft = 1) THEN····················· ' Left IR pair detects
    · GOSUB rev_pulse···································· ' Back up & turn right
    · GOSUB turn_right

    ELSEIF (irDetectRight = 1)· THEN····················· ' Right IR pair detects
    · GOSUB rev_pulse····································· ' Back up & turn left
    · GOSUB turn_left

    ELSE·················································· ' Both IR pairs 1, no detects
    · GOSUB fwd_pulse····································· ' Apply a forward pulse

    ENDIF················································· ' and check again


    GOSUB Readlinesensors······· ' 0 = black, 1 = line
    IF (lbLeft = 1) AND (lbRight = 1) THEN
    · GOSUB turn_right
    · GOSUB fwd_pulse
    ELSEIF (lbLeft = 1) THEN
    · GOSUB turn_right
    ELSEIF (lbRight = 1) THEN
    · GOSUB turn_left
    ELSE
    · GOSUB fwd_pulse
    ENDIF

    LOOP
    '
    sensor subroutines
    ·Readlinesensors:
    HIGH LLinePwr ' activate sensors
    HIGH RLinePwr
    HIGH LLineIn ' discharge caps
    HIGH RLineIn
    PAUSE 1
    RCTIME LLineIn, 1, lLine ' read left sensor
    RCTIME RLineIn, 1, rLine ' read right sensor
    LOW LLinePwr ' deactivate sensors
    LOW RLinePwr
    ' convert readings to bits
    LOOKDOWN lLine, >=[noparse][[/noparse]1000, 0], lbLeft ' 0 = black, 1 = line
    LOOKDOWN rLine, >=[noparse][[/noparse]1000, 0], lbRight
    DEBUG CR, "lbleft = ", BIN1 lbleft
    DEBUG CR, "lbRight =", BIN1 lbRight
    RETURN

    ReadIrsensors:
    FREQOUT 10, 1, 38500
    irDetectLeft = IN11
    DEBUG HOME, "irDetectLeft = ", BIN1 irDetectLeft
    PAUSE 50
    FREQOUT 12, 1, 38500
    irDetectRight = IN13··
    DEBUG CR, "irDetectRight = ", BIN1 irDetectRight
    PAUSE 50
    RETURN
    ·'
    Navigation Subroutines

    fwd_pulse:······ ' forward subroutine
    · FOR counter = 1 TO 50
    · PULSOUT 1, 950
    · PULSOUT 2, 550
    · PAUSE 20
    · NEXT
    RETURN
    rev_pulse:······ ' reverse subroutine
    · FOR counter = 1 TO 50
    · PULSOUT 1, 550
    · PULSOUT 2, 950
    · PAUSE 20
    · NEXT
    RETURN
    turn_right:······ '45 degree Right turn Subroutine
    · FOR counter = 1 TO 45··
    PULSOUT 1, 800
    ·· PAUSE 20
    · NEXT
    RETURN
    turn_left:······· '45 degree left turn subroutine
    FOR counter = 1 TO 45
    · PULSOUT 2, 700
    · PAUSE 20
    · NEXT
    RETURN
Sign In or Register to comment.