This commit is contained in:
Zelina974 2024-03-31 15:40:48 +02:00
commit 2f6da412ad
6 changed files with 315 additions and 247 deletions

View file

@ -38,6 +38,9 @@ public class FTC2024WeRobotControl {
* the width size of the tiles on the ground in metres
*/
private final double ground_tiles_width = 61.0e-2; // metres
//
private final double defaultspeed = 0.6;
private final double defaultanglespeed = 0.4;
private ElapsedTime timer;
@ -102,7 +105,7 @@ public class FTC2024WeRobotControl {
}
public void forward(double n_tiles){
this.forward(n_tiles,1);
this.forward(n_tiles,this.defaultspeed);
}
/*
@ -119,7 +122,7 @@ public class FTC2024WeRobotControl {
}
public void backward(double n_tiles){
this.backward(n_tiles,1);
this.backward(n_tiles,this.defaultspeed);
}
/*
@ -167,7 +170,7 @@ public class FTC2024WeRobotControl {
Parent.rm.setPower(0);
}
public void rotate(double angle){
this.rotate(angle,1.0);
this.rotate(angle,this.defaultanglespeed);
}
public void test_forward_10_and_rotate_20deg(){

View file

@ -55,7 +55,7 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
return (Math.exp(5 * t) - 1) / (Math.exp(5) - 1);
}
private void tele(string name, string data) {
private void tele(String name, String data) {
telemetry.addData(name, data);
telemetry.update();
}
@ -86,27 +86,27 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
// le mode du robot
String mode = "normal";
String mode = "elina";
// b est il déjà préssé?
boolean already_b = false;
// a est il déjà préssé?
boolean already_a = false;
// x est il déjà préssé?
boolean already_x = false;
boolean already_y = false;
boolean already_up = false;
boolean already_down = false;
boolean sinking = false;
telemetry.addData("Status", "Initialized");
telemetry.update();
// telemetry.update();
lm = hardwareMap.get(DcMotor.class, "blm");
@ -119,6 +119,7 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
lmelevator.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
rmelevator = hardwareMap.get(DcMotorEx.class, "rtrselv");
rmelevator.setDirection(DcMotor.Direction.REVERSE);
rmelevator.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rmelevator.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
@ -131,6 +132,13 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
box.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
imu = hardwareMap.get(IMU.class, "imu");
// rotation positions: 20° pos initiale par rapport au sol
rotation.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rotation.setVelocity(700, AngleUnit.DEGREES);
rotation.setTargetPosition(40*288/360);
imu.initialize(
@ -167,7 +175,12 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
* en attente du démarrage
*/
waitForStart();
while (opModeIsActive()){
telemetry.addData("rotation target Pos", rotation.getTargetPosition());
telemetry.addData("rotation Pos", rotation.getCurrentPosition());
telemetry.addData("rotation velocity", rotation.getVelocity());
telemetry.update();
}
/*
* le robot a démarré, le tant que le robot est activé et donc qu'il n'a pas été
* stoppé:
@ -203,7 +216,7 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
/*
* si le bouton a du gamepad 1 est appuyé et {already_a} est faux
*/
if (gamepad1.a && !already_a) {
/*if (gamepad1.a && !already_a) {
if (mode == "normal") {
mode = "tank";
} else if (mode == "tank") {
@ -211,16 +224,16 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
} else if (mode == "essaifranck") {
mode = "elina";
} else {
mode = "normal";
mode = "elina";
}
already_a = true;
}
}*/
if (!gamepad1.a && already_a) {
already_a = false;
}
double lpower = 0.0;
double rpower = 0.0;
if (mode == "normal") {
/*if (mode == "normal") {
double ysign = y > 0 ? 1.0 : (y < 0 ? -1.0 : 0.0);
double xsign = x > 0 ? 1.0 : (x < 0 ? -1.0 : 0.0);
lpower = -ysign * t + (xsign - 2 * x) * t;
@ -229,8 +242,8 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
} else if (mode == "tank") {
lpower = -y;
rpower = gamepad1.right_stick_y;
tele("mode", "tank");
} else if (mode == "essaifranck") {
tele("mode", "tank");*/
if (mode == "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;
@ -245,7 +258,7 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
rpower = (b / vmean) * t3;
tele("mode", "Elina");
}
if (!(gamepad1.left_bumper)) {
if (gamepad1.left_trigger>0.1) {
lpower /= 3;
rpower /= 3;
}
@ -267,27 +280,82 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
if (!gamepad1.b && already_b) {
already_b = false;
}
if ((gamepad1.dpad_up && !already_up)^(gamepad1.dpad_down && !already_down)){
if (sinking && Math.abs(lmelevator.getCurrentPosition()-90)<=5 && Math.abs(rmelevator.getCurrentPosition()-90)<=5){
lmelevator.setVelocity(100);
rmelevator.setVelocity(100);
Long targetPosLong = (Long) Math.round(288*3.45);
lmelevator.setTargetPosition(0);
rmelevator.setTargetPosition(0);
lmelevator.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rmelevator.setMode(DcMotor.RunMode.RUN_TO_POSITION);
}
if ((gamepad1.dpad_up && !already_up)^(gamepad1.dpad_down && !already_down)){
lmelevator.setVelocity(600);
rmelevator.setVelocity(600);
Long targetPosLong = (Long) Math.round(288*3.4);
int targetPos = targetPosLong.intValue();
if (gamepad1.dpad_down){
targetPos = 0;
targetPos = 90;
already_down = true;
sinking = true;
}else{
already_up = true;
sinking = false;
}
lmelevator.setTargetPosition(targetPos);
rmelevator.setTargetPosition(targetPos);
lmelevator.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rmelevator.setMode(DcMotor.RunMode.RUN_TO_POSITION);
}else if (!gamepad1.dpad_up && already_up){
already_up = false;
}else if (!gamepad1.dpad_down && already_down){
already_down = false;
}
if (gamepad1.x && !already_x){
box.setVelocity(200);
int targetPos = 0;
if(gamepad1.right_bumper){
targetPos = 0;
}
box.setTargetPosition(targetPos);
box.setMode(DcMotor.RunMode.RUN_TO_POSITION);
already_x = !already_x;
} else if(!gamepad1.x && already_x){
already_x = false;
}
if (gamepad1.y && already_y){
rotation.setVelocity(450);
int targetPos = 0;
if (gamepad1.right_bumper){
targetPos = 0;
}else if (gamepad1.left_bumper){
targetPos = 0;
}
rotation.setTargetPosition(targetPos);
rotation.setMode(DcMotor.RunMode.RUN_TO_POSITION);
}
if (gamepad1.right_bumper && gamepad1.left_bumper){
// launch the plane
}
<<<<<<< HEAD
telemetry.addData("x", x);
telemetry.addData("y", y);
telemetry.addData("lpow", lpower);
telemetry.addData("rpow", rpower);
telemetry.addData("ltrigg", t);
telemetry.addData("t2", t2);
// Create an object to receive the IMU angles
YawPitchRollAngles robotOrientation;
robotOrientation = imu.getRobotYawPitchRollAngles();
=======
telemetry.addData("x", x);
telemetry.addData("y", y);
telemetry.addData("lpow", lpower);
@ -297,6 +365,7 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
// Create an object to receive the IMU angles
YawPitchRollAngles robotOrientation;
robotOrientation = imu.getRobotYawPitchRollAngles();
>>>>>>> cdd50be8b9f970f1db99003d4c401bf7dafa25b6
// Now use these simple methods to extract each angle
// (Java type double) from the object you just created:
@ -305,7 +374,14 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
double Roll = robotOrientation.getRoll(AngleUnit.DEGREES);
telemetry.addData("yaw", Yaw);
<<<<<<< HEAD
telemetry.update();
}
}
}
=======
telemetry.update();
}
}
}
>>>>>>> cdd50be8b9f970f1db99003d4c401bf7dafa25b6

View file

@ -32,7 +32,11 @@ public class Ftc2024_autonome_api extends LinearOpMode {
public void runOpMode() {
lm = hardwareMap.get(DcMotor.class, "blm");
rm = hardwareMap.get(DcMotor.class, "brm");
harvestmotor = hardwareMap.get(DcMotor.class, "flm");
<<<<<<< HEAD
harvestmotor = hardwareMap.get(DcMotor.class, "moissonneuse");
=======
harvestmotor = hardwareMap.get(DcMotor.class, "moissoneuse");
>>>>>>> a8ae6d3 (hello)
rm.setDirection(DcMotor.Direction.REVERSE);

View file

@ -330,9 +330,6 @@ public class Werobot_FTC2024_carlike extends LinearOpMode {
// launch the plane
}
telemetry.addData("x", x);
telemetry.addData("y", y);
telemetry.addData("lpow", lpower);

12
list.py
View file

@ -1,12 +0,0 @@
def calcul_suite(n):
res1 = [1];
for i in range(n):
res2 = 0;
for j in res1:
res2+=j;
res2+=1;
res1.append(res2);
return res1[n-1];

View file

@ -49,7 +49,7 @@ public class ftc2024_autonome_test extends LinearOpMode {
waitForStart();
while (opModeIsActive()){
if (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 [] y = new double[lm_p.length];