Shop OBEX P1 Docs P2 Docs Learn Events
SRF04 troubles — Parallax Forums

SRF04 troubles

ArchiverArchiver Posts: 46,084
edited 2004-02-09 22:42 in General Discussion
Hello all. I'm using 3 SRF04s for avoidance on my trinity robot.

Here is my code:

'{$STAMP BS2}

'''To get to first room
'Variables======================================================================\
===============================
l_dist VAR Word 'Variable for left srf04 reading
r_dist VAR Word 'Variable for right srf04 reading
f_dist VAR Word 'Variable for front srf04 reading
a VAR Word 'Counter for servos


'Navigation=====================================================================\
===============================
Firsthall: 'hall one for the maze
(fire-fighting)
GOSUB checksensors
IF f_dist < 580 THEN left1
IF l_dist < 290 THEN radjust1
IF r_dist < 290 THEN ladjust1
GOSUB forward
GOTO firsthall

radjust1:
GOSUB radjust
GOTO Firsthall

ladjust1:
GOSUB ladjust
GOTO Firsthall

left1:
GOSUB left

halltodoor1:
GOSUB checksensors
IF f_dist < 1450 THEN left2
IF l_dist < 290 THEN radjust2
IF r_dist < 290 THEN ladjust2
GOSUB forward
GOTO halltodoor1

radjust2:
GOSUB radjust
GOTO halltodoor1

ladjust2:
GOSUB ladjust
GOTO halltodoor1

left2:
GOSUB left

intoroom1:
GOSUB checksensors
IF f_dist < 3190 THEN checkforfire
IF l_dist < 290 THEN radjust3
IF r_dist < 290 THEN ladjust3
GOSUB forward
GOTO intoroom1

radjust3:
GOSUB radjust
GOTO intoroom1

ladjust3:
GOSUB ladjust
GOTO intoroom1

checkforfire:
STOP 'normally send to hamamatsu subroutine

'Subroutines====================================================================\
===============================

checksensors:
PULSOUT 0,5 'front srf04 is P0
OUTPUT 0 'delay
RCTIME 0,1,f_dist 'store value in f_dist

PULSOUT 1,5 'left srf04 is P1
OUTPUT 1 'delay
RCTIME 1,1,l_dist 'store value in l_dist

PULSOUT 2,5 'right srf04 is P2
OUTPUT 2 'delay
RCTIME 2,1,r_dist 'store value in r_dist
return


forward:
FOR a = 1 TO 10
PULSOUT 12,1000
PULSOUT 13,500
PAUSE 10
next
return

left:
FOR a = 1 TO 20
PULSOUT 12,500
PULSOUT 13,500
PAUSE 10
next
return

right:
FOR a = 1 TO 20
PULSOUT 12,1000
PULSOUT 13,1000
PAUSE 10
next
return

ladjust:
FOR a = 1 TO 6
PULSOUT 12,800
PULSOUT 13,500
PAUSE 10
next
return

radjust:
FOR a = 1 TO 6
PULSOUT 12,1000
PULSOUT 13,700
PAUSE 10
next
return

end

Here is my problem. the code works fine. It takes too long to execute. The robot
stops each time it needs to check the sensors. Is there anyway I can eliminate
this? Can I shorten my code? All help is greatly appreciated. Thank you.

John Baker



Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online

[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-02-08 21:33
    You have a lot of 'Pause 10' lines
    in your subroutines.

    You could remove the 'Pause 10' from
    your subroutines -- move the pauses into
    your 'main' loop, and use some of that
    time to check your sensors.

    --- In basicstamps@yahoogroups.com, John Baker
    <johnbaker_erie_pa@y...> wrote:
    >
    > Hello all. I'm using 3 SRF04s for avoidance on my trinity robot.
    >
    > Here is my code:
    >
    > '{$STAMP BS2}
    >
    > '''To get to first room
    > 'Variables==========================================================
    ===========================================

    > l_dist VAR Word 'Variable for left srf04 reading
    > r_dist VAR Word 'Variable for right srf04 reading
    > f_dist VAR Word 'Variable for front srf04 reading
    > a VAR Word 'Counter for servos
    >
    >
    > 'Navigation=========================================================
    ===========================================

    > Firsthall: 'hall one for the maze
    (fire-fighting)
    > GOSUB checksensors
    > IF f_dist < 580 THEN left1
    > IF l_dist < 290 THEN radjust1
    > IF r_dist < 290 THEN ladjust1
    > GOSUB forward
    > GOTO firsthall
    >
    > radjust1:
    > GOSUB radjust
    > GOTO Firsthall
    >
    > ladjust1:
    > GOSUB ladjust
    > GOTO Firsthall
    >
    > left1:
    > GOSUB left
    >
    > halltodoor1:
    > GOSUB checksensors
    > IF f_dist < 1450 THEN left2
    > IF l_dist < 290 THEN radjust2
    > IF r_dist < 290 THEN ladjust2
    > GOSUB forward
    > GOTO halltodoor1
    >
    > radjust2:
    > GOSUB radjust
    > GOTO halltodoor1
    >
    > ladjust2:
    > GOSUB ladjust
    > GOTO halltodoor1
    >
    > left2:
    > GOSUB left
    >
    > intoroom1:
    > GOSUB checksensors
    > IF f_dist < 3190 THEN checkforfire
    > IF l_dist < 290 THEN radjust3
    > IF r_dist < 290 THEN ladjust3
    > GOSUB forward
    > GOTO intoroom1
    >
    > radjust3:
    > GOSUB radjust
    > GOTO intoroom1
    >
    > ladjust3:
    > GOSUB ladjust
    > GOTO intoroom1
    >
    > checkforfire:
    > STOP 'normally send to hamamatsu subroutine
    >
    > 'Subroutines========================================================
    ===========================================

    >
    > checksensors:
    > PULSOUT 0,5 'front srf04 is P0
    > OUTPUT 0 'delay
    > RCTIME 0,1,f_dist 'store value in f_dist
    >
    > PULSOUT 1,5 'left srf04 is P1
    > OUTPUT 1 'delay
    > RCTIME 1,1,l_dist 'store value in l_dist
    >
    > PULSOUT 2,5 'right srf04 is P2
    > OUTPUT 2 'delay
    > RCTIME 2,1,r_dist 'store value in r_dist
    > return
    >
    >
    > forward:
    > FOR a = 1 TO 10
    > PULSOUT 12,1000
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > left:
    > FOR a = 1 TO 20
    > PULSOUT 12,500
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > right:
    > FOR a = 1 TO 20
    > PULSOUT 12,1000
    > PULSOUT 13,1000
    > PAUSE 10
    > next
    > return
    >
    > ladjust:
    > FOR a = 1 TO 6
    > PULSOUT 12,800
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > radjust:
    > FOR a = 1 TO 6
    > PULSOUT 12,1000
    > PULSOUT 13,700
    > PAUSE 10
    > next
    > return
    >
    > end
    >
    > Here is my problem. the code works fine. It takes too long to
    execute. The robot stops each time it needs to check the sensors. Is
    there anyway I can eliminate this? Can I shorten my code? All help is
    greatly appreciated. Thank you.
    >
    > John Baker
    >
    >
    >
    >
    > Do you Yahoo!?
    > Yahoo! Finance: Get your refund fast by filing online
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-09 00:12
    Allan, when I remove the pauses, my servos act up. They have unpredictable
    behavior. I'm using standard modified servos. Where else would I put these
    pauses? Are you suggesting that I put one pause 10 in each "main" loop? Also, I
    read somewhere about a serial servo controller. Would it be faster to just
    "serout" a command, and use the rest of the code the way it is? Thank you for
    your time.

    Allan Lane <allan.lane@h...> wrote:You have a lot of 'Pause 10'
    lines
    in your subroutines.

    You could remove the 'Pause 10' from
    your subroutines -- move the pauses into
    your 'main' loop, and use some of that
    time to check your sensors.

    --- In basicstamps@yahoogroups.com, John Baker
    wrote:
    >
    > Hello all. I'm using 3 SRF04s for avoidance on my trinity robot.
    >
    > Here is my code:
    >
    > '{$STAMP BS2}
    >
    > '''To get to first room
    > 'Variables==========================================================
    ===========================================

    > l_dist VAR Word 'Variable for left srf04 reading
    > r_dist VAR Word 'Variable for right srf04 reading
    > f_dist VAR Word 'Variable for front srf04 reading
    > a VAR Word 'Counter for servos
    >
    >
    > 'Navigation=========================================================
    ===========================================

    > Firsthall: 'hall one for the maze
    (fire-fighting)
    > GOSUB checksensors
    > IF f_dist < 580 THEN left1
    > IF l_dist < 290 THEN radjust1
    > IF r_dist < 290 THEN ladjust1
    > GOSUB forward
    > GOTO firsthall
    >
    > radjust1:
    > GOSUB radjust
    > GOTO Firsthall
    >
    > ladjust1:
    > GOSUB ladjust
    > GOTO Firsthall
    >
    > left1:
    > GOSUB left
    >
    > halltodoor1:
    > GOSUB checksensors
    > IF f_dist < 1450 THEN left2
    > IF l_dist < 290 THEN radjust2
    > IF r_dist < 290 THEN ladjust2
    > GOSUB forward
    > GOTO halltodoor1
    >
    > radjust2:
    > GOSUB radjust
    > GOTO halltodoor1
    >
    > ladjust2:
    > GOSUB ladjust
    > GOTO halltodoor1
    >
    > left2:
    > GOSUB left
    >
    > intoroom1:
    > GOSUB checksensors
    > IF f_dist < 3190 THEN checkforfire
    > IF l_dist < 290 THEN radjust3
    > IF r_dist < 290 THEN ladjust3
    > GOSUB forward
    > GOTO intoroom1
    >
    > radjust3:
    > GOSUB radjust
    > GOTO intoroom1
    >
    > ladjust3:
    > GOSUB ladjust
    > GOTO intoroom1
    >
    > checkforfire:
    > STOP 'normally send to hamamatsu subroutine
    >
    > 'Subroutines========================================================
    ===========================================

    >
    > checksensors:
    > PULSOUT 0,5 'front srf04 is P0
    > OUTPUT 0 'delay
    > RCTIME 0,1,f_dist 'store value in f_dist
    >
    > PULSOUT 1,5 'left srf04 is P1
    > OUTPUT 1 'delay
    > RCTIME 1,1,l_dist 'store value in l_dist
    >
    > PULSOUT 2,5 'right srf04 is P2
    > OUTPUT 2 'delay
    > RCTIME 2,1,r_dist 'store value in r_dist
    > return
    >
    >
    > forward:
    > FOR a = 1 TO 10
    > PULSOUT 12,1000
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > left:
    > FOR a = 1 TO 20
    > PULSOUT 12,500
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > right:
    > FOR a = 1 TO 20
    > PULSOUT 12,1000
    > PULSOUT 13,1000
    > PAUSE 10
    > next
    > return
    >
    > ladjust:
    > FOR a = 1 TO 6
    > PULSOUT 12,800
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > radjust:
    > FOR a = 1 TO 6
    > PULSOUT 12,1000
    > PULSOUT 13,700
    > PAUSE 10
    > next
    > return
    >
    > end
    >
    > Here is my problem. the code works fine. It takes too long to
    execute. The robot stops each time it needs to check the sensors. Is
    there anyway I can eliminate this? Can I shorten my code? All help is
    greatly appreciated. Thank you.
    >
    > John Baker
    >
    >
    >
    >
    > Do you Yahoo!?
    > Yahoo! Finance: Get your refund fast by filing online
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]



    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.

    Yahoo! Groups Links







    Do you Yahoo!?
    Yahoo! Finance: Get your refund fast by filing online

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-09 00:44
    A serial controller would defintaly help. It's free the stamp up from
    having to deal with the servos directly and you wouldn't need any of those
    pauses. Scott Edwards makes a pretty good one that'll handle up to 8 servos
    from one board and can be daisy chained to control more.
    http://www.seetron.com/

    Chris Shuster

    Original Message
    From: "John Baker" <johnbaker_erie_pa@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, February 08, 2004 5:12 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Re: SRF04 troubles


    > Allan, when I remove the pauses, my servos act up. They have unpredictable
    behavior. I'm using standard modified servos. Where else would I put these
    pauses? Are you suggesting that I put one pause 10 in each "main" loop?
    Also, I read somewhere about a serial servo controller. Would it be faster
    to just "serout" a command, and use the rest of the code the way it is?
    Thank you for your time.
    >
    > Allan Lane <allan.lane@h...> wrote:You have a lot of 'Pause
    10' lines
    > in your subroutines.
    >
    > You could remove the 'Pause 10' from
    > your subroutines -- move the pauses into
    > your 'main' loop, and use some of that
    > time to check your sensors.
    >
    > --- In basicstamps@yahoogroups.com, John Baker
    > wrote:
    > >
    > > Hello all. I'm using 3 SRF04s for avoidance on my trinity robot.
    > >
    > > Here is my code:
    > >
    > > '{$STAMP BS2}
    > >
    > > '''To get to first room
    > > 'Variables==========================================================
    > ===========================================
    >
    > > l_dist VAR Word 'Variable for left srf04 reading
    > > r_dist VAR Word 'Variable for right srf04 reading
    > > f_dist VAR Word 'Variable for front srf04 reading
    > > a VAR Word 'Counter for servos
    > >
    > >
    > > 'Navigation=========================================================
    > ===========================================
    >
    > > Firsthall: 'hall one for the maze
    > (fire-fighting)
    > > GOSUB checksensors
    > > IF f_dist < 580 THEN left1
    > > IF l_dist < 290 THEN radjust1
    > > IF r_dist < 290 THEN ladjust1
    > > GOSUB forward
    > > GOTO firsthall
    > >
    > > radjust1:
    > > GOSUB radjust
    > > GOTO Firsthall
    > >
    > > ladjust1:
    > > GOSUB ladjust
    > > GOTO Firsthall
    > >
    > > left1:
    > > GOSUB left
    > >
    > > halltodoor1:
    > > GOSUB checksensors
    > > IF f_dist < 1450 THEN left2
    > > IF l_dist < 290 THEN radjust2
    > > IF r_dist < 290 THEN ladjust2
    > > GOSUB forward
    > > GOTO halltodoor1
    > >
    > > radjust2:
    > > GOSUB radjust
    > > GOTO halltodoor1
    > >
    > > ladjust2:
    > > GOSUB ladjust
    > > GOTO halltodoor1
    > >
    > > left2:
    > > GOSUB left
    > >
    > > intoroom1:
    > > GOSUB checksensors
    > > IF f_dist < 3190 THEN checkforfire
    > > IF l_dist < 290 THEN radjust3
    > > IF r_dist < 290 THEN ladjust3
    > > GOSUB forward
    > > GOTO intoroom1
    > >
    > > radjust3:
    > > GOSUB radjust
    > > GOTO intoroom1
    > >
    > > ladjust3:
    > > GOSUB ladjust
    > > GOTO intoroom1
    > >
    > > checkforfire:
    > > STOP 'normally send to hamamatsu subroutine
    > >
    > > 'Subroutines========================================================
    > ===========================================
    >
    > >
    > > checksensors:
    > > PULSOUT 0,5 'front srf04 is P0
    > > OUTPUT 0 'delay
    > > RCTIME 0,1,f_dist 'store value in f_dist
    > >
    > > PULSOUT 1,5 'left srf04 is P1
    > > OUTPUT 1 'delay
    > > RCTIME 1,1,l_dist 'store value in l_dist
    > >
    > > PULSOUT 2,5 'right srf04 is P2
    > > OUTPUT 2 'delay
    > > RCTIME 2,1,r_dist 'store value in r_dist
    > > return
    > >
    > >
    > > forward:
    > > FOR a = 1 TO 10
    > > PULSOUT 12,1000
    > > PULSOUT 13,500
    > > PAUSE 10
    > > next
    > > return
    > >
    > > left:
    > > FOR a = 1 TO 20
    > > PULSOUT 12,500
    > > PULSOUT 13,500
    > > PAUSE 10
    > > next
    > > return
    > >
    > > right:
    > > FOR a = 1 TO 20
    > > PULSOUT 12,1000
    > > PULSOUT 13,1000
    > > PAUSE 10
    > > next
    > > return
    > >
    > > ladjust:
    > > FOR a = 1 TO 6
    > > PULSOUT 12,800
    > > PULSOUT 13,500
    > > PAUSE 10
    > > next
    > > return
    > >
    > > radjust:
    > > FOR a = 1 TO 6
    > > PULSOUT 12,1000
    > > PULSOUT 13,700
    > > PAUSE 10
    > > next
    > > return
    > >
    > > end
    > >
    > > Here is my problem. the code works fine. It takes too long to
    > execute. The robot stops each time it needs to check the sensors. Is
    > there anyway I can eliminate this? Can I shorten my code? All help is
    > greatly appreciated. Thank you.
    > >
    > > John Baker
    > >
    > >
    > >
    > >
    > > Do you Yahoo!?
    > > Yahoo! Finance: Get your refund fast by filing online
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    > 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.
    >
    > Yahoo! Groups Links
    >
    >
    >
    >
    >
    >
    >
    >
    > Do you Yahoo!?
    > Yahoo! Finance: Get your refund fast by filing online
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    > 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.
    >
    > Yahoo! Groups Links
    >
    >
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-09 02:01
    Hello John Baker,

    Your program is very interesting. I just got a Davantech SRRF04 Ultrasonic
    Range Finder on Wednesday, and I'm also having problems like you are having.
    I've been learning how to use SRF04, and studying the timings with an
    OPTAscope.

    In the specs that came with the SRF04, it says the "Echo Pulse is Approx.
    36 ms if no Object Detected". In your program you have 3 RCTIME commands
    before sending PULSOUT to the servos. So, in the worst case that could be
    108 ms, plus the 10 ms on the last PAUSE 10 that was executed before a
    PULSOUT to the servos..

    You might need to send pulses to the servos between the RCTIME commands,
    depending on the distance from the SRF04 to the nearest object.

    Steve


    _____________
    Original Message
    From: "John Baker" <johnbaker_erie_pa@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, February 08, 2004 3:15 PM
    Subject: [noparse][[/noparse]basicstamps] SRF04 troubles


    >
    > Hello all. I'm using 3 SRF04s for avoidance on my trinity robot.
    >
    > Here is my code:
    >
    > '{$STAMP BS2}
    >
    > '''To get to first room
    >
    'Variables==================================================================
    ===================================
    > l_dist VAR Word 'Variable for left srf04 reading
    > r_dist VAR Word 'Variable for right srf04 reading
    > f_dist VAR Word 'Variable for front srf04 reading
    > a VAR Word 'Counter for servos
    >
    >
    >
    'Navigation=================================================================
    ===================================
    > Firsthall: 'hall one for the maze
    (fire-fighting)
    > GOSUB checksensors
    > IF f_dist < 580 THEN left1
    > IF l_dist < 290 THEN radjust1
    > IF r_dist < 290 THEN ladjust1
    > GOSUB forward
    > GOTO firsthall
    >
    > radjust1:
    > GOSUB radjust
    > GOTO Firsthall
    >
    > ladjust1:
    > GOSUB ladjust
    > GOTO Firsthall
    >
    > left1:
    > GOSUB left
    >
    > halltodoor1:
    > GOSUB checksensors
    > IF f_dist < 1450 THEN left2
    > IF l_dist < 290 THEN radjust2
    > IF r_dist < 290 THEN ladjust2
    > GOSUB forward
    > GOTO halltodoor1
    >
    > radjust2:
    > GOSUB radjust
    > GOTO halltodoor1
    >
    > ladjust2:
    > GOSUB ladjust
    > GOTO halltodoor1
    >
    > left2:
    > GOSUB left
    >
    > intoroom1:
    > GOSUB checksensors
    > IF f_dist < 3190 THEN checkforfire
    > IF l_dist < 290 THEN radjust3
    > IF r_dist < 290 THEN ladjust3
    > GOSUB forward
    > GOTO intoroom1
    >
    > radjust3:
    > GOSUB radjust
    > GOTO intoroom1
    >
    > ladjust3:
    > GOSUB ladjust
    > GOTO intoroom1
    >
    > checkforfire:
    > STOP 'normally send to hamamatsu subroutine
    >
    >
    'Subroutines================================================================
    ===================================
    >
    > checksensors:
    > PULSOUT 0,5 'front srf04 is P0
    > OUTPUT 0 'delay
    > RCTIME 0,1,f_dist 'store value in f_dist
    >
    > PULSOUT 1,5 'left srf04 is P1
    > OUTPUT 1 'delay
    > RCTIME 1,1,l_dist 'store value in l_dist
    >
    > PULSOUT 2,5 'right srf04 is P2
    > OUTPUT 2 'delay
    > RCTIME 2,1,r_dist 'store value in r_dist
    > return
    >
    >
    > forward:
    > FOR a = 1 TO 10
    > PULSOUT 12,1000
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > left:
    > FOR a = 1 TO 20
    > PULSOUT 12,500
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > right:
    > FOR a = 1 TO 20
    > PULSOUT 12,1000
    > PULSOUT 13,1000
    > PAUSE 10
    > next
    > return
    >
    > ladjust:
    > FOR a = 1 TO 6
    > PULSOUT 12,800
    > PULSOUT 13,500
    > PAUSE 10
    > next
    > return
    >
    > radjust:
    > FOR a = 1 TO 6
    > PULSOUT 12,1000
    > PULSOUT 13,700
    > PAUSE 10
    > next
    > return
    >
    > end
    >
    > Here is my problem. the code works fine. It takes too long to execute. The
    robot stops each time it needs to check the sensors. Is there anyway I can
    eliminate this? Can I shorten my code? All help is greatly appreciated.
    Thank you.
    >
    > John Baker
    >
    >
    >
    >
    > Do you Yahoo!?
    > Yahoo! Finance: Get your refund fast by filing online
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    > 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.
    >
    > Yahoo! Groups Links
    >
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-09 15:23
    When using servos you can 'refresh' the pulse to
    the servo NO FASTER THAN every 10 mSec -- 20 mSec
    is recommended. So I am not suggesting that
    you refresh your servos faster.

    My point was, currently you are waiting that
    10 mSec in each subroutine. You could easily
    use some of that 10 mSec to read your sensors
    in the MAIN loop, and THEN wait 10 mSec before
    the next refresh.

    To make your life easier,
    all you would have to do is insert one
    'PAUSE 10' after FIRSTHALL: and HALLTODOOR:,
    and INTOROOM1:
    then remove the 'PAUSE 10' lines from the
    subroutines. This would guarantee the pause
    happened ONCE for each main loop, instead
    of once for every subroutine
    call you make.

    --- In basicstamps@yahoogroups.com, John Baker
    <johnbaker_erie_pa@y...> wrote:
    > Allan, when I remove the pauses, my servos act up. They have
    unpredictable behavior. I'm using standard modified servos. Where
    else would I put these pauses? Are you suggesting that I put one
    pause 10 in each "main" loop? Also, I read somewhere about a serial
    servo controller. Would it be faster to just "serout" a command, and
    use the rest of the code the way it is? Thank you for your time.
    >
    > Allan Lane <allan.lane@h...> wrote:You have a lot of 'Pause 10'
    lines
    > in your subroutines.
    >
    > You could remove the 'Pause 10' from
    > your subroutines -- move the pauses into
    > your 'main' loop, and use some of that
    > time to check your sensors.
    >
    > --- In basicstamps@yahoogroups.com, John Baker
    > wrote:
    > >
    > > Hello all. I'm using 3 SRF04s for avoidance on my trinity robot.
    > >
    > > Here is my code:
    > >
    > > '{$STAMP BS2}
    > >
    > > '''To get to first room
    >
    > 'Variables==========================================================
    > ===========================================
    --
    >
    > > l_dist VAR Word 'Variable for left srf04 reading
    > > r_dist VAR Word 'Variable for right srf04 reading
    > > f_dist VAR Word 'Variable for front srf04 reading
    > > a VAR Word 'Counter for servos
    > >
    > >
    >
    > 'Navigation=========================================================
    > ===========================================
    --
    >
    > > Firsthall: 'hall one for the maze
    > (fire-fighting)
    > > GOSUB checksensors
    > > IF f_dist < 580 THEN left1
    > > IF l_dist < 290 THEN radjust1
    > > IF r_dist < 290 THEN ladjust1
    > > GOSUB forward
    > > GOTO firsthall
    > >
    > > radjust1:
    > > GOSUB radjust
    > > GOTO Firsthall
    > >
    > > ladjust1:
    > > GOSUB ladjust
    > > GOTO Firsthall
    > >
    > > left1:
    > > GOSUB left
    > >
    > > halltodoor1:
    > > GOSUB checksensors
    > > IF f_dist < 1450 THEN left2
    > > IF l_dist < 290 THEN radjust2
    > > IF r_dist < 290 THEN ladjust2
    > > GOSUB forward
    > > GOTO halltodoor1
    > >
    > > radjust2:
    > > GOSUB radjust
    > > GOTO halltodoor1
    > >
    > > ladjust2:
    > > GOSUB ladjust
    > > GOTO halltodoor1
    > >
    > > left2:
    > > GOSUB left
    > >
    > > intoroom1:
    > > GOSUB checksensors
    > > IF f_dist < 3190 THEN checkforfire
    > > IF l_dist < 290 THEN radjust3
    > > IF r_dist < 290 THEN ladjust3
    > > GOSUB forward
    > > GOTO intoroom1
    > >
    > > radjust3:
    > > GOSUB radjust
    > > GOTO intoroom1
    > >
    > > ladjust3:
    > > GOSUB ladjust
    > > GOTO intoroom1
    > >
    > > checkforfire:
    > > STOP 'normally send to hamamatsu subroutine
    > >
    >
    > 'Subroutines========================================================
    > ===========================================
    --
    >
    > >
    > > checksensors:
    > > PULSOUT 0,5 'front srf04 is P0
    > > OUTPUT 0 'delay
    > > RCTIME 0,1,f_dist 'store value in f_dist
    > >
    > > PULSOUT 1,5 'left srf04 is P1
    > > OUTPUT 1 'delay
    > > RCTIME 1,1,l_dist 'store value in l_dist
    > >
    > > PULSOUT 2,5 'right srf04 is P2
    > > OUTPUT 2 'delay
    > > RCTIME 2,1,r_dist 'store value in r_dist
    > > return
    > >
    > >
    > > forward:
    > > FOR a = 1 TO 10
    > > PULSOUT 12,1000
    > > PULSOUT 13,500
    > > PAUSE 10
    > > next
    > > return
    > >
    > > left:
    > > FOR a = 1 TO 20
    > > PULSOUT 12,500
    > > PULSOUT 13,500
    > > PAUSE 10
    > > next
    > > return
    > >
    > > right:
    > > FOR a = 1 TO 20
    > > PULSOUT 12,1000
    > > PULSOUT 13,1000
    > > PAUSE 10
    > > next
    > > return
    > >
    > > ladjust:
    > > FOR a = 1 TO 6
    > > PULSOUT 12,800
    > > PULSOUT 13,500
    > > PAUSE 10
    > > next
    > > return
    > >
    > > radjust:
    > > FOR a = 1 TO 6
    > > PULSOUT 12,1000
    > > PULSOUT 13,700
    > > PAUSE 10
    > > next
    > > return
    > >
    > > end
    > >
    > > Here is my problem. the code works fine. It takes too long to
    > execute. The robot stops each time it needs to check the sensors.
    Is
    > there anyway I can eliminate this? Can I shorten my code? All help
    is
    > greatly appreciated. Thank you.
    > >
    > > John Baker
    > >
    > >
    > >
    > >
    > > Do you Yahoo!?
    > > Yahoo! Finance: Get your refund fast by filing online
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    > 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.
    >
    > Yahoo! Groups Links
    >
    >
    >
    >
    >
    >
    >
    >
    > Do you Yahoo!?
    > Yahoo! Finance: Get your refund fast by filing online
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-09 15:33
    Oh, darn, I just re-read your code.
    You are doing the Servo stuff using 'FOR'
    loops -- so you can't remove the PAUSE 10
    inside the FOR loop. My Bad.


    --- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
    wrote:
    > When using servos you can 'refresh' the pulse to
    > the servo NO FASTER THAN every 10 mSec -- 20 mSec
    > is recommended. So I am not suggesting that
    > you refresh your servos faster.
    >
    > My point was, currently you are waiting that
    > 10 mSec in each subroutine. You could easily
    > use some of that 10 mSec to read your sensors
    > in the MAIN loop, and THEN wait 10 mSec before
    > the next refresh.
    >
    > To make your life easier,
    > all you would have to do is insert one
    > 'PAUSE 10' after FIRSTHALL: and HALLTODOOR:,
    > and INTOROOM1:
    > then remove the 'PAUSE 10' lines from the
    > subroutines. This would guarantee the pause
    > happened ONCE for each main loop, instead
    > of once for every subroutine
    > call you make.
    >
    > --- In basicstamps@yahoogroups.com, John Baker
    > <johnbaker_erie_pa@y...> wrote:
    > > Allan, when I remove the pauses, my servos act up. They have
    > unpredictable behavior. I'm using standard modified servos. Where
    > else would I put these pauses? Are you suggesting that I put one
    > pause 10 in each "main" loop? Also, I read somewhere about a serial
    > servo controller. Would it be faster to just "serout" a command,
    and
    > use the rest of the code the way it is? Thank you for your time.
    > >
    > > Allan Lane <allan.lane@h...> wrote:You have a lot of 'Pause 10'
    > lines
    > > in your subroutines.
    > >
    > > You could remove the 'Pause 10' from
    > > your subroutines -- move the pauses into
    > > your 'main' loop, and use some of that
    > > time to check your sensors.
    > >
    > > --- In basicstamps@yahoogroups.com, John Baker
    > > wrote:
    > > >
    > > > Hello all. I'm using 3 SRF04s for avoidance on my trinity
    robot.
    > > >
    > > > Here is my code:
    > > >
    > > > '{$STAMP BS2}
    > > >
    > > > '''To get to first room
    > >
    >
    > 'Variables==========================================================
    > > ===========================================
    --
    > --
    > >
    > > > l_dist VAR Word 'Variable for left srf04 reading
    > > > r_dist VAR Word 'Variable for right srf04 reading
    > > > f_dist VAR Word 'Variable for front srf04 reading
    > > > a VAR Word 'Counter for servos
    > > >
    > > >
    > >
    >
    > 'Navigation=========================================================
    > > ===========================================
    --
    > --
    > >
    > > > Firsthall: 'hall one for the maze
    > > (fire-fighting)
    > > > GOSUB checksensors
    > > > IF f_dist < 580 THEN left1
    > > > IF l_dist < 290 THEN radjust1
    > > > IF r_dist < 290 THEN ladjust1
    > > > GOSUB forward
    > > > GOTO firsthall
    > > >
    > > > radjust1:
    > > > GOSUB radjust
    > > > GOTO Firsthall
    > > >
    > > > ladjust1:
    > > > GOSUB ladjust
    > > > GOTO Firsthall
    > > >
    > > > left1:
    > > > GOSUB left
    > > >
    > > > halltodoor1:
    > > > GOSUB checksensors
    > > > IF f_dist < 1450 THEN left2
    > > > IF l_dist < 290 THEN radjust2
    > > > IF r_dist < 290 THEN ladjust2
    > > > GOSUB forward
    > > > GOTO halltodoor1
    > > >
    > > > radjust2:
    > > > GOSUB radjust
    > > > GOTO halltodoor1
    > > >
    > > > ladjust2:
    > > > GOSUB ladjust
    > > > GOTO halltodoor1
    > > >
    > > > left2:
    > > > GOSUB left
    > > >
    > > > intoroom1:
    > > > GOSUB checksensors
    > > > IF f_dist < 3190 THEN checkforfire
    > > > IF l_dist < 290 THEN radjust3
    > > > IF r_dist < 290 THEN ladjust3
    > > > GOSUB forward
    > > > GOTO intoroom1
    > > >
    > > > radjust3:
    > > > GOSUB radjust
    > > > GOTO intoroom1
    > > >
    > > > ladjust3:
    > > > GOSUB ladjust
    > > > GOTO intoroom1
    > > >
    > > > checkforfire:
    > > > STOP 'normally send to hamamatsu subroutine
    > > >
    > >
    >
    > 'Subroutines========================================================
    > > ===========================================
    --
    > --
    > >
    > > >
    > > > checksensors:
    > > > PULSOUT 0,5 'front srf04 is P0
    > > > OUTPUT 0 'delay
    > > > RCTIME 0,1,f_dist 'store value in f_dist
    > > >
    > > > PULSOUT 1,5 'left srf04 is P1
    > > > OUTPUT 1 'delay
    > > > RCTIME 1,1,l_dist 'store value in l_dist
    > > >
    > > > PULSOUT 2,5 'right srf04 is P2
    > > > OUTPUT 2 'delay
    > > > RCTIME 2,1,r_dist 'store value in r_dist
    > > > return
    > > >
    > > >
    > > > forward:
    > > > FOR a = 1 TO 10
    > > > PULSOUT 12,1000
    > > > PULSOUT 13,500
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > left:
    > > > FOR a = 1 TO 20
    > > > PULSOUT 12,500
    > > > PULSOUT 13,500
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > right:
    > > > FOR a = 1 TO 20
    > > > PULSOUT 12,1000
    > > > PULSOUT 13,1000
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > ladjust:
    > > > FOR a = 1 TO 6
    > > > PULSOUT 12,800
    > > > PULSOUT 13,500
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > radjust:
    > > > FOR a = 1 TO 6
    > > > PULSOUT 12,1000
    > > > PULSOUT 13,700
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > end
    > > >
    > > > Here is my problem. the code works fine. It takes too long to
    > > execute. The robot stops each time it needs to check the sensors.
    > Is
    > > there anyway I can eliminate this? Can I shorten my code? All
    help
    > is
    > > greatly appreciated. Thank you.
    > > >
    > > > John Baker
    > > >
    > > >
    > > >
    > > >
    > > > Do you Yahoo!?
    > > > Yahoo! Finance: Get your refund fast by filing online
    > > >
    > > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > >
    > >
    > >
    > > 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.
    > >
    > > Yahoo! Groups Links
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > > Do you Yahoo!?
    > > Yahoo! Finance: Get your refund fast by filing online
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-09 22:42
    Thanks Allan. I think I'm going to save up $50 and get a Serial Servo
    Controller. I'd love to build my own, but I don't know where to start. I've
    never successfully programmed a PIC.

    Allan Lane <allan.lane@h...> wrote:Oh, darn, I just re-read your
    code.
    You are doing the Servo stuff using 'FOR'
    loops -- so you can't remove the PAUSE 10
    inside the FOR loop. My Bad.


    --- In basicstamps@yahoogroups.com, "Allan Lane"
    wrote:
    > When using servos you can 'refresh' the pulse to
    > the servo NO FASTER THAN every 10 mSec -- 20 mSec
    > is recommended. So I am not suggesting that
    > you refresh your servos faster.
    >
    > My point was, currently you are waiting that
    > 10 mSec in each subroutine. You could easily
    > use some of that 10 mSec to read your sensors
    > in the MAIN loop, and THEN wait 10 mSec before
    > the next refresh.
    >
    > To make your life easier,
    > all you would have to do is insert one
    > 'PAUSE 10' after FIRSTHALL: and HALLTODOOR:,
    > and INTOROOM1:
    > then remove the 'PAUSE 10' lines from the
    > subroutines. This would guarantee the pause
    > happened ONCE for each main loop, instead
    > of once for every subroutine
    > call you make.
    >
    > --- In basicstamps@yahoogroups.com, John Baker
    > wrote:
    > > Allan, when I remove the pauses, my servos act up. They have
    > unpredictable behavior. I'm using standard modified servos. Where
    > else would I put these pauses? Are you suggesting that I put one
    > pause 10 in each "main" loop? Also, I read somewhere about a serial
    > servo controller. Would it be faster to just "serout" a command,
    and
    > use the rest of the code the way it is? Thank you for your time.
    > >
    > > Allan Lane wrote:You have a lot of 'Pause 10'
    > lines
    > > in your subroutines.
    > >
    > > You could remove the 'Pause 10' from
    > > your subroutines -- move the pauses into
    > > your 'main' loop, and use some of that
    > > time to check your sensors.
    > >
    > > --- In basicstamps@yahoogroups.com, John Baker
    > > wrote:
    > > >
    > > > Hello all. I'm using 3 SRF04s for avoidance on my trinity
    robot.
    > > >
    > > > Here is my code:
    > > >
    > > > '{$STAMP BS2}
    > > >
    > > > '''To get to first room
    > >
    >
    > 'Variables==========================================================
    > > ===========================================
    --
    > --
    > >
    > > > l_dist VAR Word 'Variable for left srf04 reading
    > > > r_dist VAR Word 'Variable for right srf04 reading
    > > > f_dist VAR Word 'Variable for front srf04 reading
    > > > a VAR Word 'Counter for servos
    > > >
    > > >
    > >
    >
    > 'Navigation=========================================================
    > > ===========================================
    --
    > --
    > >
    > > > Firsthall: 'hall one for the maze
    > > (fire-fighting)
    > > > GOSUB checksensors
    > > > IF f_dist < 580 THEN left1
    > > > IF l_dist < 290 THEN radjust1
    > > > IF r_dist < 290 THEN ladjust1
    > > > GOSUB forward
    > > > GOTO firsthall
    > > >
    > > > radjust1:
    > > > GOSUB radjust
    > > > GOTO Firsthall
    > > >
    > > > ladjust1:
    > > > GOSUB ladjust
    > > > GOTO Firsthall
    > > >
    > > > left1:
    > > > GOSUB left
    > > >
    > > > halltodoor1:
    > > > GOSUB checksensors
    > > > IF f_dist < 1450 THEN left2
    > > > IF l_dist < 290 THEN radjust2
    > > > IF r_dist < 290 THEN ladjust2
    > > > GOSUB forward
    > > > GOTO halltodoor1
    > > >
    > > > radjust2:
    > > > GOSUB radjust
    > > > GOTO halltodoor1
    > > >
    > > > ladjust2:
    > > > GOSUB ladjust
    > > > GOTO halltodoor1
    > > >
    > > > left2:
    > > > GOSUB left
    > > >
    > > > intoroom1:
    > > > GOSUB checksensors
    > > > IF f_dist < 3190 THEN checkforfire
    > > > IF l_dist < 290 THEN radjust3
    > > > IF r_dist < 290 THEN ladjust3
    > > > GOSUB forward
    > > > GOTO intoroom1
    > > >
    > > > radjust3:
    > > > GOSUB radjust
    > > > GOTO intoroom1
    > > >
    > > > ladjust3:
    > > > GOSUB ladjust
    > > > GOTO intoroom1
    > > >
    > > > checkforfire:
    > > > STOP 'normally send to hamamatsu subroutine
    > > >
    > >
    >
    > 'Subroutines========================================================
    > > ===========================================
    --
    > --
    > >
    > > >
    > > > checksensors:
    > > > PULSOUT 0,5 'front srf04 is P0
    > > > OUTPUT 0 'delay
    > > > RCTIME 0,1,f_dist 'store value in f_dist
    > > >
    > > > PULSOUT 1,5 'left srf04 is P1
    > > > OUTPUT 1 'delay
    > > > RCTIME 1,1,l_dist 'store value in l_dist
    > > >
    > > > PULSOUT 2,5 'right srf04 is P2
    > > > OUTPUT 2 'delay
    > > > RCTIME 2,1,r_dist 'store value in r_dist
    > > > return
    > > >
    > > >
    > > > forward:
    > > > FOR a = 1 TO 10
    > > > PULSOUT 12,1000
    > > > PULSOUT 13,500
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > left:
    > > > FOR a = 1 TO 20
    > > > PULSOUT 12,500
    > > > PULSOUT 13,500
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > right:
    > > > FOR a = 1 TO 20
    > > > PULSOUT 12,1000
    > > > PULSOUT 13,1000
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > ladjust:
    > > > FOR a = 1 TO 6
    > > > PULSOUT 12,800
    > > > PULSOUT 13,500
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > radjust:
    > > > FOR a = 1 TO 6
    > > > PULSOUT 12,1000
    > > > PULSOUT 13,700
    > > > PAUSE 10
    > > > next
    > > > return
    > > >
    > > > end
    > > >
    > > > Here is my problem. the code works fine. It takes too long to
    > > execute. The robot stops each time it needs to check the sensors.
    > Is
    > > there anyway I can eliminate this? Can I shorten my code? All
    help
    > is
    > > greatly appreciated. Thank you.
    > > >
    > > > John Baker
    > > >
    > > >
    > > >
    > > >
    > > > Do you Yahoo!?
    > > > Yahoo! Finance: Get your refund fast by filing online
    > > >
    > > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > >
    > >
    > >
    > > 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.
    > >
    > > Yahoo! Groups Links
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > > Do you Yahoo!?
    > > Yahoo! Finance: Get your refund fast by filing online
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]



    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.

    Yahoo! Groups Links







    Do you Yahoo!?
    Yahoo! Finance: Get your refund fast by filing online

    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.