![]() |
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)? |
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 1That should do it. |
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) |
Re: Servo control with a joystick
Thanks!
Just to verify: Code:
public double convert(double input) { |
Re: Servo control with a joystick
Quote:
|
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 |
| All times are GMT -5. The time now is 09:43. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi