Multitasking

Hi.
I’m creating a new topic, becouse I couldn’t find anything useful on forum.

I have a working script (Brandon M of Pololu helped me with it - thanks, which we discussed in topic 2 buttons and 3 servos) and want to upgrade it with a third button.

Push of the third button has to override any servo positions or movements immediately and send scipt cursor to end: line in the script. Im using 6 channel maestro, so third button will be on channel 0 and Im using pull down resistor on buttons.

This is the script:

 6500 3 servo
 6500 4 servo
 6500 5 servo


 wait_for_trigger_press_1000ms
 goto main_loop
 sub trigger
   1 get_position 1023 equals
   2 get_position 1023 equals
   logical_and
 return
 sub wait_for_trigger_press_1000ms
   get_ms
   begin
     trigger
     if
       get_ms over minus 1000 greater_than
       if drop return endif
     else
       drop get_ms
     endif
   repeat


 main_loop:

 get_ms 1

  begin

   1 get_position 1023 equals
   2 get_position 1023 equals
   logical_and
   if
   # STRAIGHT
   4000 3 servo #RUDDER
   4000 4 servo #STABILIZER
   4000 5 servo #WIGGLER
   endif

   1 get_position 1023 equals
   2 get_position 512 less_than
   logical_and
   if
  # LAUNCH
   5000 3 servo #RUDDER
   5000 4 servo #STABILIZER
   5000 5 servo #WIGGLER
   endif

   1 get_position 512 less_than
   2 get_position 1023 equals
   logical_and
   if
  # CIRCLE
   6000 3 servo #RUDDER
   6000 4 servo #STABILIZER
   6000 5 servo #WIGGLER
   endif

   1 get_position 512 less_than
   2 get_position 512 less_than
   logical_and
   if
  # BUNT
   #    RUDDER        STABILIZER        WIGGLER        TIME (miliseconds)
       4500 3 servo    4500 4 servo    4500 5 servo    0500 delay        #BUNT_1
       5000 3 servo    5000 4 servo    5000 5 servo    0500 delay        #BUNT_2
       5500 3 servo    5500 4 servo    5500 5 servo    0500 delay        #BUNT_3
       6000 3 servo    6000 4 servo    6000 5 servo    0500 delay        #BUNT_4
   # FLIGHT
   #    RUDDER        STABILIZER        WIGGLER        TIME (seconds)
       6500 3 servo    6500 4 servo    6500 5 servo    180 delay_seconds

   end:
  # DT    
   #    RUDDER        STABILIZER        WIGGLER
         7000 3 servo    7000 4 servo    7000 5 servo
   quit
   endif

   dup 2 get_position 1023 equals logical_and if
       drop
       0
    endif
   dup logical_not 1 get_position 1023 equals logical_and if
     drop
     1
   endif
    dup if swap drop get_ms swap endif
   swap dup get_ms minus
    dup negative if
      negate
    endif
      32000 greater_than
        if  
          goto end
        endif
   swap
   repeat

   sub delay_seconds
     begin dup while
       1 minus 1000 delay
     repeat
     drop return

Hello, sasho.

Since the Maestro does not support interrupts on the Maestro channels, detecting the button push at anytime within a script as complex as yours would probably be impractical and difficult. One way you might be able to do something like that would be to use a separate microcontroller like an Arduino to detect the button push and send the “Restart Script at Subroutine” or “Stop Script” serial command (depending on how you want it to behave) to interrupt the current script.

Brandon

So sorry to hear that. My application has to be light and compact as possible.
Is there some other controller that supports interrupts and reads maestro script?

We do not have any other devices that accept Maestro scripts and have inputs available that support interrupts. However, you might consider using something like the Arduino-compatible A-Star 32U4 Micro for monitoring the button and sending serial commands to the Maestro to stop the script:

The A-Star 32U4 Micro features the ATmega32U4 microcontroller (the same one used on the Arduino Leonardo), but comes in a much smaller form factor and still offers 15 general-purpose I/O lines. You can find the available Maestro serial commands for controlling the execution of the script in the “Serial Script Commands” section of the Maestro user’s guide. We also have a Maestro Servo Controller library for Arduino available that should help make the communication easier.

Brandon