helloworldhellwoorldeofoehfafihuofijoahfgyioafjpafhzguirg uvuizerurg_ozerygvoiuhrgreqiogrehh
This commit is contained in:
parent
71fd015dc6
commit
09b9a7bc9c
1 changed files with 55 additions and 38 deletions
|
@ -7,7 +7,7 @@ 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;
|
||||||
|
|
||||||
@TeleOp(name="WeRobot: FGC2023 OpMode", group="WeRobot")
|
@TeleOp(name="WeRobot: FGC2023", group="WeRobot")
|
||||||
public class WeRobot_FGC2023_GZod01 extends LinearOpMode {
|
public class WeRobot_FGC2023_GZod01 extends LinearOpMode {
|
||||||
private DcMotor flm;
|
private DcMotor flm;
|
||||||
private DcMotor frm;
|
private DcMotor frm;
|
||||||
|
@ -33,6 +33,7 @@ public class WeRobot_FGC2023_GZod01 extends LinearOpMode {
|
||||||
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");
|
||||||
|
WRRobot wr = new WRRobot(flm,frm,blm,brm);
|
||||||
waitForStart();
|
waitForStart();
|
||||||
|
|
||||||
while (opModeIsActive()) {
|
while (opModeIsActive()) {
|
||||||
|
@ -67,92 +68,108 @@ public class WeRobot_FGC2023_GZod01 extends LinearOpMode {
|
||||||
|
|
||||||
|
|
||||||
g2x = gamepad1.right_stick_x;
|
g2x = gamepad1.right_stick_x;
|
||||||
WRRobot.moves(x,y,flm, frm,blm,brm);
|
wr.moves(x,y );
|
||||||
WRRobot.Rotation(g2x, flm, frm, blm, brm);
|
wr.Rotation(g2x );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class WRRobot{
|
class WRRobot{
|
||||||
public static void moves(float x, double y, DcMotor flm, DcMotor frm, DcMotor blm, DcMotor brm){
|
private DcMotor flm;
|
||||||
|
private DcMotor frm;
|
||||||
|
private DcMotor blm;
|
||||||
|
private DcMotor brm;
|
||||||
|
public WRRobot(DcMotor cflm,DcMotor cfrm,DcMotor cblm,DcMotor cbrm){
|
||||||
|
flm = cflm;
|
||||||
|
frm = cfrm;
|
||||||
|
blm = cblm;
|
||||||
|
brm = cbrm;
|
||||||
|
}
|
||||||
|
public void moves(float x, double y){
|
||||||
double approx = 0.15;
|
double 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(!(Math.abs(x)>approx || Math.abs(y)>approx)){
|
||||||
//DO TRANSLATIONS
|
|
||||||
if(xnozero){
|
|
||||||
if(ynozero){
|
|
||||||
WRRobot.diagonal(x,y, flm,frm,blm,brm);
|
|
||||||
}else{
|
|
||||||
WRRobot.horizontal(x,flm,frm,blm,brm);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
WRRobot.vertical(y,flm,frm,blm,brm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// 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);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//DO TRANSLATIONS
|
||||||
|
if(Math.abs(x)>approx){
|
||||||
|
if(Math.abs(y)>approx){
|
||||||
|
diagonal(x,y);
|
||||||
|
}else{
|
||||||
|
horizontal(x);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
vertical(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void diagonal(float x, double y, DcMotor flm, DcMotor frm,DcMotor blm,DcMotor brm){
|
public void diagonal(float x, double y){
|
||||||
|
double pow = Math.abs(x+y)/2;
|
||||||
if(x>0){
|
if(x>0){
|
||||||
if(y>0){
|
if(y>0){
|
||||||
// North East
|
// North East
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{1,0,0,1});
|
movement(new double[]{pow,0,0,-pow});
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
//South East
|
//South East
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{0,-1,-1,0});
|
movement(new double[]{0,pow,-pow,0});
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(y>0){
|
if(y>0){
|
||||||
//North West
|
//North West
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{0,1,1,0});
|
movement(new double[]{0,-pow,pow,0});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//South West
|
//South West
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{-1,0,0,-1});
|
movement(new double[]{-pow,0,0,pow});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void horizontal(float x,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
public void horizontal(float x){
|
||||||
|
double pow = Math.abs(x);
|
||||||
if(x>0){
|
if(x>0){
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{1,-1,-1,1});
|
movement(new double[]{pow,pow,-pow,-pow});
|
||||||
}else{
|
}else{
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{-1,1,1,-1});
|
movement(new double[]{-pow,-pow,pow,pow});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void vertical(double y,DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
public void vertical(double y){
|
||||||
|
double pow = Math.abs(y);
|
||||||
if(y>0){
|
if(y>0){
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{1,1,1,1});
|
movement(new double[]{pow,-pow,pow,-pow});
|
||||||
}else{
|
}else{
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{-1,-1,-1,-1});
|
movement(new double[]{pow,-pow,pow,-pow});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void movement(DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm,int[] list){
|
public void movement(double[] 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 static void Rotation(float g2x, DcMotor flm,DcMotor frm,DcMotor blm,DcMotor brm){
|
|
||||||
|
/*
|
||||||
|
* @param g2x is the x coordinates of the right joystick
|
||||||
|
*/
|
||||||
|
public void Rotation(float g2x){
|
||||||
double approx = 0.15;
|
double approx = 0.15;
|
||||||
boolean xnozero = (g2x<-approx || g2x>approx);
|
boolean xnozero = (g2x<-approx || g2x>approx);
|
||||||
if(xnozero){
|
double pow = Math.abs(g2x);
|
||||||
if(g2x>0){
|
if (!xnozero) return;
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{1,-1,1,-1});
|
if (g2x > 0) {
|
||||||
}else{
|
movement(new double[]{pow,pow,pow,pow});
|
||||||
WRRobot.movement(flm,frm,blm,brm,new int[]{-1,1,-1,1});
|
} else {
|
||||||
}
|
movement(new double[]{-pow,-pow,-pow,-pow});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue