2024-01-28 16:37:13 +01:00
|
|
|
package org.firstinspires.ftc.teamcode;
|
|
|
|
|
|
|
|
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
|
|
|
import com.qualcomm.robotcore.hardware.AnalogInput;
|
|
|
|
import com.qualcomm.robotcore.hardware.Gyroscope;
|
|
|
|
import com.qualcomm.robotcore.hardware.ColorSensor;
|
|
|
|
import com.qualcomm.robotcore.hardware.Servo;
|
|
|
|
import com.qualcomm.robotcore.hardware.DigitalChannel;
|
|
|
|
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
|
|
|
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
|
|
|
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
|
|
|
import com.qualcomm.robotcore.hardware.DcMotor;
|
|
|
|
import com.qualcomm.robotcore.hardware.DcMotorSimple;
|
|
|
|
import com.qualcomm.robotcore.util.ElapsedTime;
|
|
|
|
|
|
|
|
|
|
|
|
@Autonomous
|
|
|
|
|
2024-01-28 16:47:11 +01:00
|
|
|
public class ftc2024_autonome extends LinearOpMode {
|
|
|
|
private DcMotor rm;
|
|
|
|
private DcMotor lm;
|
2024-01-28 16:37:13 +01:00
|
|
|
private ElapsedTime runtime = new ElapsedTime();
|
2024-02-04 14:46:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
public double time_for_dist(double speed, double dist){
|
|
|
|
return (double) (dist/speed);
|
|
|
|
}
|
2024-01-28 16:37:13 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void runOpMode() {
|
2024-01-28 16:47:11 +01:00
|
|
|
lm = hardwareMap.get(DcMotor.class, "blm");
|
|
|
|
rm = hardwareMap.get(DcMotor.class, "brm");
|
2024-02-04 14:42:33 +01:00
|
|
|
rm.setDirection(DcMotorSimple.Direction.REVERSE);
|
2024-01-28 16:37:13 +01:00
|
|
|
telemetry.addData("Status", "Initialized");
|
|
|
|
telemetry.update();
|
2024-02-04 14:42:33 +01:00
|
|
|
double tour_par_minute = 300.0;
|
|
|
|
double wheel_width = 9.0e-2;
|
|
|
|
double wheel_rayon = (wheel_width)/2;
|
|
|
|
double wheel_perimeter = wheel_rayon*2*Math.PI;
|
|
|
|
double speed = (tour_par_minute/60)*wheel_perimeter;//dist per second
|
|
|
|
boolean mode = false;
|
2024-01-28 16:37:13 +01:00
|
|
|
// Wait for the game to start (driver presses PLAY)
|
|
|
|
waitForStart();
|
|
|
|
|
2024-02-04 14:42:33 +01:00
|
|
|
runtime.reset();
|
|
|
|
if (mode){
|
|
|
|
//mode Elina
|
2024-02-04 15:11:23 +01:00
|
|
|
while (opModeIsActive() && (runtime.seconds() <= 41*maths.PI/4/speed)) {
|
2024-02-04 14:42:33 +01:00
|
|
|
lm.setPower(1);
|
|
|
|
rm.setPower(-1);
|
|
|
|
telemetry.addData("Leg 1", runtime.seconds());
|
|
|
|
telemetry.update();
|
|
|
|
}
|
|
|
|
runtime.reset();
|
2024-02-04 15:11:23 +01:00
|
|
|
while (opModeIsActive() && (runtime.seconds() <= 121.92/speed)) {
|
2024-02-04 14:42:33 +01:00
|
|
|
lm.setPower(1);
|
|
|
|
rm.setPower(1);
|
|
|
|
telemetry.addData("Leg 2", runtime.seconds());
|
|
|
|
telemetry.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
double[][] operations = {
|
2024-02-04 14:54:03 +01:00
|
|
|
{-1.0,1.0}, // vectors
|
|
|
|
{1.0,1.0},
|
|
|
|
{-1.0,1.0},
|
|
|
|
{-1.0,-1.0},
|
|
|
|
{1.0,-1.0}
|
2024-02-04 14:42:33 +01:00
|
|
|
};
|
|
|
|
//mode Aurelien
|
|
|
|
for(int i = 0; i<operations.length; i++){
|
2024-02-04 15:10:54 +01:00
|
|
|
double[] vec = operations[i];
|
2024-02-04 14:54:03 +01:00
|
|
|
double x = vec[0];
|
|
|
|
double y = vec[1];
|
|
|
|
double total_dist = (double) math.sqrt(Math.pow(y,2)+Math.pow(x,2));
|
|
|
|
double time = time_for_dist(speed, time);
|
|
|
|
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;
|
|
|
|
lmvalue = (a/vmean);
|
|
|
|
rmvalue = (b/vmean);
|
2024-02-04 14:42:33 +01:00
|
|
|
runtime.reset();
|
|
|
|
while (opModeIsActive() && (runtime.seconds() <= time)) {
|
|
|
|
lm.setPower(lmvalue);
|
|
|
|
rm.setPower(rmvalue);
|
|
|
|
telemetry.addData("Runtime Seconds", runtime.seconds());
|
|
|
|
telemetry.addData("current_operation",operations[i]);
|
|
|
|
telemetry.addData("current_op_id",i);
|
|
|
|
telemetry.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-28 16:55:48 +01:00
|
|
|
// run until the end of the match (driver presses STOP
|
2024-01-28 16:37:13 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-01-28 16:55:48 +01:00
|
|
|
|