This commit is contained in:
Zelina974 2024-04-05 16:47:18 +02:00
parent 6b385dc189
commit 2f476afc66

View file

@ -3,6 +3,7 @@ package org.firstinspires.ftc.teamcode;
//import FTC2024WeRobotControl; //a tester car pas sur que ça fonctionne //import FTC2024WeRobotControl; //a tester car pas sur que ça fonctionne
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.IMU; import com.qualcomm.robotcore.hardware.IMU;
import org.firstinspires.ftc.robotcore.external.navigation.YawPitchRollAngles; import org.firstinspires.ftc.robotcore.external.navigation.YawPitchRollAngles;
@ -22,150 +23,165 @@ import com.qualcomm.robotcore.util.ElapsedTime;
@Autonomous @Autonomous
public class Ftc2024_autonome_api extends LinearOpMode { public class Ftc2024_autonome_api extends LinearOpMode {
public String autonomous_mode; public String autonomous_mode;
public DcMotor lm; public DcMotor lm;
public DcMotor rm; public DcMotor rm;
public DcMotor harvestmotor; public DcMotorEx lmelevator;
public IMU imu; public DcMotorEx rmelevator;
public DcMotor harvestmotor;
public IMU imu;
public DcMotorEx rotation;
@Override @Override
public void runOpMode() { public void runOpMode() {
lm = hardwareMap.get(DcMotor.class, "blm"); lm = hardwareMap.get(DcMotor.class, "blm");
rm = hardwareMap.get(DcMotor.class, "brm"); rm = hardwareMap.get(DcMotor.class, "brm");
harvestmotor = hardwareMap.get(DcMotor.class, "moissonneuse"); harvestmotor = hardwareMap.get(DcMotor.class, "moissonneuse");
rotation = hardwareMap.get(DcMotorEx.class, "elvRot");
rm.setDirection(DcMotor.Direction.REVERSE); rm.setDirection(DcMotor.Direction.REVERSE);
rotation.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
imu = hardwareMap.get(IMU.class, "imu"); imu = hardwareMap.get(IMU.class, "imu");
imu.initialize( imu.initialize(
new IMU.Parameters( new IMU.Parameters(
new RevHubOrientationOnRobot( new RevHubOrientationOnRobot(
RevHubOrientationOnRobot.LogoFacingDirection.UP, RevHubOrientationOnRobot.LogoFacingDirection.UP,
RevHubOrientationOnRobot.UsbFacingDirection.FORWARD))); RevHubOrientationOnRobot.UsbFacingDirection.FORWARD)));
imu.resetYaw(); imu.resetYaw();
YawPitchRollAngles robotOrientation; YawPitchRollAngles robotOrientation;
FTC2024WeRobotControl robot = new FTC2024WeRobotControl(this); FTC2024WeRobotControl robot = new FTC2024WeRobotControl(this);
autonomous_mode = "b4d"; autonomous_mode = "b4d";
telemetry.addData("wait for start", ""); telemetry.addData("wait for start", "");
telemetry.update(); telemetry.update();
waitForStart(); waitForStart();
telemetry.addData("started", ""); telemetry.addData("started", "");
telemetry.update(); telemetry.update();
robotOrientation = imu.getRobotYawPitchRollAngles(); robotOrientation = imu.getRobotYawPitchRollAngles();
if (opModeIsRunning()) { if (opModeIsActive()) {
/* /*
* autonomous_mode differents possibles values respect the next scheme: * autonomous_mode differents possibles values respect the next scheme:
* team_color_shortcode + start_line_index + direct_or_no * team_color_shortcode + start_line_index + direct_or_no
* *
* team_color_shortcode = "b" for blue & "r" for red * team_color_shortcode = "b" for blue & "r" for red
* start_line_index = 4 or 2 see competition manual appendix B Tile location * start_line_index = 4 or 2 see competition manual appendix B Tile location
* plan * plan
* direct_or_no = "d" to direct go to pixel deliver zone or "n" to harvest * direct_or_no = "d" to direct go to pixel deliver zone or "n" to harvest
* pixels before to go in deliver zone * pixels before to go in deliver zone
* *
* default is "b4d" * default is "b4d"
*/ */
switch (autonomous_mode) { switch (autonomous_mode) {
default: default:
robot.forward(0.5); robot.boxElv();
robot.rotate((-90)); robot.forward(0.5);
robot.forward(1.5); robot.rotate((-90));
robot.harvest(-1); robot.forward(1.5);
robot.backward(1); robot.harvest(-1);
robot.harvest(0); robot.backward(1);
break; robot.harvest(0);
case ("b2d"): break;
robot.forward(0.5); case ("b2d"):
robot.rotate((-90)); robot.boxElv();
robot.forward(2.5); robot.forward(0.5);
robot.harvest(-1); robot.rotate((-90));
robot.backward(1); robot.forward(2.5);
robot.harvest(0); robot.harvest(-1);
break; robot.backward(1);
case ("r4d"): robot.harvest(0);
robot.forward(0.5); break;
robot.rotate(90); case ("r4d"):
robot.forward(1.5); robot.boxElv();
robot.harvest(-1); robot.forward(0.5);
robot.backward(1); robot.rotate(90);
robot.harvest(0); robot.forward(1.5);
break; robot.harvest(-1);
case ("r2d"): robot.backward(1);
robot.forward(0.5); robot.harvest(0);
robot.rotate(90); break;
robot.forward(2.5); case ("r2d"):
robot.harvest(-1); robot.boxElv();
robot.backward(1); robot.forward(0.5);
robot.harvest(0); robot.rotate(90);
break; robot.forward(2.5);
case ("b4n"): robot.harvest(-1);
robot.forward(1.5); robot.backward(1);
robot.rotate(90); robot.harvest(0);
robot.harvest(); break;
robot.forward(3); case ("b4n"):
robot.harvest(0); robot.boxElv();
robot.rotate(180); robot.forward(1.5);
robot.forward(1); robot.rotate(90);
robot.rotate(-90); robot.harvest();
robot.forward(1); robot.forward(3);
robot.rotate(90); robot.harvest(0);
robot.forward(2.5); robot.rotate(180);
robot.harvest(-1); robot.forward(1);
robot.backward(1); robot.rotate(-90);
robot.harvest(0); robot.forward(1);
break; robot.rotate(90);
case ("b2n"): robot.forward(2.5);
robot.forward(1.5); robot.harvest(-1);
robot.rotate(90); robot.backward(1);
robot.harvest(); robot.harvest(0);
robot.forward(1); break;
robot.harvest(0); case ("b2n"):
robot.rotate(180); robot.boxElv();
robot.forward(1); robot.forward(1.5);
robot.rotate(-90); robot.rotate(90);
robot.forward(1); robot.harvest();
robot.rotate(90); robot.forward(1);
robot.forward(2.5); robot.harvest(0);
robot.harvest(-1); robot.rotate(180);
robot.backward(1); robot.forward(1);
robot.harvest(0); robot.rotate(-90);
break; robot.forward(1);
case ("r4n"): robot.rotate(90);
robot.forward(1.5); robot.forward(2.5);
robot.rotate(-90); robot.harvest(-1);
robot.harvest(); robot.backward(1);
robot.forward(3); robot.harvest(0);
robot.harvest(0); break;
robot.rotate(180); case ("r4n"):
robot.forward(1); robot.boxElv();
robot.rotate(90); robot.forward(1.5);
robot.forward(1); robot.rotate(-90);
robot.rotate(-90); robot.harvest();
robot.forward(2.5); robot.forward(3);
robot.harvest(-1); robot.harvest(0);
robot.backward(1); robot.rotate(180);
robot.harvest(0); robot.forward(1);
break; robot.rotate(90);
case ("r2n"): robot.forward(1);
robot.forward(1.5); robot.rotate(-90);
robot.rotate(-90); robot.forward(2.5);
robot.harvest(); robot.harvest(-1);
robot.forward(1); robot.backward(1);
robot.harvest(0); robot.harvest(0);
robot.rotate(180); break;
robot.forward(1); case ("r2n"):
robot.rotate(90); robot.boxElv();
robot.forward(1); robot.forward(1.5);
robot.rotate(-90); robot.rotate(-90);
robot.forward(2.5); robot.harvest();
robot.harvest(-1); robot.forward(1);
robot.backward(1); robot.harvest(0);
robot.harvest(0); robot.rotate(180);
break; robot.forward(1);
} robot.rotate(90);
} robot.forward(1);
} robot.rotate(-90);
} robot.forward(2.5);
robot.harvest(-1);
robot.backward(1);
robot.harvest(0);
break;
}
}
}
}