Help with script code for maestro 6

i have used a maestro 6 to control a servo for about 8 yrs. it basically flips a focusing mask in front of my telescope and back out of the way. Also i have a red led on pins 2, so that the led on tells me from afar in the dark, the position im in. I had a simple script, someone helped me put together on this forum that i ran from windows cmd line. i have only used up to now one servo. it has worked great.
here is the script i have used.

; move servo 0 to either open or close
; depending on previous state
; also turns led on when in closed state

3  0 acceleration   ;set acceleration
5  0 speed          ;set speed

sub beginning       ; makes it so will repeat at cmd prompt
0 get_position

6000 less_than
if
   8000 0 servo    ; servo motor to mask in place
   8000 2 servo     ; led to on
else
   4000 0 servo     ; servo motor to mask parked away
   4000 2 servo     ; led to off
endif

at the cmd prompt: i type… UscCmd --sub 0
and it flips it in position… then run cmd again and it flips it in stored position.

Now im wanting to add a second servo to control. I have 2 telescope on my mount and am wanting to control two seperate focus mask. i have the original servo on pins0… the second on pins1.
im having trouble getting a script that works…
can i get help? been ages since ive done any simple Basic programming.
Anthony

Hello.

If you want your second servo to function separately from your first and have it’s own Command Line prompt, then you can write the code for it in a separate subroutine. If you want it to basically behave the same way as your first servo, you can copy and paste your beginning subroutine, then change the name and update the values for the new servo and LED, which would look something like this:

sub beginning       #subroutine 0: controls servo on channel 0 and LED on channel 2
  0 get_position 6000 less_than if
    8000 0 servo    ; servo motor to mask in place
    8000 2 servo     ; led to on
  else
    4000 0 servo     ; servo motor to mask parked away
    4000 2 servo     ; led to off
  endif
quit

sub newSubroutine       #subroutine 1: controls servo on channel 1 and LED on channel 3
  1 get_position 6000 less_than if
    8000 1 servo    ; servo motor to mask in place
    8000 3 servo     ; led to on
  else
    4000 1 servo     ; servo motor to mask parked away
    4000 3 servo     ; led to off
  endif
quit

Then, if you want to move the first servo, you can still use usccmd --sub 0, and if you want to move the second servo you can use usccmd --sub 1.

If you try this and run into problems, could you post a copy of your Maestro settings file? You can save a copy of your settings file from the “File” drop-down menu of the Maestro Control Center while the controller is connected.

Brandon

Brandon…
thanks a million, ill give it a try and let you know how it worked.
another question…

i set the acceleration and speed with
3 0 acceleration #set acceleration channel 0
5 0 speed #set speed channel 0

can i simply add additional lines? … or will the stack somehow be effected?
3 1 acceleration #set acceleration channel 1
5 1 speed #set speed channel 1

i have recommended Pololu to others over the years who are trying to do simple robotic stuff.
your great

Those lines of code should be fine for setting the speed and acceleration on channel 1; however, since your script is always starting at one of the two subroutines, it will never run that code if you put them outside of the subroutines. Since you aren’t ever changing the speed or acceleration, it would probably be easier to configure it in the “Channel Settings” tab of the Maestro Control Center (the speed and acceleration values there are essentially applied at power up each time).

Brandon

Brandon
thanks for the advice. so i will eliminate those lines from the script code and let maestro control center define it… even if different for each channel.

1 Like