Actualiser WeRobot-Code.java

This commit is contained in:
Gzod01 2023-09-26 15:55:37 +00:00
parent 807649c996
commit 65844de4cb

View file

@ -2,6 +2,7 @@ package org.firstinspires.ftc.teamcode;
//package fr.gzod01.werobot.competition_singapour_2023; //package fr.gzod01.werobot.competition_singapour_2023;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.robot.Robot;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp; import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor; import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple; import com.qualcomm.robotcore.hardware.DcMotorSimple;
@ -20,141 +21,140 @@ public class DualDrive extends LinearOpMode {
public void runOpMode() { public void runOpMode() {
float x; float x;
double y; double y;
float g2x; float g2x;
boolean ismoissonactive=false; boolean ismoissonactive=false;
boolean ga; boolean ga;
boolean gy; boolean gy;
boolean preva =false; boolean preva =false;
flm = hardwareMap.get(DcMotor.class, "flm"); flm = hardwareMap.get(DcMotor.class, "flm");
frm = hardwareMap.get(DcMotor.class, "frm"); frm = hardwareMap.get(DcMotor.class, "frm");
blm = hardwareMap.get(DcMotor.class, "blm"); blm = hardwareMap.get(DcMotor.class, "blm");
brm = hardwareMap.get(DcMotor.class, "brm"); brm = hardwareMap.get(DcMotor.class, "brm");
moissonmotor = hardwareMap.get(DcMotor.class, "msn"); moissonmotor = hardwareMap.get(DcMotor.class, "msn");
launchermotor = hardwareMap.get(DcMotor.class, "lnc"); launchermotor = hardwareMap.get(DcMotor.class, "lnc");
mountmotor = hardwareMap.get(DcMotor.class, "mnt"); mountmotor = hardwareMap.get(DcMotor.class, "mnt");
waitForStart(); waitForStart();
while (opModeIsActive()) { while (opModeIsActive()) {
x = gamepad1.left_stick_x; x = gamepad1.left_stick_x;
y = -gamepad1.left_stick_y; y = -gamepad1.left_stick_y;
a = gamepad1.a; a = gamepad1.a;
gy = gamepad1.y; gy = gamepad1.y;
if(a & !preva){ if(a & !preva){
ismoissonactive=!ismoissonactive; ismoissonactive=!ismoissonactive;
preva=true; preva=true;
} }
if(!a & preva){ if(!a & preva){
preva =false; preva =false;
} }
if(ismoissonactive){ if(ismoissonactive){
moissonmotor.setPower(1); moissonmotor.setPower(1);
}else{ }else{
moissonmotor.setPower(0); moissonmotor.setPower(0);
} }
if(y){ if(y){
launchermotor.setPower(1); launchermotor.setPower(1);
}else{ }else{
launchermotor.setPower(0); launchermotor.setPower(0);
} }
if (gamepad1.dpad_down){ if (gamepad1.dpad_down){
mountmotor.setPower(-1); mountmotor.setPower(-1);
}else if (gamepad1.dpad_up){ }else if (gamepad1.dpad_up){
mountmotor.setPower(1); mountmotor.setPower(1);
}else{ }else{
mountmotor.setPower(0); mountmotor.setPower(0);
} }
g2x = gamepad1.right_stick_x; g2x = gamepad1.right_stick_x;
Robot.moves(x,y,flm, frm,blm,brm); Robot.moves(x,y,flm, frm,blm,brm);
Robot.Rotation(g2x, flm, frm, blm, brm); Robot.Rotation(g2x, flm, frm, blm, brm);
} }
} }
} }
public class Robot{ public class Robot{
public void moves(float x, double y, DcMotor flm, DcMotor frm, DcMotor blm, DcMotor brm){ public static void moves(float x, double y, DcMotor flm, DcMotor frm, DcMotor blm, DcMotor brm){
float approx = 0.15; float approx = 0.15;
boolean xnozero = (x<-approx || x>approx); boolean xnozero = (x<-approx || x>approx);
boolean ynozero = (y<-approx || y>approx); boolean ynozero = (y<-approx || y>approx);
if((xnozero & ynozero) || (xnozero || ynozero)){ if((xnozero & ynozero) || (xnozero || ynozero)){
//DO TRANSLATIONS //DO TRANSLATIONS
if(xnozero){ if(xnozero){
if(ynozzero){ if(ynozzero){
Robot.diagonal(x,y, flm,frm,blm,brm); Robot.diagonal(x,y, flm,frm,blm,brm);
}else{ }else{
Robot.horizontal(x,flm,frm,blm,brm); Robot.horizontal(x,flm,frm,blm,brm);
} }
}else{ }else{
Robot.vertical(y,flm,frm,blm,brm); Robot.vertical(y,flm,frm,blm,brm);
} }
} }
else{ else{
// NO TRANSLATIONS BECAUSE 0 SO STOP // NO TRANSLATIONS BECAUSE 0 SO STOP
flm.setPower(0); flm.setPower(0);
frm.setPower(0); frm.setPower(0);
blm.setPower(0); blm.setPower(0);
brm.setPower(0); brm.setPower(0);
} }
} }
public void diagonal(float x, double y, DcMotor flm, DcMotor frm,DcMotor blm,DcMotor brm){ public static void diagonal(float x, double y, DcMotor flm, DcMotor frm,DcMotor blm,DcMotor brm){
if(x>0){ if(x>0){
if(y>0){ if(y>0){
// North East // North East
Robot.movement(flm,frm,blm,brm,[1,0,0,1]); Robot.movement(flm,frm,blm,brm,{1,0,0,1});
} }else{
else{ //South East
//South East Robot.movement(flm,frm,blm,brm,{0,-1,-1,0});
Robot.movement(flm,frm,blm,brm,[0,-1,-1,0]); }
} }else{
}else{ if(y>0){
if(y>0){ //North West
//North West Robot.movement(flm,frm,blm,brm,{0,1,1,0});
Robot.movement(flm,frm,blm,brm,[0,1,1,0]); }
} else{
else{ //South West
//South West Robot.movement(flm,frm,blm,brm,{-1,0,0,-1});
Robot.movement(flm,frm,blm,brm,[-1,0,0,-1]); }
} }
} }
} public static void horizontal(float x,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
public void horizontal(float x,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){ if(x>0){
if(x>0){ Robot.movement(flm,frm,blm,brm,{1,-1,-1,1});
Robot.movement(flm,frm,blm,brm,[1,-1,-1,1]); }else{
}else{ Robot.movement(flm,frm,blm,brm,;{-1,1,1,-1});
Robot.movement(flm,frm,blm,brm,[-1,1,1,-1]); }
}
} }
public void vertical(double y,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){ public static void vertical(double y,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
if(y>0){ if(y>0){
Robot.movement(flm,frm,blm,brm,[1,1,1,1]); Robot.movement(flm,frm,blm,brm,{1,1,1,1});
}else{ }else{
Robot.movement(flm,frm,blm,brm,[-1,-1,-1,-1]); Robot.movement(flm,frm,blm,brm,{-1,-1,-1,-1});
} }
} }
public void movement(DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm,int[] list){ public static void movement(DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm,int[] list){
flm.setPower(list[0]); flm.setPower(list[0]);
frm.setPower(list[1]); frm.setPower(list[1]);
blm.setPower(list[2]); blm.setPower(list[2]);
brm.setPower(list[3]); brm.setPower(list[3]);
} }
public void Rotations(float g2x, DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){ public static void Rotations(float g2x, DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
float approx = 0.15; float approx = 0.15;
boolean xnozero = (g2x<-approx || g2x>approx); boolean xnozero = (g2x<-approx || g2x>approx);
if(xnozero){ if(xnozero){
if(x>0){ if(x>0){
Robot.movement(flm,frm,blm,brm,[1,-1,1,-1]); Robot.movement(flm,frm,blm,brm,{1,-1,1,-1});
}else{ }else{
Robot.movement(flm,frm,blm,brm,[-1,1,-1,1]); Robot.movement(flm,frm,blm,brm,{-1,1,-1,1});
} }
} }
} }
} }