Actualiser WeRobot-Code.java
This commit is contained in:
parent
807649c996
commit
65844de4cb
1 changed files with 120 additions and 120 deletions
|
@ -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)){
|
|
||||||
//DO TRANSLATIONS
|
|
||||||
if(xnozero){
|
|
||||||
if(ynozzero){
|
|
||||||
Robot.diagonal(x,y, flm,frm,blm,brm);
|
|
||||||
}else{
|
|
||||||
Robot.horizontal(x,flm,frm,blm,brm);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
Robot.vertical(y,flm,frm,blm,brm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// NO TRANSLATIONS BECAUSE 0 SO STOP
|
|
||||||
flm.setPower(0);
|
|
||||||
frm.setPower(0);
|
|
||||||
blm.setPower(0);
|
|
||||||
brm.setPower(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if((xnozero & ynozero) || (xnozero || ynozero)){
|
||||||
public void diagonal(float x, double y, DcMotor flm, DcMotor frm,DcMotor blm,DcMotor brm){
|
//DO TRANSLATIONS
|
||||||
if(x>0){
|
if(xnozero){
|
||||||
if(y>0){
|
if(ynozzero){
|
||||||
// North East
|
Robot.diagonal(x,y, flm,frm,blm,brm);
|
||||||
Robot.movement(flm,frm,blm,brm,[1,0,0,1]);
|
}else{
|
||||||
|
Robot.horizontal(x,flm,frm,blm,brm);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Robot.vertical(y,flm,frm,blm,brm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// NO TRANSLATIONS BECAUSE 0 SO STOP
|
||||||
|
flm.setPower(0);
|
||||||
|
frm.setPower(0);
|
||||||
|
blm.setPower(0);
|
||||||
|
brm.setPower(0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
public static void diagonal(float x, double y, DcMotor flm, DcMotor frm,DcMotor blm,DcMotor brm){
|
||||||
//South East
|
if(x>0){
|
||||||
Robot.movement(flm,frm,blm,brm,[0,-1,-1,0]);
|
if(y>0){
|
||||||
}
|
// North East
|
||||||
}else{
|
Robot.movement(flm,frm,blm,brm,{1,0,0,1});
|
||||||
if(y>0){
|
|
||||||
//North West
|
|
||||||
Robot.movement(flm,frm,blm,brm,[0,1,1,0]);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
//South West
|
|
||||||
Robot.movement(flm,frm,blm,brm,[-1,0,0,-1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void horizontal(float x,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
|
||||||
if(x>0){
|
|
||||||
Robot.movement(flm,frm,blm,brm,[1,-1,-1,1]);
|
|
||||||
}else{
|
|
||||||
Robot.movement(flm,frm,blm,brm,[-1,1,1,-1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//South East
|
||||||
|
Robot.movement(flm,frm,blm,brm,{0,-1,-1,0});
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(y>0){
|
||||||
|
//North West
|
||||||
|
Robot.movement(flm,frm,blm,brm,{0,1,1,0});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//South West
|
||||||
|
Robot.movement(flm,frm,blm,brm,{-1,0,0,-1});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void horizontal(float x,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
||||||
|
if(x>0){
|
||||||
|
Robot.movement(flm,frm,blm,brm,{1,-1,-1,1});
|
||||||
|
}else{
|
||||||
|
Robot.movement(flm,frm,blm,brm,;{-1,1,1,-1});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
public void vertical(double y,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
|
||||||
if(y>0){
|
|
||||||
Robot.movement(flm,frm,blm,brm,[1,1,1,1]);
|
|
||||||
}else{
|
|
||||||
Robot.movement(flm,frm,blm,brm,[-1,-1,-1,-1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public void movement(DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm,int[] list){
|
|
||||||
flm.setPower(list[0]);
|
|
||||||
frm.setPower(list[1]);
|
|
||||||
blm.setPower(list[2]);
|
|
||||||
brm.setPower(list[3]);
|
|
||||||
}
|
|
||||||
public void Rotations(float g2x, DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
|
||||||
float approx = 0.15;
|
|
||||||
boolean xnozero = (g2x<-approx || g2x>approx);
|
|
||||||
if(xnozero){
|
|
||||||
if(x>0){
|
|
||||||
Robot.movement(flm,frm,blm,brm,[1,-1,1,-1]);
|
|
||||||
}else{
|
|
||||||
Robot.movement(flm,frm,blm,brm,[-1,1,-1,1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
public static void vertical(double y,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
||||||
|
if(y>0){
|
||||||
|
Robot.movement(flm,frm,blm,brm,{1,1,1,1});
|
||||||
|
}else{
|
||||||
|
Robot.movement(flm,frm,blm,brm,{-1,-1,-1,-1});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public static void movement(DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm,int[] list){
|
||||||
|
flm.setPower(list[0]);
|
||||||
|
frm.setPower(list[1]);
|
||||||
|
blm.setPower(list[2]);
|
||||||
|
brm.setPower(list[3]);
|
||||||
|
}
|
||||||
|
public static void Rotations(float g2x, DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
||||||
|
float approx = 0.15;
|
||||||
|
boolean xnozero = (g2x<-approx || g2x>approx);
|
||||||
|
if(xnozero){
|
||||||
|
if(x>0){
|
||||||
|
Robot.movement(flm,frm,blm,brm,{1,-1,1,-1});
|
||||||
|
}else{
|
||||||
|
Robot.movement(flm,frm,blm,brm,{-1,1,-1,1});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue