Actualiser ftc2024-carlike.java

This commit is contained in:
Gzod01 2024-01-06 14:52:12 +00:00
parent 442a689436
commit d2ff9d7db6

View file

@ -20,6 +20,7 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
public void runOpMode() throws InterruptedException { public void runOpMode() throws InterruptedException {
float x; float x;
double y; double y;
double t;
String mode = "normal"; String mode = "normal";
boolean already_a = false; boolean already_a = false;
telemetry.addData("Status", "Initialized"); telemetry.addData("Status", "Initialized");
@ -30,6 +31,9 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
while (opModeIsActive()) { while (opModeIsActive()) {
x = gamepad1.left_stick_x;
y = gamepad1.left_stick_y;
t= gamepad1.left_trigger;
telemetry.addData("Status", "Running"); telemetry.addData("Status", "Running");
if(gamepad1.a && !already_a){ if(gamepad1.a && !already_a){
if(mode=="normal"){ if(mode=="normal"){
@ -47,21 +51,21 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
double lpower = 0.0; double lpower = 0.0;
double rpower = 0.0; double rpower = 0.0;
if(mode=="normal"){ if(mode=="normal"){
double ysign = gamepad1.left_stick_y>0?1.0:(gamepad1.left_stick_y<0?-1.0:0.0); double ysign = y>0?1.0:(y<0?-1.0:0.0);
double xsign = gamepad1.left_stick_x>0?1.0:(gamepad1.left_stick_x<0?-1.0:0.0); double xsign = x>0?1.0:(x<0?-1.0:0.0);
lpower = -ysign * gamepad1.left_trigger + (xsign-2*gamepad1.left_stick_x)*gamepad1.left_trigger; lpower = -ysign * t + (xsign-2*x)*t;
rpower = ysign * gamepad1.left_trigger + (xsign-2*gamepad1.left_stick_x)*gamepad1.left_trigger; rpower = ysign * t + (xsign-2*x)*t;
} }
else if (mode=="tank"){ else if (mode=="tank"){
lpower = -gamepad1.left_stick_y; lpower = -y;
rpower = gamepad1.right_stick_y; rpower = gamepad1.right_stick_y;
} }
else if (mode=="essaifranck"){ else if (mode=="essaifranck"){
double a = (gamepad1.left_stick_x-gamepad1.left_stick_y)/Math.pow(2,1/2); double a = (x-y)/Math.pow(2,1/2);
double b = (gamepad1.left_stick_x+gamepad1.left_stick_y)/Math.pow(2,1/2); double b = (x+y)/Math.pow(2,1/2);
double asqr_plus_bsqr = Math.pow(a,2)+Math.pow(b,2); double vmean = (a+b)/2;
lpower = (a/asqr_plus_bsqr)*Math.pow(gamepad1.left_trigger,1/2); lpower = (a/vmean)*t;
rpower = (b/asqr_plus_bsqr)*Math.pow(gamepad1.left_trigger,1/2); rpower = (b/vmean)*t;
} }
if(!(gamepad1.left_bumper)){ if(!(gamepad1.left_bumper)){
lpower/=3; lpower/=3;
@ -69,7 +73,7 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
} }
lm.setPower(lpower); lm.setPower(lpower);
rm.setPower(rpower); rm.setPower(rpower);
telemetry.addData("ltrigg",gamepad1.left_trigger); telemetry.addData("ltrigg",t);
telemetry.addData("mode",mode); telemetry.addData("mode",mode);
telemetry.update(); telemetry.update();
} }