XY Joystick as Momentary Switch for 2 Servos

Hello,
I am trying to control 2 servos with an XY joystick with the Mini Maestro 12 controller. Using the Example Scripts provided I was able to successfully control the servos with the joystick. However, when the joystick returns to the “home” position, the servos do as well. I would like to keep the servo in it’s position when the joystick is released (think aiming a security camera).
For example, I would like servo 1 to move up when the joystick is moved up, and stay when the joystick is released. Continue to move when the joystick is moved up again, then stop when released, and so on.
I am having a really hard time understanding how to code this. Below is a very simple example to show positioning of the servos/joystick inputs.

begin
  2 get_position   
  4 times 4000 plus 
  0 servo          
  3 get_position    
  4 times 4000 plus 
  1 servo           
repeat

Any help would be greatly appreciated. Thanks!

Hello.

It sounds like you want the joystick to move the target position and not map directly to the servo position. There are probably a few ways you could go about doing that, but the simplest would probably be to set some threshold for the upper and lower joystick positions, and when the joystick is outside of those positions, increase or decrease the target position accordingly.

Here is an example of what that might look like with a single servo and joystick:

begin
  2 get_position      #get joystick reading
  dup 700 greater_than if  #check if it is moved forward
    0 get_position    #get current servo position
    4 plus            #increase it by 4
    0 servo           #update servo position
    drop	
  else 300 less_than if  #check if it is moved backward
    0 get_position        #get current servo position
    4 minus	          #decrease it by 4
    0 servo	          #update servo position		
    endif
  endif
repeat

This example increases or decreases the servo position by a set amount. The 4 plus and 4 minus lines of code are controlling how quickly the servo moves since it is getting updated each cycle by that amount, so you can reduce the 4 to make it move slower or increase the 4 to make it move faster.

If you are new to the Maestro scripting language, you might find the “Step Script” button in the “Script” tab of the Maestro Control Center helpful for understanding what each line of code is doing. You might try going through the “Example Scripts” one by one and stepping through them to get an understanding of how the various commands work with the stack.

Brandon

Thank you! I was lost on how to go about this. It works well and i am able to control the servo correctly and should be easily able to add a second servo.

One issue i had is that when the servo reaches its maximum rotation, the servo ‘resets’. I am able to spin it (for example) 10 degrees, then another 20 degrees, and so on, but then when it reaches it’s limit it returns to the starting position automatically. What could I add to prevent this movement?

The minimum and maximum values should be capped by the “Min” and “Max” settings for your servo channel in the “Channel Settings” tab. For example, when the servo is at the maximum position, and the joystick is pushed up, it should add 4 to that, but since that is above the maximum, it will get reset back to the maximum. What do you have your Min and Max values set to? Can you post your Maestro settings file so I can see what else might be causing that behavior? You can save your settings file by selecting the “Save settings file…” option within the “File” drop-down menu of the Maestro Control Center.

By the way, does it look like the servos are straining at some point before they “reset”? It might be possible that you are commanding the servos to move beyond their physical limit, causing them to brown out and reset. If this is the problem, you should be able to fix it by adjusting your Min and Max settings to reduce the range. More information about finding the limits of your servo can be found in the fifth FAQ under the “FAQs” tab of the Maestro’s product page.

Brandon

I have the min and max for both X and Y servo directions set at 64 and 4080, respectively (the min and max possible). It only happens in one direction for each servo as well.

To explain this further, just looking at one servo, you can hold the joysitck “down” and the servo will reach it’s maximum. It will stay at the max. When the joystick is moved “down” again, it will then reset it’s position (fully “up”). It does not do it for the other, “up”, direction. This is the same for both servos (X left/right, and Y up/down).

Maybe unrelated, but notable, is that in the “status” tab, I do not have full range of the sliding bar. The servos only move for the first ~75% of the bar, and do nothing for the last ~25% moving from left to right. This position can be seen on the first line for servo 1. Joystick positions 2 and 3 move the full length of the bar but return “home” in the position seen below.

image
maestro_settings.txt (3.3 KB)

Do you have a link to the specifications of your servos? It sounds like you are sending pulse widths way outside of the standard 1000-2000us range, which probably aren’t supported by your servos and could potentially damage them. If you change the Min and Max settings for to the Maestro defaults of 992 and 2000 respectively, do they work without those problems?

Brandon

That was it. I changed the Min and Max to the original settings and all the issues were solved. I guess I have to mess around now and find out the max limits I am able to use. Thanks!

Servo link below:

1 Like