Update
This commit is contained in:
parent
60d01e81f5
commit
07423e3692
1 changed files with 321 additions and 318 deletions
65
ftc_new.java
65
ftc_new.java
|
@ -25,8 +25,8 @@ import org.firstinspires.ftc.robotcore.external.navigation.Velocity;
|
|||
|
||||
@TeleOp(name = "WeRobot: FTC2024 NEW!!! Carlike", group = "WeRobot")
|
||||
public class WEROBOT_FTC2024_New_carlike extends LinearOpMode {
|
||||
public enum RobotMode{
|
||||
ESSAIFRANCK, ELINA, NORMAL, TANCK;
|
||||
public enum RobotMode{
|
||||
ESSAIFRANCK, ELINA, NORMAL, TANK;
|
||||
}
|
||||
|
||||
private DcMotor rm;
|
||||
|
@ -37,7 +37,7 @@ public class WEROBOT_FTC2024_New_carlike extends LinearOpMode {
|
|||
private DcMotorEx box;
|
||||
private DcMotorEx rotation;
|
||||
private ElapsedTime runtime = new ElapsedTime();
|
||||
|
||||
private RobotMode mode = RobotMode.ESSAIFRANCK;
|
||||
/*La fonction pour faire des exponentielles spécifiques
|
||||
* @param double t => le nombre dont on veut faire l'exponentielle
|
||||
* @return double une_exponentielle_très_spéciale_de_t*/
|
||||
|
@ -59,8 +59,6 @@ public class WEROBOT_FTC2024_New_carlike extends LinearOpMode {
|
|||
double t2;
|
||||
double t3;
|
||||
|
||||
String mode = "elina";
|
||||
|
||||
boolean already_b = false;
|
||||
boolean already_a = false;
|
||||
boolean already_x = false;
|
||||
|
@ -81,6 +79,7 @@ public class WEROBOT_FTC2024_New_carlike extends LinearOpMode {
|
|||
rm.setDirection(DcMotor.Direction.REVERSE);
|
||||
|
||||
moissoneuse = hardwareMap.get(DcMotor.class, "moissonneuse");
|
||||
moissoneuse.setDirection(DcMotor.Direction.REVERSE);
|
||||
|
||||
lmelevator = hardwareMap.get(DcMotorEx.class, "ltrselv");
|
||||
lmelevator.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
|
@ -136,21 +135,15 @@ public class WEROBOT_FTC2024_New_carlike extends LinearOpMode {
|
|||
t3 = helloexp(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
|
||||
|
||||
telemetry.addData("Status", "Running");
|
||||
// si le bouton a du gamepad 1 est appuyé et {already_a} est faux
|
||||
if (gamepad1.a && !already_a) {
|
||||
if (mode == "normal") {
|
||||
mode = "tank";
|
||||
} else if (mode == "tank") {
|
||||
mode = "essai franck";
|
||||
} else if (mode == "essai franck") {
|
||||
mode = "elina";
|
||||
} else {
|
||||
mode = "elina";
|
||||
}
|
||||
already_a = true;
|
||||
}
|
||||
|
||||
boxRot = gamepad1.right_stick_x;
|
||||
if (0.1<gamepad1.right_stick_x){
|
||||
boxRot = 0.2;
|
||||
} else if (-0.1>gamepad1.right_stick_x){
|
||||
boxRot = -0.2;
|
||||
}
|
||||
if (gamepad1.right_trigger>0){
|
||||
box.setPower(boxRot);
|
||||
}
|
||||
// if (boxRot <= 0){
|
||||
// signeBR = -1;
|
||||
// }
|
||||
|
@ -169,41 +162,51 @@ public class WEROBOT_FTC2024_New_carlike extends LinearOpMode {
|
|||
// }
|
||||
// }
|
||||
|
||||
box.setPower(boxRot);
|
||||
|
||||
|
||||
|
||||
if(gamepad1.a && !already_a){
|
||||
nextMode();
|
||||
already_a = true;
|
||||
}
|
||||
if (!gamepad1.a && already_a) {
|
||||
already_a = false;
|
||||
}
|
||||
double lpower = 0.0;
|
||||
double rpower = 0.0;
|
||||
if (mode == "normal") {
|
||||
|
||||
switch (mode) {
|
||||
case NORMAL:
|
||||
double ysign = Double.signum(y);
|
||||
double xsign = Double.signum(x);
|
||||
lpower = -ysign * t + (xsign - 2 * x) * t;
|
||||
rpower = ysign * t + (xsign - 2 * x) * t;
|
||||
} else if (mode == "tank") {
|
||||
break;
|
||||
|
||||
case TANK:
|
||||
lpower = -y;
|
||||
rpower = gamepad1.right_stick_y;
|
||||
}
|
||||
if (mode == "essaifranck") {
|
||||
break;
|
||||
|
||||
case ESSAIFRANCK :
|
||||
double a = (-y + x) / Math.pow(2, 1 / 2);
|
||||
double b = (-y - x) / Math.pow(2, 1 / 2);
|
||||
double vmean = (Math.abs(a) + Math.abs(b)) / 2;
|
||||
lpower = (a / vmean) * t2;
|
||||
rpower = (b / vmean) * t2;
|
||||
} else if (mode == "elina") {
|
||||
break;
|
||||
|
||||
case ELINA :
|
||||
double a = (-y + x) / Math.pow(2, 1 / 2);
|
||||
double b = (-y - x) / Math.pow(2, 1 / 2);
|
||||
double vmean = (Math.abs(a) + Math.abs(b)) / 2;
|
||||
double vmean = (Math.abs(a) + Math.abs(b)) / 4;
|
||||
lpower = (a / vmean) * t3;
|
||||
rpower = (b / vmean) * t3;
|
||||
break;
|
||||
}
|
||||
|
||||
if (gamepad1.left_trigger>0.1) {
|
||||
lpower /= 3;
|
||||
rpower /= 3;
|
||||
}
|
||||
|
||||
lm.setPower(lpower);
|
||||
rm.setPower(rpower);
|
||||
|
||||
|
@ -375,11 +378,11 @@ public class WEROBOT_FTC2024_New_carlike extends LinearOpMode {
|
|||
|
||||
telemetry.addData("x", x);
|
||||
telemetry.addData("y", y);
|
||||
telemetry.addData("mode", mode);
|
||||
telemetry.addData("lpow", lpower);
|
||||
telemetry.addData("rpow", rpower);
|
||||
telemetry.addData("ltrigg", t);
|
||||
telemetry.addData("t2", t2);
|
||||
telemetry.addData("manual mode", manualMode);
|
||||
telemetry.addData("rotation power",boxRot);
|
||||
telemetry.addData("mode manuel", manualMode);
|
||||
telemetry.addData("Position elevateur l", lmelevator.getCurrentPosition());
|
||||
|
@ -390,7 +393,7 @@ public class WEROBOT_FTC2024_New_carlike extends LinearOpMode {
|
|||
telemetry.update();
|
||||
}
|
||||
}
|
||||
public void nextMode(){
|
||||
public void nextMode(){
|
||||
this.RobotMode toNextMode;
|
||||
switch(this.mode){
|
||||
case (this.RobotMode.ESSAIFRANCK):
|
||||
|
|
Loading…
Reference in a new issue