|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#6
|
||||
|
||||
|
Re: Converting Two joystick values into a vector
Alright, let me get this straight.
You have a setup with two joysticks that are used in a tank drive set up, and from these two, you'd like to find the angle/magnitude. This is a little trickier, as you first need to find the amount of turn (x), then you need the amount of going forward (y) from the two axes used in tank drive. The speed of your turn is just the difference in the speeds of two sides of the robot, and the forward speed is the average of the two sticks. Here's some more java examples. NOTE:See my later post for corrections! Code:
public double getTheta(double x, double y){
return com.sun.squawk.util.MathUtils.atan2(y, x);
}
public double getR(double x, double y){
return Math.sqrt((x*x)+(y*y));
}
public double getX(){
return stick1.getY()-stick2.getY();
}
public double getY(){
return (stick1.getY()+stick2.getY())/2;
}
Code:
//you can get your values like this
double theta = getTheta(getX(), getY());
double r = getR(getX(), getY());
Last edited by magnets : 22-09-2013 at 15:10. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|