Shop OBEX P1 Docs P2 Docs Learn Events
walk/chew gum....simultaniously — Parallax Forums

walk/chew gum....simultaniously

Husky X3Husky X3 Posts: 18
edited 2007-11-27 15:38 in Robotics
· I am looking for a code that will allow me to program my Boe-bot to drive foward and flash·LED's·simultaniously. The problem is that either the servos will operate, or the LED's will operate. The other senario is that the LED's will run the same PULSOUT or HIGH/LOW command that the servos are using, so the flash sequence remains the same as servo duration.
·
·The Stamp wants to·handle commands only on an On-Off basis·for each of the I/O pins. Is there a way to isolate data packets that can be ignored by the rest of the program, thereby allowing me to run the LED's in any sequence that I wish despite·specific·commands to the servos?·




·· AJ

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PSALM 23

Post Edited (Husky X3) : 11/21/2007 5:23:43 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-20 23:31
    Servos generally require a control pulse every 20ms. That leaves quite a bit of time to do other things like flash LEDs. If you're controlling 2 servos, that's at most 5ms (2 x 2.5ms) for the control pulses leaving 20ms - 5ms = 15ms. Alternatively, you could use something like the new ServoPAL to take over the servo pulses and do whatever you wanted with the LEDs.
  • ZootZoot Posts: 2,227
    edited 2007-11-21 03:57
    As usual, Mike is right -- 20ms is enough time to do other stuff, and it's actually pretty fast -- if you blink your LEDs that fast, you won't see them blink...

    This might give you an idea of how to tackle it:

    ledCntr VAR Byte  'time slice
    speedL VAR Byte  'motor speed
    speedR VAR Byte  'motor speed
    
    motoL PIN 0
    motoR PIN 1
    leds VAR OUTC '4 leds on output states of pins 8-11
    
    DIRC = %1111 'make leds outputs
    
    leds = %0101 'turn on two of 'em
    
    Main:
    
       ' the goal is for the main loop to take about 20ms including send time on the pulses
      ' do some stuff
      speedL = 120
      speedR = 170
      'IF obstacle, change speed, etc
      'more stuff
       
    Update_Leds:
       ledCntr = ledCntr + 1 'each pass through loop increment counter -- each "tick" = ~20ms
       IF ledCntr = 5 THEN   'every 100ms (approx.) change the LEDs -- this is still pretty fast
          ledCntr = 0            'reset counter
          leds = ~leds         'just invert 'em, or put lots of fancy patterns here. Make the "5" above a variable to change speed of pattern "on the fly"
       ENDIF
    
    Send_Motors:
      GOSUB SEND_PULSES
    
    End_Main_Loop:
        'PAUSE 5  '---- strictly optional pause IF you need to pad the loop -- usually you will be tight, not loose, but you never know
        GOTO Main
    
    '-----------
    SEND_PULSES:
       'PULSOUT motoL, speedL, etc
       'PULSOUT motoR, speedR, etc
       RETURN
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Husky X3Husky X3 Posts: 18
    edited 2007-11-26 23:02
    Thanks Mike, but it was not the amount of time I had left over. Merely the fact that the Boe-bot would stop the servos to flash the LEDs, and then continue it's foward travel. I will check out the ServoPal, but ultimately I would like to run the the LED'S and sevos from the same MC ( bs2-ic ).


    · AJ

    P.S.
    that is some code, Zoot, thanks. I will give it a shot.


    i APPRECIATE EVERYONE'S HELP AND COMMENTS! thank you all.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PSALM 23
  • FranklinFranklin Posts: 4,747
    edited 2007-11-27 02:26
    Post your code and maybe we could find ways to help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • stephenwagnerstephenwagner Posts: 147
    edited 2007-11-27 13:08
    Try this.
    'Output Pins
    LEDPIN1 PIN ??
    LEDPIN2 PIN ???

    DO

    Hight LEDPIN1
    Low LEDPIN2

    FOR idx = 1 to 50

    GOSUB YourCodeToControlServo

    NEXT

    LOW LEDPIN1
    High LEDPIN2

    FOR idx = 1 to 50

    GOSUB YourCodeToControlServo

    NEXT

    LOOP

    YourCodeToControlServo:
    Your code goes here as a sub.
    RETURN

    Change the value(s) of idx to suit your needs.

    You might also want to try RANDOM and OUTS in place of the High and Low.

    I hope this helps.

    SJW
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-27 15:38
    Husky X3,
    What we're saying is that you have to interleave the servo handling and the LED handling rather than do one, than the other. It is certainly clearer and more straightforward to use something like a ServoPAL, but the Stamps can handle servos and LEDs at the same time with the interleaving.
Sign In or Register to comment.