|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using xbox thumbstick to control servos on pan/tilt
Here's a good one.
I am using the right thumbstick (let's say axis 1 and 2) of an xbox controller to control the two servos for the pan and tilt for our axis camera. The servos are plugged right into the PWM8 and PWM9 spots on the roboRIO. Now, the thumbstick is already running these servos, but the problem is once you let the thumbstick go back to center, the servos also return to there zero position (far left and straight down). This is an issue when you have to constantly compensate to keep the camera in the right position at all times. What I need is the servos to start at the centered position (camera looking straight ahead) so that when you move the thumbstick around to view, the camera follows the joystick commands and stays there without returning to the far left and straight down position. Can anyone provide some sample coding for this? Thank you ahead of time for any effort to help! |
|
#2
|
|||||
|
|||||
|
Re: Using xbox thumbstick to control servos on pan/tilt
I don't fully understand what you're asking for. Do you want the camera position to follow the joystick, except for when the joystick is at neutral/center? Or do you want the joystick to control the camera's motion, such that the camera continuously tries to pan right while the joystick is right of center, or to stay in motion downward while the joystick is positioned down, and stay where it is when the joystick is returned to center?
Depending on what you really want, you might need to add a button that must be pressed in order to tell the camera servos when you want the joystick to control them. That way, releasing the button will make the camera position hold in place, regardless of the joystick position. |
|
#3
|
|||
|
|||
|
Re: Using xbox thumbstick to control servos on pan/tilt
Like Alan, I'm not sure what you want, but here are the two things I'd suggest.
1. Instead of setting the servo to the X and Y values of the joystick, use them to increment the value of the servo. You'll want to have a shift register that is initialized to zero, and add a fraction of the joystick each time through the loop. Send that to the servos. 2. Only update the servo value based on a button. I'm also testing to see if the code snippets work when attached like this, but they should at least show you what the code should look like. Greg McKaskle |
|
#4
|
|||
|
|||
|
Re: Using xbox thumbstick to control servos on pan/tilt
Right on, Alan,
Alan and Greg, I am looking for the second option you listed. When the thumbstick is moved to the right, the camera pans to the right. When the thumbstick is moved down, the camera pans down. When you release the thumbstick, the camera stays exactly in the position it is is, and stops moving. Thank you for your past and future help! ![]() |
|
#5
|
|||||
|
|||||
|
Re: Using xbox thumbstick to control servos on pan/tilt
Greg's first snippet is probably what you want.
The constant going into the multiply should be changed based on how quickly you want the servo to be able to move when the joystick is at full travel. If you make it 0.001, it will take at least a thousand loops of the code to pan all the way from one side to the other. In teleop, at 50 Hz or 20 ms per loop, that's a very long 20 seconds. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|