-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMecanumWheels.java
102 lines (90 loc) · 3.54 KB
/
MecanumWheels.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple.Direction;
import com.qualcomm.robotcore.util.Range;
class MecanumWheels {
// initializes the 4 local Powers & Motors, & sets them to 0
private DcMotor frontRight;
private double frontRightPower = 0;
private DcMotor frontLeft;
private double frontLeftPower = 0;
private DcMotor backRight;
private double backRightPower = 0;
private CRServo backLeft;
private double backLeftPower = 0;
public MecanumWheels (CRServo leftBack, DcMotor leftFront, DcMotor rightBack, DcMotor rightFront){
// sets the local motors to Graber's motors
frontRight = rightFront;
frontLeft = leftFront;
backRight = rightBack;
backLeft = leftBack;
//sets the local motor's directions to forward
frontLeft.setDirection(Direction.FORWARD);
frontRight.setDirection(Direction.FORWARD);
backLeft.setDirection(Direction.REVERSE);
backRight.setDirection(Direction.FORWARD);
}
// sets the 4 local to what Graber gives when the method is called
public void drive (double rx, double ry, double lx, double ly) {
double FR = -ry;
double FL = ly;
double BR = -ry;
double BL = ly;
if (rx >= 0.25 || lx > 0.25) {
double lrx = (rx + lx) / 2;
FR += -lrx;
FL += -lrx;
BR += lrx;
BL += lrx;
}
if (lx <= -0.25 || rx <= -0.25) {
double llx = (rx + lx) / 2;
FR += -llx;
FL += -llx;
BR += llx;
BL += llx;
}
FR = Range.clip(FR, -1, 1);
FL = Range.clip(FL, -1, 1);
BR = Range.clip(BR, -1, 1);
BL = Range.clip(BL, -1, 1);
frontRight.setPower(FR);
frontLeft.setPower(FL);
backRight.setPower(BR);
backLeft.setPower(BL);
}
// if (rx < 0.25 && rx > -0.25 && lx > -0.25 && lx < 0.25) {
// frontRight.setPower(-ry);
// frontLeft.setPower(ly);
// backRight.setPower(-ry);
// backLeft.setPower(ly);
// }
// if (rx >= 0.25 || lx > 0.25 ) {
// double lrx = (rx + lx)/2;
// frontRight.setPower(-lrx);
// frontLeft.setPower(-lrx);
// backRight.setPower(lrx);
// backLeft.setPower(lrx);
// }
// if (lx <= -0.25 || rx <= -0.25) {
// double llx = (rx + lx)/2;
// frontRight.setPower(-llx);
// frontLeft.setPower(-llx);
// backRight.setPower(llx);
// backLeft.setPower(llx);
// }
// setters
// private void setFrontRightPower(double angle, double magnitude, double rotationalVelocity) {
// frontRightPower = (-(Math.sin(angle - (Math.PI/4.0) )) * magnitude - rotationalVelocity)/2;
// }
// private void setFrontLeftPower(double angle, double magnitude, double rotationalVelocity) {
// frontLeftPower = (Math.sin(angle + (Math.PI/4.0) ) * magnitude + rotationalVelocity)/2;
// }
// private void setBackRightPower(double angle, double magnitude, double rotationalVelocity) {
// backRightPower = (-(Math.sin(angle + (Math.PI/4.0) )) * magnitude - rotationalVelocity)/2;
// }
// private void setBackLeftPower(double angle, double magnitude, double rotationalVelocity) {
// backLeftPower = (Math.sin(angle - (Math.PI/4.0) ) * magnitude + rotationalVelocity)/2;
// }
}