Synchronize Maestro sequence to external clock

I am a newbie using the Maestro 6 controller. It is working great for my animatronic project. However, I am not a programmer. I would like to be able to synchronize the movements to music. So I would like to know if it would be possible to control the speed of the sequence based on a hardware clock input I am open to use any controller, even Arduino or similar to do the job. But I like the simplicity of control using the Maestro controller software.

Hello.

It is possible for you to control the speed of a sequence based on an external clock, however, it would be very difficult and inaccurate if you are planning to read and handle those values directly from the Maestro. I recommend that you use a microcontroller to handle the music synchronization and control the Maestro’s sequence execution via serial commands. You can find more details about the Maestro serial commands in the “Serial Servo Commands” and “Serial Script Commands” sections of the Maestro User’s Guide. It might be convenient for you to use an Arduino or an Arduino-compatible board (like our A-Stars), since there are a lot of music synchronization examples for the Arduino that you can find on the Internet to help you get started. You might also consider using the Arduino Maestro library, which makes it easier to control the Maestro from an Arduino or an Arduino-compatible board.

Alternatively, you might be interested in using Brookshire’s Visual Show Automation software, which provides a visual interface to choreograph animatronic sequences, and has a feature that allows users to specify that they are using a Maestro controller. We do not use VSA, but some of our customers have used it to send commands to the Maestro. You can search the forum to see examples of people using VSA with the Maestro.

- Amanda

Amanda,

Thanks so much for your detailed response.

My initial test plan was to use an op-amp based beat detector, and then use this pulse somehow to ‘sync’ the script. I was hoping to be able to read this pulse as it were a push button input. Is it possible to ‘manually’ step a sequence by pushing a button. This way it may be possible to achieve a sort of sync.

I will look into Arduino music synchronization.

Yes, it is possible to step through your sequence using a button. You can find a button example which might be helpful to you under the “Examples Scripts” section in the Maestro User’s Guide.

- Amanda

Amanda,

I finally found some time to implement the push button step of a sequence using the 6c sample script and it works very well. In fact I can connect a pulse generator instead of a button ans I am able to control the sequence speed in real time, which is great. Now I would like to create a sequence, generate the script, and paste into the button stepper script of 6c. I tried it but I get errors. So here is a very basic sequence script:

[code]# Sequence 0
begin
500 3968 3968 3968 3968 0 0
0 0 0 0 0 frame_1…11 # Frame 0
500 8000 frame_1 # Frame 1
500 8000 frame_2 # Frame 2
500 8000 frame_3 # Frame 3
500 8000 frame_4 # Frame 4
repeat

sub frame_1…11
11 servo
10 servo
9 servo
8 servo
7 servo
6 servo
5 servo
4 servo
3 servo
2 servo
1 servo
delay
return

sub frame_1
1 servo
delay
return

sub frame_2
2 servo
delay
return

sub frame_3
3 servo
delay
return

sub frame_4
4 servo
delay
return[/code]

Can you please show me where to insert it the the 6c script so that I can push button step through it?

Thanks so much for your help.

Using the “Using a button or switch to control servos” example script, you could put the code in the BEGIN/REPEAT code block of the basic script you posted into a subroutine (e.g. start_sequence) and call that subroutine after calling wait_for_button_press. For example:

# rest of "Using a button or switch to control servos" example code

sub frame
  wait_for_button_press
  start_sequence
  return

subroutine start_sequence
  500 3968 3968 3968 3968 0 0 
  0 0 0 0 0 frame_1..11 # Frame 0
  500 8000 frame_1 # Frame 1
  500 8000 frame_2 # Frame 2
  500 8000 frame_3 # Frame 3
  500 8000 frame_4 # Frame 4
  return

# rest of your basic script

If you try again and keep getting errors, can you post the full script that is causing the errors and a screenshot of the Error tab in the Maestro Control Center?

- Amanda

Amanda,

I am not able to get a basic script to work with the button step script. Would you mind merging my basic sequence to the 6c code also attached? Thanks!

Basic test sequence:

[code]# Sequence 0
begin
500 3968 0 8000 3968 0 0
0 0 0 0 0 frame_1…11 # Frame 0
500 8000 frame_1 # Frame 1
500 3968 frame_3 # Frame 2
500 8000 frame_4 # Frame 3
repeat

sub frame_1…11
11 servo
10 servo
9 servo
8 servo
7 servo
6 servo
5 servo
4 servo
3 servo
2 servo
1 servo
delay
return

sub frame_1
1 servo
delay
return

sub frame_3
3 servo
delay
return

sub frame_4
4 servo
delay
return
[/code]
Step sequence script (6c):

[code]
goto main_loop # Run the main loop when the script starts (see below).

This subroutine returns 1 if the button is pressed, 0 otherwise.

To convert the input value (0-1023) to a digital value (0 or 1) representing

the state of the button, we make a comparison to an arbitrary threshold (500).

This subroutine puts a logical value of 1 or a 0 on the stack, depending

on whether the button is pressed or not.

sub button
0 get_position 500 less_than
return

This subroutine uses the BUTTON subroutine above to wait for a button press,

including a small delay to eliminate noise or bounces on the input.

sub wait_for_button_press
wait_for_button_open_10ms
wait_for_button_closed_10ms
return

Wait for the button to be NOT pressed for at least 10 ms.

sub wait_for_button_open_10ms
get_ms # put the current time on the stack
begin
# reset the time on the stack if it is pressed
button
if
drop get_ms
else
get_ms over minus 10 greater_than
if drop return endif
endif
repeat

Wait for the button to be pressed for at least 10 ms.

sub wait_for_button_closed_10ms
get_ms
begin
# reset the time on the stack if it is not pressed
button
if
get_ms over minus 10 greater_than
if drop return endif
else
drop get_ms
endif
repeat

An example of how to use wait_for_button_press is shown below:

Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through

a sequence of positions on servo 1.

main_loop:
begin
4000 frame
5000 frame
6000 frame
7000 frame
8000 frame
repeat

sub frame
wait_for_button_press
1 servo
return[/code]

It sounds like you might have tried merging the two scripts yourself. If that is the case, can you post that code here? If not, can you try implementing what I had suggested in my previous post?

In general, we do not mind helping you troubleshoot your code and giving suggestions, but we do not want to write our user’s code for them.

- Amanda

Amanda,

Attached are my last attempt at the script, and the errors.

I appreciate your advice.

Thanks!




COMBINED SCRIPT 011616.txt (1.88 KB)

Amanda,

Never mind I figured out.

It should would be nice if the step sequence script was an option in the Maestro software so that once you setup a channel as an input and created a sequence, a script would be created with the button subroutine automatically embedded. So one would not have to modify the script and do so much editing. As I mentioned before once a step button is operating, the button input can be replaced by a simple hardware oscillator allowing speed control of a sequence by turning a knob that varies the oscillator frequency.

I am glad you found out what was causing the issue and resolved it; thank you for letting us know.

We appreciate your suggestion, but we do not think that it would be useful to automatically add a button/switch subroutine into every script converted from the “Sequence” tab, since a button or switch is not always used in a system.

By the way, even though your issue has been resolved, I wanted to point out to others, who might have the same issue, the most likely reason you received the error described in your previous post. Your code had a colon after the definition of your start_sequence subroutine like so sub start_sequence:, which is invalid in the Maestro scripting language. (Colons are used when defining a label like main_loop:, which is the name of an address of an instruction or piece of data. For example, using GOTO main_loop in your script will cause the program to redirect to the main_loop label in your code and resume flow from there.)

- Amanda

I realize that a button is not always used, but you could add this option in the sequence menu. So if you select the option and choose an input channel, then the step/sync button option would be enabled. I think it would be a good option to easily control the speed of an animation like a walking bug or robot. You could sell an oscillator accessory board for ease of implementation. Another optional accessory could be a simple hardware based beat detector (opamp/filter scheme) that could also be used to control the sequence.

Checkout the video of my Maestro 12 controlled marionette:

We enjoyed watching the video of your Karate puppet. Thank you for sharing it.

- Amanda