Shop OBEX P1 Docs P2 Docs Learn Events
Simultaneous multiple mechanical operations — Parallax Forums

Simultaneous multiple mechanical operations

neosurrealneosurreal Posts: 7
edited 2007-08-01 05:29 in BASIC Stamp
hi,

i would like some clarification on this. is it possible to have multiple mechanical operations, motors, leds, etc, functioning all simultaneously with only one board? what i mean is that if a pin is programmed for a certain duration, that operation has to end in order to move onto the next one, no? so it's a linear process? or is there to order one's programming in a different way that one pin doesn't have to wait until the other pin finishes.

hope that makes sense...

Thanks!

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-08-01 02:08
    You can make one pin high, go on to something else and come back to make it low. You couldn't watch a pin for input and output to the serial port at the same time though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • neosurrealneosurreal Posts: 7
    edited 2007-08-01 02:45
    Right, so for example, if i have a LED circuit/matrix and a motor, I would have to first keep the motor on, let the LED do its thing, and THEN, come back to turn off the motor, right? I apologize if I sound utterly clueless.

    Thanks in advance!

    Post Edited (neosurreal) : 8/1/2007 5:20:28 AM GMT
  • ZootZoot Posts: 2,227
    edited 2007-08-01 05:29
    Correct. The biggest issue here is "scheduling" and, most likely, avoiding the need for regular PULSOUTs or PWMs. I have a fairly large 'bot that runs all the following "simultaneously" in a round-robin fashion:

    - 2 motors (external I2C motor controller)
    - 3 pan/tilt sensor turrets (Parallax Servo Controller)
    - 2 PING sonar units
    - 2 IR rangers (using external I2C ADC)
    - 2 CDS light sensors (using external I2C ADC)
    - LED "running" lights (using external I2C PWM out)
    - 12x5 LED matrix display (using MAX 7221 display driver)
    - 2 RC receiver channels
    - misc. boolean sensors (low voltage, battery charger, etc.)
    - DS1307 real-time clock (I2C)
    - Emic text-to-speech

    I set the code up so that it cycles through all the routines, but certain routines get run more often than others. In pseudo code it looks something like this:

    
    START:
    
    ticks = ticks + 1 // 5  ' ticks count from 0 to 4, then repeat
    
    I2COUT to PWM LEDs ' run LED running lights every tick for smooth fades, etc
    SHIFTOUT to MAX7221 ' dump bitmaps, scrolling text, etc., every tick to LED matrix for smooth animation
    check boolean sensors 'simple check of input pins
    I2CIN once per minute from DS1307 or so to update real-time
    
    IF ticks = 0 THEN
         check RC X channel   'check each RC channel only once per 5 ticks because timeout on PULSIN is slow
         SEROUT to PSC 'run all the servos at beginning of the ticks cycle
    ENDIF
    
    IF ticks = 1 THEN
         check RC Y channel   'check each RC channel only once per 5 ticks because timeout on PULSIN is slow
         I2CIN from ADC for IR cliff/lowobj detector  'check twice per 5 ticks for faster stop at cliff/lowobject
    ENDIF
    
    IF ticks = 2 THEN
         check leftside PING   'check each sonar channel only once per 5 ticks because time can be pretty long
         I2CIN from ADC for rear IR detector  'check once per 5 ticks
         I2CIN from ADC for left light sensor
    ENDIF
    
    IF ticks = 3 THEN
         check rightside PING   'check each sonar channel only once per 5 ticks because time can be pretty long
         I2CIN from ADC for IR cliff/lowobj detector  'check twice per 5 ticks for faster stop at cliff/lowobject
         I2CIN from ADC for right light sensor
    ENDIF
    
    IF ticks = 4
         do all the main parsing and behavioral code 'decide what to do based on sensors, etc
          SEROUT to Emic
    ENDIF
    
    IF ticks = 4 or MotorSpeed = STOP THEN    'motors are updated only once per cycle, or immediately if a stop command has been issued
        I2COUT to motor controller 'move the platform
    ENDIF
    
    GOTO Start  'do it all again
    
    
    


    Of course, it's all a bit more complex, and I set up my subsumption engine so that some sensors (like the RC receiver) are not checked when reacting to obstacles (this cuts the time through the loop to make reflex actions more responsive), but under ideal circumstances I'm getting 7-12 hz for the 5 tick cycle, which isn't bad for a Stamp (BS2p40). Again, none of this would be possible if I didn't have the "set it and forget it" advantage of the PSC handling servo pulses (though the serout overhead is a bit stiff) and the external I2C chip for PWM and ADC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    Post Edited (Zoot) : 8/1/2007 5:34:29 AM GMT
Sign In or Register to comment.