Get_s subroutine

Hi.
Can anyone post a script for get_ms commad to be in seconds.
I cant figure it out by myself.

Thanks in advance

Hello.

I am sorry you are having trouble. What have you tried and what specifically are you not able to figure out?

-Jon

Hello.
I am posting a part of script that is cousing me trouble:

dup 2 get_position 512 less_than logical_and if #This line of code checks if the state variable is 1 and button 2 is pressed
drop #if the statement above is true, drop the current state variable and replace it with 0
0
endif
dup logical_not 1 get_position 512 less_than logical_and if #This checks if the state variable is 0 and button 1 is pressed
drop #if true, set the state variable back to the default of 1
1
endif
dup if swap drop get_ms swap endif #if state variable is true, update the timer
swap dup get_ms minus #subtract the current time from the stored timer
dup negative if #if negative, make positive
negate
endif
10000 greater_than #compare it to 10 seconds (10000 ms)
if
goto end #if greater than 10 seconds, go to the “end” label
endif
swap

In this part of the code I am trying to change 10000 miliseconds to be 180 seconds

Hello.

It sounds like you want to compare long delay values using the Maestro scripting language. The Maestro’s GET_MS timer wraps around from 32767 to -32768, so the maximum amount of time elapsed that it can help you determine before wrapping around is about 65 seconds. So, you will probably first need to write a script that can represent 180 seconds of elapsed time. You could see an example of a subroutine that counts the number of elapsed seconds inside our “Long delays” example, which you can find under the “Example Scripts” section of the Maestro user’s guide. You can find the user’s guide under the “Resources” tab of any Maestro product page. However, those example scripts only show how to do blocking delays; it would not be easy to run other code during those delays. Let me know if you need to do a non-blocking delay because I could offer some advice on that too.

-Jon

I have already tried to help myself with long delays example, but no success. I have practicaly no skills in scripting in any language.
would you be so nice to advise me how to do a non-blocking delay.

Here is an example of a non-blocking subroutine that keeps track of the number of seconds elapsed:

0       # initialize seconds_timer, how many seconds have elapsed
get_ms  # initialize current_time_elapsed

begin
  seconds_timer_update
  # run other code, but make sure it takes less then 30 seconds
repeat

sub seconds_timer_update
  # while (get_ms - current_time_elapsed) > 1000
  begin
    get_ms 1 pick minus 1000 greater_than while
    1000 plus         # (current_time_elapsed += 1000)
    swap 1 plus swap  # (seconds_timer += 1)      	
  repeat
  return

-Jon

Hi Jon.
Thank you for uploading an example.

Is this the way to extend time to more than just 32767 miliseconds?
And if - how do I integrate it into my script?

FREE FLIGHT GLIDER (CATEGORY F1A).txt (3.8 KB)

Sorry for not having any descriptions in the script, because honestly I don’t understand behavior of every step in the script + English is not my native language.

Note that I am using Maestro Micro and this is my setup:

  • channel 0 is button with pull-up resistor
  • channel 1 & 2 are buttons with pull-down resistor
  • channel 3 to 5 are servos

The subroutine in my last post keeps track of the number of seconds that have passed by incrementing a counter each time the script recognizes that 1000 milliseconds has gone by. Reading through the code comments and stepping through it (using the “Step Script” button) inside the “Script” tab of the Maestro Control Center should help you get a better understanding of how the subroutine works.

In order to incorporate that subroutine into your script, you will need to add its variables to your stack and then do a good job with your stack operations to effectively manage all of variables your script is working with. Can you try integrating the subroutine in your script? If you get stuck, post what you have tried and I might be able to help. If you do not know where or how to start, specifically describe what it is you do not understand.

-Jon