Log in

View Full Version : Controlling the camera with a joystick


Dakabt
22-01-2010, 16:42
Hello I was wondering how (if possible) I would be able to allow a joystick to be used to control the camera on the robot.

lscime
22-01-2010, 17:18
Assuming you mean that you want to move the servos on the camera mount using a joystick, yes it is indeed possible.

We've been playing around with such control for about a week. Here is a one method in LabVIEW. Essentially you can tell the servo "goal" position to increment by 1 (or another value) every time the main loop loops if a certain condition is met (i.e. a joystick in a particular position). The servos will constantly goal seek on this new position. We accomplished this by storing the "goal" position in a shift register and incrementing/decrementing/not changing this value depending on a case statement triggered by a joystick.

Again this in LabVIEW but the same principle should apply in Java and C.

Hope this helps,
Student Programmer, Team #2614.

non847
23-01-2010, 04:34
how about setting the angle of the servos proportionate to the axes of the joystick? works great!

EricWilliams
24-01-2010, 14:24
how about setting the angle of the servos proportionate to the axes of the joystick? works great!

This requires you to hold the joystick in a non-centered position if you want the camera to be anywhere but centered.

psychomonkey
31-01-2010, 20:13
Essentially you can tell the servo "goal" position to increment by 1 (or another value) every time the main loop loops if a certain condition is met (i.e. a joystick in a particular position). The servos will constantly goal seek on this new position. We accomplished this by storing the "goal" position in a shift register and incrementing/decrementing/not changing this value depending on a case statement triggered by a joystick.


So, if I understand correctly, In order to run this code, it must be in a while loop INSIDE the initial teleop case structure? I tried doing this and every time, I would get a watchdog error. I know that I didn't have a shift register. Do I need one on each side of the loop?:confused:

apalrd
31-01-2010, 20:38
No while loops inside while loops.
Use a shift register and put the code in the main loop.

Alan Anderson
31-01-2010, 21:06
We accomplished this by storing the "goal" position in a shift register and incrementing/decrementing/not changing this value depending on a case statement triggered by a joystick.

You can also do without the shift register. Since the FPGA knows what value you've set the servo to, you can use a Get Angle or Get Position vi to retrieve it, apply whatever modifications you wish to the value, and give it to a Set Angle or Set Position vi.

(If you're changing the value by extremely small amounts, you might need to watch out for rounding errors in the conversion between servo position and PWM value.)

psychomonkey
31-01-2010, 23:20
No while loops inside while loops.
Use a shift register and put the code in the main loop.

I'm not doing that. In the code this year, the teleop is all inside a case structure. Can I place a while loop inside a case structure?

psychomonkey
31-01-2010, 23:26
I'm not doing that. In the code this year, the teleop is all inside a case structure. Can I place a while loop inside a case structure?

You know what, I just realized that you were referring to the robot main.vi, not the teleop.vi. My apologies. So instead of using the while loop, I should just use comparison vi's on the joysticks to lead to increment vi's inside case structures?

psychomonkey
01-02-2010, 21:51
Got it, thanks.