03-02-2010 08:40 AM
Hello, I am trying to get joystick 2 to control the two servos that control the camera, I have included my begin vi and teleop vi.
If you folks could help i would really appreciate it
thanks John
03-02-2010 09:03 AM
Can you be more specific about the problem you're having? The major problem I see is that you're not consistent about your reference names; sometimes, you added a leading space. For example, in Begin, you name a reference "Joystick 2" but then in your TeleOp you look up " Joystick 2" (note the space at the beginning). I haven't looked at the implementation of Registry Get, but I expect that this mismatch will cause the lookup to fail. In Begin you open " Compressor" and " Servo Updown" (again, with extra spaces at the beginning).
You also open joystick 1 twice in Begin. You only need to open it once.
03-02-2010 09:46 AM
well at this point when i move the joystick 1 the motors move as expected but the servo also tries to move
I move joystick 2 and nothing happens.
I will check the ref names etc and make sure they match.
I will also check opening the joystick 1 twice,
thanks.
I also know that at this point i only have one servo in the teleop, but wanted to get one going at a time.
Have i set up the axis ref in the teleop execute loop correctly?
thanks
03-02-2010 10:00 AM
I wonder if Registry Get is returning the first available reference (in your case, for joystick 1) when it can't find the one you requested. It should also be returning an error at the Error Out terminal, which you could then wire to Servo Set Angle to prevent the servo from running if the lookup fails. That's just a theory to explain the behavior you're seeing. By the way, on a second look I noticed that you have an extra trailing space in "Joystick 2 " in Begin, in addition to the leading space in TeleOp.
Notice that Servo Set Angle expects an angle, but you're passing it a joystick value (from -1 to +1). You won't be able to move your servo very far. Also, you're matching the servo position to the joystick position, so if you stop pushing on the joystick it will spring back to 0 and the servo will follow. If that isn't the behavior you want, think about how you can use Servo Get Angle.
There should be a servo example somewhere in the examples that may help you.
03-02-2010 10:33 AM
I took out the space in joystick 2 and now i get a response from it to control the servo, What I would like to do is for the servo to move in response to the joystick,
at this point i have one or both servos reacting to either the x or y axis of joystick, and as you said when i move the joystick the servos move to the max position and then when i return the joystick to the original position the servos return to 0.
So here is what i would like help with,
1. When i move the joystick forward the tilt servo makes the servo go down and then when i pull on the joystick the tilt servo tilts the camera up.
2. Then if i move the joystick to the left the pan servo causes the camera to move left and then when i move the joystick to the right the camera moves right.
At this point i guess i need to know how i can get the joystick to determine the angle of either servo. I did look at the example vi for servos and that is how i would like the servos to move but not in response to the mouse but rather the joystick.
Thanks Much
03-02-2010 12:36 PM
The Servo Get Angle function will help you get the behavior you want. If that's not enough of a hint, start by thinking about what value you should write to the servo when the joystick is not being pushed.
03-02-2010 01:24 PM
I did figure out that i needed the get angle, i am just not sure how to wire it to the joystick.
could you tell me how to wire the get angle to joystick?
also how might i wire both servos to one joystick using the x and y axes?
thanks
03-02-2010 01:36 PM
Wiring the joystick to the two servos is simple - just use different axis, one per servo, and duplicate your existing code for the second axis. The node that you're using to get the X axis out of the cluster from the joystick is "Unbundle By Name." Right-click on it, choose "Add Element", then left-click on the new element and pick the Y axis. Alternatively you can resize the Unbundle by dragging the its handles. Wire the Y axis the same way you wire the X axis, but connect it to a second instance of Servo Set Angle and use the reference you created for that second servo.
You don't want to connect the joystick to Servo Get Angle. What you want to do is add to or subtract from the current angle to give you a new angle, and write that new angle to the servo. Then, when the joystick is at 0, you're continuously writing the same angle to the servo so it won't move. Of course, since the joystick gives you positive values in one direction and negative in the other, you don't actually need to subtract, you can just add. You may want to multiply (scale) the joystick value to control the rate at which the angle changes.
03-02-2010 08:08 PM
I was able to add and element to the joystick and now i have one joystick with the servos connected so that the x and y axis control both servos.
I am alittle confused how to accomplish the second task of getting the joystick connected to read the current angle.
If i don't want the joystick connected to the serrvo get angle then how should i connect it?
thanks much
John
03-03-2010 08:40 AM
The short answer is, connect Servo Get Angle to the joystick using the Add function. If that's not enough information, keep reading.
Maybe the misunderstanding here is how a servo works, so if you've got that already feel free to skip this. Unlike the motors driven by your Jagwires/Victors, the servo doesn't run when it receives a signal and stop when it gets no signal. It always needs a signal, and moves to a specific position based on the signal it receives. This is why you have Servo Set Angle versus Motor Set Speed for the other motor controllers. Sending a signal of 0 to the servo tells it to move to position 0, not to stop moving. To stop the servo you need to send it a constant signal.
Servo Get Angle returns the last angle that was written using Servo Set Angle; it does not return the actual servo angle. To keep the servo in a steady position you can connect Get Angle to Set Angle so that the servo will maintain position. Now, you want to move the servo, so you take the output of Servo Get Angle, add or subtract a few degrees, and write that new value to the servo. The next time through the loop, Get Angle returns the updated position that you set the previous time. The joystick value determines how many degrees to move. You need to add the joystick value (multiplied by some amount depending on desired speed) to the output of Get Angle. Does that make sense?