Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mecanum2;
- public class Mecanum2 {
- static double x = -1;
- static double y = -1;
- static double rawTheta = 0;
- static double theta = 0;
- static double magnitude = 0;
- static double d = 0;
- static double FLPower;
- static double FRPower;
- static double BLPower;
- static double BRPower;
- public static void main(String[] args) {
- magnitude = Math.hypot(x, y);
- //Quadrant 1
- if (getTheta() >= 0 && getTheta() <= 90) {
- d = getTheta() / 90;
- FLPower = 1;
- FRPower = -1 + (2 * d);
- BLPower = -1 + (2 * d);
- BRPower = 1;
- }
- //Quadrant II
- else if (getTheta() > 90 && getTheta() <= 180) {
- d = (getTheta() - 90) / 90;
- FLPower = 1 - (2 * d);
- FRPower = 1;
- BLPower = 1;
- BRPower = 1 - (2 * d);
- }
- //Quadrant III
- else if (getTheta() > 180 && getTheta() <= 270) {
- d = (getTheta() - 180) / 90;
- FLPower = -1;
- FRPower = 1 - (2 * d);
- BLPower = 1 - (2 * d);
- BRPower = -1;
- }
- //Quadrant IV
- else if (getTheta() > 270 && getTheta() < 360) {
- d = (360 - getTheta()) / 90;
- FLPower = -1 + (2 * d);
- FRPower = -1;
- BLPower = -1;
- BRPower = -1 + (2 * d);
- }
- System.out.println(FLPower);
- System.out.println(FRPower);
- System.out.println(BLPower);
- System.out.println(BRPower);
- if(FLPower > FRPower && BRPower > BLPower && FLPower > 0){ //Motors should behave like this in QI
- System.out.println("Northeast");
- }
- else if(FLPower < FRPower && BRPower < BLPower && FRPower > 0){ //Motors should behave like this in QII
- System.out.println("Northwest");
- }
- else if(FLPower < FRPower && BRPower < BLPower && FLPower < 0){ //Motors should behave like this in QIII
- System.out.println("Southwest");
- }
- else if(FLPower > FRPower && BRPower > BLPower && FRPower < 0){ //Motors should behave like this in QIV
- System.out.println("Southeast");
- }
- }
- public static double getTheta(){
- if(x != 0){
- rawTheta = Math.atan2(y, x) * 180 / Math.PI;
- if(rawTheta > 0){
- theta = rawTheta;
- }
- else if(rawTheta < 0){
- theta = 360 + rawTheta; //Negative angle measures in quadrants 3 and 4 are converted to angles from 180-360
- }
- }
- else if(x == 0){ //Required because the atan function divides y by x and you can't divide by 0
- if(y > 0){
- theta = 90;
- }
- else if(y < 0){
- theta = 270;
- }
- }
- else if(y == 0){ //Not sure if I need this but I'll keep it in here for consistency.
- if(x > 0){
- theta = 0;
- }
- else if(x < 0){
- theta = 180;
- }
- }
- else{
- }
- return theta;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement