View Single Post
  #6   Spotlight this post!  
Unread 22-09-2013, 11:57
magnets's Avatar
magnets magnets is offline
Registered User
no team
 
Join Date: Jun 2013
Rookie Year: 2012
Location: United States
Posts: 748
magnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond reputemagnets has a reputation beyond repute
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.