2024-01-28 16:37:13 +01:00
|
|
|
package org.firstinspires.ftc.teamcode;
|
|
|
|
|
|
|
|
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
|
|
|
|
2024-02-11 15:48:03 +01:00
|
|
|
import com.qualcomm.robotcore.hardware.IMU;
|
2024-02-11 16:17:58 +01:00
|
|
|
import org.firstinspires.ftc.robotcore.external.navigation.YawPitchRollAngles;
|
2024-02-11 15:48:03 +01:00
|
|
|
import com.qualcomm.robotcore.hardware.ImuOrientationOnRobot;
|
|
|
|
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
|
2024-02-26 16:15:47 +01:00
|
|
|
|
|
|
|
import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
|
2024-02-11 15:48:03 +01:00
|
|
|
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
|
|
|
|
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
|
2024-02-26 16:15:47 +01:00
|
|
|
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
|
2024-02-11 15:48:03 +01:00
|
|
|
|
2024-02-26 16:15:47 +01:00
|
|
|
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
|
|
|
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
|
|
|
import com.qualcomm.robotcore.hardware.DcMotor;
|
|
|
|
import com.qualcomm.robotcore.util.ElapsedTime;
|
2024-01-28 16:37:13 +01:00
|
|
|
|
|
|
|
@Autonomous
|
|
|
|
|
2024-02-26 16:15:47 +01:00
|
|
|
public class ftc2024_autonome_test extends LinearOpMode {
|
2024-02-11 16:17:58 +01:00
|
|
|
private DcMotor rm;
|
|
|
|
private DcMotor lm;
|
|
|
|
private IMU imu;
|
2024-02-11 15:48:03 +01:00
|
|
|
|
2024-02-11 16:17:58 +01:00
|
|
|
@Override
|
2024-02-26 16:15:47 +01:00
|
|
|
|
2024-02-11 16:17:58 +01:00
|
|
|
public void runOpMode() {
|
2024-02-26 16:15:47 +01:00
|
|
|
lm = hardwareMap.get (DcMotor.class, "blm");
|
|
|
|
rm = hardwareMap.get (DcMotor.class, "brm");
|
|
|
|
|
|
|
|
rm.setDirection(DcMotor.Direction.REVERSE);
|
2024-02-11 16:17:58 +01:00
|
|
|
|
|
|
|
imu = hardwareMap.get(IMU.class, "imu");
|
|
|
|
imu.initialize(
|
|
|
|
new IMU.Parameters(
|
|
|
|
new RevHubOrientationOnRobot(
|
|
|
|
RevHubOrientationOnRobot.LogoFacingDirection.UP,
|
|
|
|
RevHubOrientationOnRobot.UsbFacingDirection.FORWARD
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
imu.resetYaw();
|
|
|
|
YawPitchRollAngles robotOrientation;
|
|
|
|
robotOrientation = imu.getRobotYawPitchRollAngles();
|
|
|
|
double Yaw = robotOrientation.getYaw(AngleUnit.DEGREES);
|
2024-02-26 16:15:47 +01:00
|
|
|
double yaw_sortie = 0.0;
|
2024-02-11 16:42:14 +01:00
|
|
|
|
2024-02-11 16:17:58 +01:00
|
|
|
waitForStart();
|
2024-02-11 15:48:03 +01:00
|
|
|
|
2024-02-26 16:15:47 +01:00
|
|
|
while (opModeIsActive()){
|
|
|
|
double [] lm_p = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1};
|
|
|
|
double [] rm_p = {-0.1,-0.2,-0.3,-0.4,-0.5,-0.6,-0.7,-0.8,-0.9,-1};
|
|
|
|
double [] x = new double[lm_p.length];
|
2024-02-26 16:35:33 +01:00
|
|
|
for(int i = 0; i< 9; i++){
|
2024-02-26 16:15:47 +01:00
|
|
|
while (opModeIsActive() && Yaw < 90){
|
|
|
|
lm.setPower(lm_p[i]);
|
|
|
|
rm.setPower(rm_p[i]);
|
|
|
|
robotOrientation = imu.getRobotYawPitchRollAngles();
|
|
|
|
Yaw = robotOrientation.getYaw(AngleUnit.DEGREES);
|
2024-02-26 16:35:33 +01:00
|
|
|
telemetry.addData("Yaw ", Yaw);
|
2024-02-26 16:15:47 +01:00
|
|
|
telemetry.update();
|
|
|
|
yaw_sortie = Yaw;
|
|
|
|
}
|
|
|
|
telemetry.addData("Yaw sortie", yaw_sortie);
|
2024-02-26 14:10:42 +01:00
|
|
|
telemetry.update();
|
|
|
|
Yaw = robotOrientation.getYaw(AngleUnit.DEGREES);
|
2024-02-26 16:15:47 +01:00
|
|
|
x [i]= Yaw - yaw_sortie;
|
2024-02-26 14:10:42 +01:00
|
|
|
|
2024-02-26 16:15:47 +01:00
|
|
|
imu.resetYaw();
|
2024-02-26 16:35:33 +01:00
|
|
|
Yaw = robotOrientation.getYaw(AngleUnit.DEGREES);
|
|
|
|
telemetry.addData("Yaw", Yaw);
|
|
|
|
telemetry.update();
|
|
|
|
}
|
|
|
|
while (opModeIsActive()){
|
|
|
|
telemetry.addData("0.1", x[0]);
|
|
|
|
telemetry.addData("0.2", x[1]);
|
|
|
|
telemetry.addData("0.3", x[2]);
|
|
|
|
telemetry.addData("0.4", x[3]);
|
|
|
|
telemetry.addData("0.5", x[4]);
|
|
|
|
telemetry.addData("0.6", x[5]);
|
|
|
|
telemetry.addData("0.7", x[6]);
|
|
|
|
telemetry.addData("0.8", x[7]);
|
|
|
|
telemetry.addData("0.9", x[8]);
|
|
|
|
telemetry.addData("1", x[9]);
|
2024-02-11 16:17:58 +01:00
|
|
|
}
|
2024-02-26 16:15:47 +01:00
|
|
|
}
|
2024-02-11 16:17:58 +01:00
|
|
|
}
|
2024-02-26 16:15:47 +01:00
|
|
|
}
|