IM using a Micro Maestro 6-Channel.
Hi, Im a total beginner with this and I apologize if Im all over the place Ill try and be concise. IM making an iron man helmet and want to control servos with the micro maestro. Ive figured out basically how to create and run a sequence from the laptop.
Im going to wire a button into channel 0, servo A into channel 1, Servo B into channel 2 (possibly LEDS eyes into channel 3 though it’ll probably be easier to run the lights manually with just a switch on a seperate circuit without the pololu)
The way I see it I could have a few possibilities:
Situation A- Top priority
I would like to have the button begin a sequence (open helmet) and push the button again to reverse the sequence, or reset (to close the helmet) whichever brings it back to the starting position the easiest.
…if that isnt easily doable
Situation B- I dont mind using extra buttons if needed
Same as A except a second button in a spare channel to play a closing sequence. button1 runs open command, button2 runs close
Situation C
Same as A except LED light eyes turn off on open command, and turn back on after close, another button controls lights independently. This would be my most ideal, but it is the most confusing for me to imagine, and most complicated IM sure, so it isnt my top priority
IF anyone in Pololu land could help and paste the most basic script to achieve Situation A or B that I could study, (please assume Im ignorant of programming) and tweak myself with my own actual movement commands I would be forever grateful. And if someone really really patient wants to walk through a possible way to achieve Situation 3 I wouldnt turn that down :).
Having one button do a sequence of different things (in this case just 2 things) can usually be done easily by using some sort of state variable. Here is an example script that should function the way you described in “Situation A” once you add your servo commands where I have indicated:
1 #Sets an initial state (open)
begin
0 get_position
500 greater_than #Check if button is pushed
if
dup
if #If helmet is open, run frame to close it
close_helmet #Run the close_helmet subroutine
drop #Change the state to 0
0
else #If helmet is closed, run frame to open it
open_helmet #Run the open_helmet subroutine
drop #Change the state to 1
1
endif
endif
repeat
sub close_helmet #This is the subroutine to close the helmet
#Add your servo commands to close the helmet here
500 delay
return
sub open_helmet #This is the subroutine to open the helmet
#Add your servo commands to open the helmet here
500 delay
return
As for “Situation C”, you could try adding in commands in the “close_helmet” and “open_helmet” subroutines that control your LEDs. Once you get that working, you could try adding a second button that uses the “get_position” command to check the state of the LED, and changes it independently of the first button. If you have trouble with any of that, please let me know.
Thanks so much for the help. I did a little test run with two junk sub routines and it kept looping forever. Im totally new to this code, but I just applied a little thought and quickly noticed, that the button was going from 0-256 when open or closed. SO I changed the first line you gave me to less than 1 just to see what would happen. Now it runs one command with one press and the other command with a second press. As far as I can tell I just have to plug in the real positions and I’ll be done. Thanks so much again. Ill let you know if something else comes up. Let me know if you notice a flaw in my logic above.
Another Question(s).
IF I were to run a second button to do somethng else separately how could I let the program know the difference between the two buttons? A different strength resistor? a different range signal change to look for?
Also could you show me a basic on/ off command for LEd please. Thanks again
**EDIT**
Ive only actually tested it by checking “run script on startup” in the script part of the program. I havent downloaded it to the Pololu yet. While Testing I noticed the Stack window on the side, it goes up to 31, and after 31 routines(basically it is filling up when I press the button) there is an error and I have to manually restart the device. Will this happen after downloading the commands to the Pololu as well? or is it just a part of the script program that Im misreading? I understand there is only so much memory in the chip, but im repeating the same two commands, I didnt think it would matter how often I press the button (maybe it doesnt??) is there a way to avoid this error? Like a command that resets upon error?
*DOUBLE EDIT*
I think Ive solved that issue, I had my delay after a frame at the bottom instead of after the actual subroutine for open_helmet. Ive fixed that and now the stack isnt growing at all no matter how often I press the button
1 #Sets an initial state (open)
begin
0 get_position
1 less_than #Check if button is pushed
if
dup
if #If helmet is open, run frame to close it
close_helmet #Run the close_helmet subroutine
drop #Change the state to 0
0
else #If helmet is closed, run frame to open it
open_helmet #Run the open_helmet subroutine
drop #Change the state to 1
1
endif
endif
repeat
### Sequence subroutines: ###
# close_helmet
sub close_helmet
500 0 0 0 7491 9033 frame_1..5 # Frame 0
500 4594 frame_4 # Frame 1
500 delay
return
# open_helmet
sub open_helmet
500 0 0 0 5984 7254 frame_1..5 # Frame 0
500 6659 frame_5 # Frame 1
500 6316 frame_4 # Frame 2
500 5686 frame_5 # Frame 3
500 6923 frame_4 # Frame 4
500 5091 frame_5 # Frame 5
500 7491 frame_4 # Frame 6
return
sub frame_1..5
5 servo
4 servo
3 servo
2 servo
1 servo
delay
return
sub frame_4
4 servo
delay
return
sub frame_5
5 servo
500 delay
return
I am glad you figured out the problem with your script and that you were able to get it working.
Connecting and controlling an LED is described in the “Attaching Servos and Peripherals” section of the user’s guide. Please note that you will use the same “Set Target” command you use for controlling servos, to control your LEDs. The LED should be on if you set the target to greater than or equal to 1500us (or 6000 in your script) and off otherwise.
In order to connect a second button that controls the LEDs independently, you would use a separate channel and use the “get_position” command with that channel, as you did with the first button on channel 0.
Hey Bud. I actually made a Ironman costume 2 years ago built around the Micro Maestro 6-Channel. I posted all the code and how it was to function in the Projects forum. Good luck. Here is the test I recorded. The switch was a small piece of metal glued to my forefinger and one on the thumb of my glove. I used RCA male and female jacks for easy connecting when I put the suit on.
Testing facebook.com/photo.php?v=10 … 2570949749
Sorry to dig up an old thread, but instead of starting a new one I thought I would revive this one…
Anyone perchance have the wiring diagram of how he hooked up the switches?
I’m doing something similar with 4 servos (opening 4 doors), each 2 doors get 1 button. Push to open then push to close again.
So a schematic or fzz file, anything would be appreciated.
Information about connecting switches to the Maestro can be found in the “Button or switch” heading of the “Attaching Servos and Peripherals” section of the Maestro user’s guide. Please note that in order to use a switch or button with the Maestro, the channel it is connected to must be configured as an input, which you can do from the “Channel Settings” tab of the Maestro Control Center. If you have any questions about connecting your switches after looking through the section of the guide linked to above, please let me know, and I would be glad to help.
Well I made some progress. But nothing happens on button push.
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`
# 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
I know this is an old post i hate to bring it up again but im trying to accomplish the same build with an iron man helmet and i have no idea what im doing, i have the movement i want in a script but having trouble adding the button one click up, and a second click to go down any help would be great.
Have you tried adding code to handle the button press to your script? I suspect you will be able to get what you want by using the code in my post above and putting in 2500 3968 8000 0 0 0 0 0 0 0 0 0 frame_1..11 or 2500 9920 2176 frame_1_2 (your two positions) in the lines I indicated for adding your servo commands for closing and opening the helmet.
If you try that and have problems, can you post your complete updated script?
thanks for your help, i have done what you have asked and im still having problems.
nothing happens when i press the momentary switch i have im using 0 on the servo board, Im going to post the script i have below
1 #Sets an initial state (open)
begin
0 get_position
500 greater_than #Check if button is pushed
if
dup
if #If helmet is open, run frame to close it
close_helmet #Run the close_helmet subroutine
drop #Change the state to 0
0
else #If helmet is closed, run frame to open it
open_helmet #Run the open_helmet subroutine
drop #Change the state to 1
1
endif
endif
repeat
sub close_helmet
2500 3968 8000 0 0 0 0
0 0 0 0 0 # frame 0
500 delay
return
sub open_helmet
2500 9920 2176 # frame 1
500 delay
return
There are no actual “SERVO” commands in your close_helmet and open_helmet subroutines, so nothing will happen right now when you press the button, aside from adding the values to the stack and delaying for 500ms. Since your sequences look so simple, it is probably easier to rewrite them than copy them over with the subroutines from your previous post. For example, to add the “SERVO” commands to your close_helmet subroutine, what you have now would become:
1 #Sets an initial state (open)
begin
0 get_position
500 greater_than #Check if button is pushed
if
dup
if #If helmet is open, run frame to close it
close_helmet #Run the close_helmet subroutine
drop #Change the state to 0
0
else #If helmet is closed, run frame to open it
open_helmet #Run the open_helmet subroutine
drop #Change the state to 1
1
endif
endif
repeat
sub close_helmet
3968 1 servo
8000 2 servo
500 delay
return
sub open_helmet
9920 1 servo
8000 2 servo
500 delay
return
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_2
2 servo
1 servo
delay
return
It looks like you made a mistake trying to copy the servo positions; you have 8000 2 servo in both the open_helmet and close_helmet subroutine, so that servo will not change positions when they are called. To match your original code, the line in open_helmet should change to 2176 2 servo as I suggested in my last post.
Also, note that since you are following my suggestion to rewrite the code, you can delete the sub frame_1..11 and sub frame_1_2 subroutines (e.g. everything after the open_helmet subroutine).