Program help pls,Micro Maestro 6-Channel Servo Controller

Hi Guys

I hoping someone can help me out with some programming. I have a Micro Maestro 6-Channel USB Servo Controller. I have a push button on channel 0. I have a Continuous Rotation Servo on Channel 1. The servo position for off is 1492. This is what I’d like to do

Press the button
Wait 3 seconds
Spin the servo 360 degrees, direction doesn’t matter, then stop the servo.
Wait for the button to be pushed again
Wait 3 seconds
Spin the servo 360 degrees, direction doesn’t matter then stop the servo.
And so on

Any help would be greatly appreciated

Here’s my Ironman form 2 years ago

Hi Guys. I can’t find the guy who helped me with my Iron Man programming so if anyone can help with 360 degree program that’d be awesome. .

I’ve been asked for the code for the Ironman helmet. Here it is. As I mentioned an acquaintance wrote this and I paid him for it. The servers had to run in mirror opposite directions but together because of how they were mounted.

[code]Connections
Channel 0 - Servo 1
Channel 1 - Servo 1
Channel 2 - Push Button Switch
Channel 3 - Eyes
Channel 4 - Arc Reactor

Operation
The start position is always “visor up, eyes and Arc reactor off ”

Press the button to run the servos to close the visor.
Visor closed “then” the Arc reactor lights up
then the lights in the eyes flicker a little then stay on.

Press the button again to run the servos to open the visor.
At the same time the lights in the eyes flicker a little then turn off.
Visor open
Then the Arc reactor turns off
This is the start position

Program
servo_reset
lights_off
servo_reset

main_loop

quit

servo control subroutines

sub servo_reset
#reset servos to mid position
500 delay
4000 4000 set_servos
return

sub servo_gate_open
#move servos in the opposite direction
500 delay
4000 8000 set_servos
return

sub servo_fin_right
#move both servos to the left
500 delay
8000 8000 set_servos
return

sub set_servos
#consume two stack values to run servos
1 servo 0 servo
return

Button stadfte read subroutines

sub button
2 get_position 511 less_than
return

sub wait_for_press
wait_open
wait_close
return

sub wait_open
get_ms
begin
button
if
drop get_ms
else
get_ms over minus 10 greater_than
if drop return endif
endif
repeat
return

sub wait_close
get_ms
begin
button
if
get_ms over minus 10 greater_than
if drop return endif
else
drop get_ms
endif
repeat
return

light control

sub eyes_on
8000 3 servo
return

sub eyes_off
2000 3 servo
return

sub arc_on
8000 4 servo
return

sub arc_off
2000 4 servo
return

sub eyes_flicker
eyes_on
20 delay
eyes_off
180 delay
eyes_on
40 delay
eyes_off
160 delay
eyes_on
80 delay
eyes_off
120 delay
return

sub lights_off
arc_off
eyes_off
return

sub main_loop
#Test function: control light with a button
begin
wait_for_press
led_on
arc_on
1000 delay
servo_fin_right
500 delay
eyes_flicker
eyes_on
led_off
wait_for_press
led_on
eyes_off
500 delay
servo_reset
500 delay
arc_off
led_off
repeat
return[/code]

Hello.

I am not sure I understand what you are asking. Did you want the script you posted to be modified to include the functionality you mentioned in your first post?

Also, it is typically more difficult to turn the continuous rotation servos exactly 360° since you do not have position feedback in most cases. You will most likely have to send them a command to rotate, and time how long a full rotation takes. Then, you can delay for that amount of time before sending a command to stop the rotation.

-Brandon

[quote=“BrandonM”]Hello.

I am not sure I understand what you are asking. Did you want the script you posted to be modified to include the functionality you mentioned in your first post?

Also, it is typically more difficult to turn the continuous rotation servos exactly 360° since you do not have position feedback in most cases. You will most likely have to send them a command to rotate, and time how long a full rotation takes. Then, you can delay for that amount of time before sending a command to stop the rotation.

-Brandon[/quote]

Hey Brandon

No I was just posting the Ironman script for those interested.

For my new project I modified a servo to spin 360. You’re 100 percent right on the positioning. Without the pot the program has no way of knowing the location. I’m new to all this. I did get it working though. I fumbled through the examples and used the sequence function. There is prolly a bunch of code in this that isn’t required but it works and I’ll mess with it after Halloween.

[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
5900 frame
6000 frame
repeat

sub frame
wait_for_button_press
5 servo

Sequence subroutines:

Sequence 0

sub Sequence_0
500 0 0 0 0 6000 frame_1…5 # Frame 0
1650 6343 frame_5 # Frame 1
500 6000 frame_5 # Frame 2
return

sub frame_1…5
5 servo
4 servo
3 servo
2 servo
1 servo
delay
return

sub frame_5
5 servo
delay
return[/code]