Hello, maybe someone can help here. I’m getting the error message
“ENDIF must end an IF…ENDIF or an IF…ELSE…ENDIF block.”
I actually just want the Mastro6 to send a command to the ESP32 via a button.
So, I’ve set the servo on the Maestro to channel 0, the data cable to channel 1 (and to output), and the button to channel 2 (there, to input). The code on the ESP is installed to wait for the Maestro’s command.
But as soon as I try to upload it, the error message appears. I’ve tried having the Maestro check whether the servo is in the home position, i.e., down. It should do this as soon as it receives power to ensure it’s in the correct position.
Can anyone give me a tip?
I moved your post to the “Servo controllers and servos” category of the forum since it seems more appropriate.
If that is your complete script, there are several problems with the way it is written right now.
There are 3 BEGIN commands (which mark the beginning of a loop), but only 1 REPEAT command (which mark the end of a loop).
Also, you have a few commands in your script which are not valid commands for the Maestro scripting language (GET_VARIABLE, SET_VARIABLE, NOT, and UNTIL), so those aren’t going to work unless there is additional code defining those as subroutines that is missing from your post.
If you are unsure how to go about fixing those things, could you post more details about what you are doing and how you want the code to work?
Oh, actually, it’s quite simple.
I have a Maestro6 here. It has a servo connected to channel 0. This script was created using ChatGPT. The servo moves to a position, waits 4 seconds, then moves back, waits another 4 seconds, and so on.
This script works. Now I wanted the servo to only move when I give it a command, and in this case, that would be with a button. Later, I’d like to use a remote control, but first, a button. So, I put a button on channel 2 (connected to Signal+GND). And now the script should be rewritten so that the servo responds to the button.
As an additional feature, I had thought that the Maestro, when it receives power, would check the position of the servo, because it’s supposed to be in the home position.
Well, this script shown above was created using ChatGPT, and I don’t understand what’s wrong with it. I’ve noticed that there are commands that the Maestro6 can’t process, which are only for the 12, 18, or 24. This is also something that can be really annoying at times.
Unfortunately, ChatGPTis not very reliable at programming in the Maestro scripting language (although from my testing it seems to help sometimes if you include that it is a stack-based programming language based on FORTH).
However, for what you’re trying to do, I recommend looking through the “Example Scripts” section of the Maestro user’s guide (particularly the two examples for using a button). If you plan to switch to some kind of remote in the future, you probably don’t have to worry about the extra debouncing code, so a combination of the two button programs would probably work fine. For example:
begin
wait_for_button_press
9159 0 servo
500 delay
wait_for_button_press
3392 0 servo
500 delay
repeat
sub wait_for_button_press
begin
2 get_position 500 less_than if
return
endif
repeat
By the way, it sounds like you might not have used a pull-up resistor for your button; you will need to add one as described in the “Attaching Servos and Peripherals” section of the guide for it to work properly.
As far as the Maestro checking the position of the servo, unfortunately that is not possible. Servos do not make their feedback information available to the controller. They use 1-way communication, so the electronics inside the servo just process the pulse width signal being sent by the Maestro and drive the motor as commanded. If you want the Maestro to move a specific servo a home position on startup, you can set the “On startup or error” option in the “Channel Settings” tab to “Go to” and then enter the desired position into the text box. Alternatively, you could add that feature to your script by putting a SERVO command (e.g. 3392 0 servo) at the beginning, before the first BEGIN statement.
It sounds like you might not be copying the entire script/subroutine. To clarify, wait_for_button_press is not a native command in the Maestro scripting language; it is a subroutine defined at the bottom of the script I posted. If you still have problems after copying the entire subroutine definition into your script, please post your entire script and I would be glad to help troubleshoot further.
Okay, somehow it’s not working the way I want it to. I’ve checked everything, but I don’t understand what I’m forgetting? When I run the script, I don’t get an error message, which is fine. But the script runs completely once, and that’s it. The button has no effect.
begin
# hoch
wait_for_button_press
sub hoch
500 3392 0 0 frame_0..2 # Frame 0
500 9216 frame_0 # Frame 1
quit
# runter
wait_for_button_press
sub runter
500 9216 0 0 frame_0..2 # Frame 0
500 3392 frame_0 # Frame 1
quit
repeat
sub frame_0..2
2 servo
1 servo
0 servo
delay
return
sub frame_0
0 servo
delay
return
sub wait_for_button_press
begin
2 get_position 500 less_than if
return
endif
repeat
There are a few issues with the way your script is written. if you have not done so already, I recommend reading through “The Maestro Scripting Language” section of the Maestro user’s guide to get a better understanding of it. You might consider trying out the “Example Scripts” as well, and using the “Step Script” button to walk through it and see how each command works.
It looks like you might be confused about how the scripting language works with subroutines. A subroutine is essentially a custom function defined within the script (the sub command denotes the definition of a subroutine). Your main loop should not contain the definition of a subroutine, but it can call subroutines by name to run the code associated with them.
Another issue is that it looks like you might be using the sequencer to generate the start of your script, but might not have channel 2 configured correctly for a button input since your frame_0..2 subroutine is trying to use it as an output. Since you’re only using 1 servo, I recommend just using the SERVO command directly instead of using the sequencer. Before troubleshooting the code more, could you verify that your button is working as expected by monitoring the “Status” tab of the Maestro Control Center and making sure the slider on channel 2 moves from the right to the left when the button is pressed?