Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Slide Pot to control 2 servos

Hi,
I have one button which controls one servo and one potentiometer that controls 2 servos

The code I have can make the button work or I can make one servo work using the slide pot.

I’m getting myself really confused here and would really appreciate some help please.

begin 

 0 get_position     #get the value of the input on channel 0

  500 less_than if   #if it is less than 500 

  4000 5 servo      #move the servo on channel 0 to 1000us

  
  1 get_position    # get the value of the pot, 0-1023

  4 times 4000 plus # scale it to 4000-8092, approximately 1-2 ms

  3 servo           # set servo 5 based to the value

  

  endif

repeat


If I add another servo, 4 servo the mini maestro crashes.
If I remove the button part of the script the slide pot works with one servo.

I know I could use a y lead, but is there code I can use instead?

If I remove the potentiometer code the button part works.

Any help would be really gratefully received thanks,

Jon

Hello, Jon.

Could you describe how you want each servo to behave with regards to the button and potentiometer? Right now, it looks like the potentiometer code will not work unless the button is pressed/held. So, if you want that to be independent, you should move the endif command to just before 1 get_position.

Do you want the servo on channel 4 to follow the potentiometer (i.e. have the same position as the servo on channel 3)? Could you post the script that you tried to included 4 servo in?

Brandon

Hi,
Thanks for the help.
The button is to control one servo. When pressed it goes to position and when released the servo returns.

The slide potentiometer is separate from the button but controls two servos.

I’m making a puppet so that when I press the button he blinks and when I move the slide potentiometer his eyes move from side to side.

I hope that helps,

Thanks again,

Jon

There are a few things you will need to add to your script to make it work like you described, but I suggest breaking it up into parts. So, for the button part, you currently have the first half, which moves the servo when the button is pressed; however, you will need to add the else condition to move the servo back when it is released, which would look like this:

 0 get_position     #get the value of the input on channel 0

  500 less_than if   #if it is less than 500 

  4000 5 servo      #move the servo on channel 5 to 1000us
 
  else		#otherwise,

  8000 5 servo      #move the servo on channel 5 to 2000us

  endif

Then, for the potentiometer portion, you will need to add a dup command after scaling the input value. This will put 2 identical values on the stack, then one will be used for 3 servo and one will be used for 4 servo, like this:

  1 get_position    # get the value of the pot, 0-1023

  4 times 4000 plus  #scale it to 4000-8092, approximately 1-2 ms
 
  dup	           #duplicate the scaled value

  3 servo           #set servo 3 to the scaled value

  4 servo          #set servo 4 to the scaled value

If you try to make those changes and still have problems, can you post your updated script?

Brandon

Hi Brandon,

Everything work sgreat, really happy with the results.
Just a question though, I’m using hobby servos to control the eye movement and blink. These are very noisy, especially when moved quickly like in the blink.
Could I use mini stepper motors instead? Would they move fast enough?

Thanks,

Jon

You might be able to get some small stepper motors that are fast enough. It is a little bit more complicated to tell how fast a stepper motor can move since there are a lot of factors that can impact it. If you can quantify how much torque your system needs, you can probably get a general idea of the capabilities of a stepper motor by looking at it’s pull-out torque curve, which is usually provided in the manufacturer’s datasheet.

Please note that the Maestro cannot directly drive stepper motors. I would generally recommend a dedicated stepper motor driver or one of our Tic stepper motor controllers. The Tic stepper motor controllers can be configured to accept RC signals like those from the Maestro, so you could control them from a Maestro.

Brandon

Awesome thanks,

I’m looking at controlling them with radio control and see you have a Tic stepper motor controller for that.
Would I need one controller for each motor though?

Thanks again,

Jon

The Tic controllers have a single stepper motor output channel, so if you want to control two steppers independently, you would need one for each. If you want your stepper motors to always move in unison, you could probably get away with connecting them in series or parallel to a single Tic controller. If you are interested in doing this and want more information about running them in series or parallel, I would be happy to post some more details.

Brandon