Moving Camera Servos With Joystick Button

Hello, I am looking for help on how to program in LabView how to move the servo with 2 joystick buttons. What I want it to do is move the camera servo 1 degree/increment everytime a press a joystick button. I could not figure this out on my own and any help or ideas would be greatly appreciated.

Create a setpoint for the servos using either a control, a shift register, or a feedback variable. Depending on the buttons, either increment or decrement the value of the setpoint. Then add the function to update the servo to the setpoint.

Greg McKaskle

Thanks for the speedy reply. That is what I thought needed to happen. Im still a little confused by what you said, could you show me a screenshot of that code please?

Sorry, I’m not at a PC right now. The code I’d write first is the joystick stuff. Inside the teleop you are either unbundling buttons already, or you are about to. Use the buttons to affect the servo setpoint with + or -. Then add a shift register to the loop initialized to centered I guess. Run the shift register wire to the cases doing the + and -. Prove the wire and test it out. Once you are happy with it, connect up the servo open, close, and the write angle.

Greg McKaskle

What Greg suggests will work great, just be careful about how often you change the angle. If you change the servo setpoint whenever the button is held down, then the servo will almost instantly go to it’s extreme angle. The reason being that the loop runs really fast, so you increment the setpoint very fast and it builds up to the max quickly.

I would check the time and only do the servo code when a certain amount of time has passed.

It might be easier to learn how to use a feedback node to remember what the state of the joystick button was the previous time through the code. I don’t have a copy of LabVIEW available, so I’ll see what I can do to describe a good way to react just once to a joystick button being pressed.

Wire the Joystick Get “Buttons” output to an “Unbundle by name” and select the desired button from the unbundle’s popup menu.
Wire the unbundle’s boolean output to one input of a boolean And gate, and also to the input to a feedback node.
Wire the output of the feedback node to a boolean Not.
Wire the output of the boolean Not to the other input of the boolean And.

The output of the boolan And will be true only during the single loop when the joystick button has changed from false to true.

You can use that single-time signal as the select input to a Case structure which passes a numeric input straight through to its output when false, and increments it by one when true.

Duplicate this entire process for another joystick input and another Case that decrements the numeric value.

Wire a numeric value through both Case structures and a shift register on the surrounding While loop. That way the joystick buttons will bump the value up or down by one each time one gets pressed. Use that value as the input to the Servo Set Angle. If you feel like it, run the value through a range check and coerce on its way through the process so that it never exceeds the proper range for a servo angle.

Thanks for all the help, still a bit confused, but having LabView in front of me will help. Alan, where exactly do I set a constant of the angle I want the servo to be at? It sounds like I create a constant then run a wire to the border of a case structure. I am also confused on what a feedback node is. Is it in the same menu as Not, And, Or functions?

The only constant you will want is the one connected to the left side of the shift register you create on your outermost while loop. The shift register will remember the angle you set the previous time through the loop so you can either use it as is or bump it up or down by one before using it. The input to the shift register sets the initial value it will have the very first time through the loop; you will probably want to choose a value that centers the servo.

I am also confused on what a feedback node is. Is it in the same menu as Not, And, Or functions?

You won’t find it in the boolean menu, because it isn’t a boolean operator. It works with booleans, but it also works with integers, floating point numbers, strings, enumerated values, bundles, basically whatever kind of data you feed it. I can’t remember exactly what the name of the palette is where it resides. Now is as good a time as any to learn how to use the search feature in the palette. Type in “feedback” and see what it finds.