Shop OBEX P1 Docs P2 Docs Learn Events
Sumobot + PING - Avoid pauses while waiting for ping — Parallax Forums

Sumobot + PING - Avoid pauses while waiting for ping

flowstateflowstate Posts: 3
edited 2014-02-24 21:36 in BASIC Stamp
Hi,

I've got a sumobot using Ping sensors (a pair up front). Currently, the code works, and is pretty standard. If either of the sensors sees something closer than the radius of the ring, it's flag is set to 1, else 0.

I found that to avoid cross-chatter between the sensors, I'm having to introduce a pause. This, added to the natural pause on the PULSIN command, has given me a robot that stutters like Forrest Gump. I know we can't use threading in BASIC, but has anyone found a way around this? Below is the way that I'm reading the input from the Pings. I'm basically running the standard SumoWrestler code, substituting Pings in place of the IR pairs.
PULSOUT Left_Ping_Pin, 5
PULSIN Left_Ping_Pin, 1, time
inDistance = inConstant ** time  ' not sure of the math on this one, but it's from the Parallax site
PAUSE 50

I do that twice (once for each Ping), and then go on about my business. However, the length of this function creates the servo stuttering I mentioned earlier. Any help would be appreciated.

Regards,
Eric

Comments

  • flowstateflowstate Posts: 3
    edited 2014-01-16 09:46
    So I solved the problem. Basically, after each PULSIN call to a Ping, I called the Pulse_Servos subroutine. This came in under the 20ms requirement for smooth servo manipulation
  • RonbertRonbert Posts: 20
    edited 2014-02-24 12:22
    Could you expand on your second post with some code? I'm in a situation like this and am displeased with the pause times.

    So say I check the ping sensors, instead of putting

    PAUSE 20
    RETURN

    just do

    GOSUB Forward
    RETURN
  • FranklinFranklin Posts: 4,747
    edited 2014-02-24 21:36
    [COLOR=#333333]So say I check the ping sensors, instead of putting[/COLOR]
    
    [COLOR=#333333]PAUSE 20[/COLOR]
    [COLOR=#333333]RETURN[/COLOR]
    
    [COLOR=#333333]just do [/COLOR]
    
    [COLOR=#333333]GOSUB Forward[/COLOR]
    [COLOR=#333333]RETURN
    
    anything you can fit into those 20 ms can be substituted for the pause or any part of it. If you had something that took 10 ms you could use that and a PAUSE 10.[/COLOR]
Sign In or Register to comment.