|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Servo control with a joystick
Hello.
My team wants me to get a servo rigged to be controlled with a joystick. How do I convert joystick values (-1 thru. 1) to servo values (0 thru. 1)? |
|
#2
|
|||
|
|||
|
Re: Servo control with a joystick
Use the Servo class.
It has two methods you can use: set(double value) where value = 0.0 to 1.0 for full range of motion setAngle(double degrees) where degrees = position of the servo...values in excess of allowable range of motion simply saturate to the servo limit. The API assumes that the kit servos are linear. So to answer your question. Since the joys run from -1 to 1, you can simply use a multiple for the set method: Code:
Servo servo = new Servo(1);//Servo in PWM port 1 double servoIn = (joy.getX() +1)*0.5; // Command to servo servo.set(servoIn); That should do it. |
|
#3
|
|||
|
|||
|
Re: Servo control with a joystick
FYI, the general formula for scaling one range of values to another is:
Code:
newValue = newMax + (newMax - newMin) * (oldValue- oldMax) / (oldMax - oldMin) |
|
#4
|
||||
|
||||
|
Re: Servo control with a joystick
Thanks!
Just to verify: Code:
public double convert(double input) {
//newValue = newMax + (newMax - newMin) * (oldValue- oldMax) / (oldMax - oldMin)
input = 1 + (1 - 0) * (input- 1) / (1 - -1);
return input;
}
|
|
#5
|
|||
|
|||
|
Re: Servo control with a joystick
You can verify it by plugging in your input extremes (-1 to +1). I haven't had my coffee yet, but it doesn't seem like -1 converts to 0. Why not try the one I posted? KISS
|
|
#6
|
|||||
|
|||||
|
Re: Servo control with a joystick
I'm probably REALLY late to the party, but here's the solution I was taught.
double servOut = (stick.getRawAxis(1) + 1) / 2; -1.0 becomes 0 and +1.0 becomes 1.0 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with servo control | Jake The Man | NI LabVIEW | 2 | 09-02-2010 23:23 |
| Joystick-Servo control | Lumit | NI LabVIEW | 1 | 08-02-2010 23:21 |
| Camera servo control off of the Joystick axes | m3rc1l3ss | NI LabVIEW | 5 | 13-03-2009 20:00 |
| We need help with joystick control | Team ICE #1611 | Control System | 4 | 24-01-2005 15:57 |
| how do i control a piston with a joystick | Ryan Foley | Programming | 2 | 27-05-2003 17:13 |