Hi,
I’m trying to write a script that executes 3 subroutines once and then stops. According to a previous forum post, I put the quit command before the repeat in the loop as this is supposed to make the script run only once. However, this makes only the last subroutine be executed. Any ideas why that is? This is the script:
That script will run through all three subroutines, but it will not wait for the servos to reach each commanded position before continuing. So I suspect it is happening so fast that you are not able to see any affects from the first two, and are just left with the results of the last one.
With the way the subroutines are written, the first number in the string of numbers before calling the subroutine sets the delay time in milliseconds. In this case, they are all 10, which means the entire script is done in roughly 30ms. Just to verify it is working, you might try changing those to something much larger like 5000, which will cause the Maestro to wait 5 seconds between each subroutine.
Hi Brandon,
Thanks for your response, increasing the time did work! How would I change it so that the servos reach each commanded position before continuing please?
The easiest way to do that would be to use the GET_MOVING_STATE command, which returns true if any servos are still moving and false otherwise. However, please note that the Maestro does not have access to the servo’s feedback information, so for this command to work properly, the servo must be limited by speed or acceleration settings (the Maestro essentially compares the target position to the current position it’s commanding). So, if you have non-zero speed or acceleration settings for your servos, you could use a while statement like this after each subroutine to wait for the servos to reach their target position:
begin get_moving_state while
repeat
Additionally, please note that when the Maestro first starts up, it will not have a target for any of the servo channels by default, and the GET_MOVING_STATE will not work correctly since it relies on that information. So, the first time you run the script, it will look like the first subroutine was skipped. You can fix this by either setting starting positions for them in the “Channel Settings” tab, under the “On startup or error” column or by giving them initial positions at the start of your script. Please note that the starting positions must be different from the ones in your first subroutine or the Maestro will think the servo is already there and immediately move on to the next subroutine.
The Maestro script is stored on your computer, so there is practically no limit to the number of lines you can have in your script. You can add whitespace and comments without taking up memory on your Maestro. However, each value and command does occupy some of the Maestro’s limited memory. The Micro Maestro has 1 KB available for holding the compiled form of your script, while the Mini Maestros have 8 KB. If the size of your script (which is displayed for you near the top of the “Script” tab) becomes an issue for you, the “Compressing the sequence” subsection of the “Example Scripts” section of the Maestro user’s guide could be helpful.