fix errors
This commit is contained in:
parent
bb66abbe84
commit
fe0282842b
1 changed files with 112 additions and 157 deletions
133
ftc_new.java
133
ftc_new.java
|
@ -38,18 +38,42 @@ public enum RobotMode{
|
||||||
private DcMotorEx rotation;
|
private DcMotorEx rotation;
|
||||||
private ElapsedTime runtime = new ElapsedTime();
|
private ElapsedTime runtime = new ElapsedTime();
|
||||||
private RobotMode mode = RobotMode.ESSAIFRANCK;
|
private RobotMode mode = RobotMode.ESSAIFRANCK;
|
||||||
/*La fonction pour faire des exponentielles spécifiques
|
|
||||||
|
/*
|
||||||
|
* La fonction pour faire des exponentielles spécifiques
|
||||||
|
*
|
||||||
* @param double t => le nombre dont on veut faire l'exponentielle
|
* @param double t => le nombre dont on veut faire l'exponentielle
|
||||||
* @return double une_exponentielle_très_spéciale_de_t*/
|
*
|
||||||
|
* @return double une_exponentielle_très_spéciale_de_t
|
||||||
|
*/
|
||||||
private double helloexp(double t) {
|
private double helloexp(double t) {
|
||||||
return (Math.exp(5 * t) - 1) / (Math.exp(5) - 1);
|
return (Math.exp(5 * t) - 1) / (Math.exp(5) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void nextMode() {
|
||||||
|
RobotMode toNextMode;
|
||||||
|
switch (this.mode) {
|
||||||
|
case ESSAIFRANCK:
|
||||||
|
toNextMode = RobotMode.ELINA;
|
||||||
|
break;
|
||||||
|
case ELINA:
|
||||||
|
toNextMode = RobotMode.NORMAL;
|
||||||
|
break;
|
||||||
|
case NORMAL:
|
||||||
|
toNextMode = RobotMode.TANK;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
toNextMode = RobotMode.ESSAIFRANCK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.mode = toNextMode;
|
||||||
|
}
|
||||||
|
|
||||||
// La fonction du thread principal
|
// La fonction du thread principal
|
||||||
@Override
|
@Override
|
||||||
public void runOpMode() throws InterruptedException {
|
public void runOpMode() throws InterruptedException {
|
||||||
|
|
||||||
double boxRot;
|
double boxRot = 0;
|
||||||
int signeBR;
|
int signeBR;
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
|
@ -125,13 +149,17 @@ public enum RobotMode{
|
||||||
/* définition de {@link t} sur la valeur du trigger droit du gamepad 1 */
|
/* définition de {@link t} sur la valeur du trigger droit du gamepad 1 */
|
||||||
t = gamepad1.right_trigger;
|
t = gamepad1.right_trigger;
|
||||||
|
|
||||||
/* définition de {@link t2} par utilisation de la fonction {@link helloexp} sur
|
/*
|
||||||
* {@link t}*/
|
* définition de {@link t2} par utilisation de la fonction {@link helloexp} sur
|
||||||
|
* {@link t}
|
||||||
|
*/
|
||||||
t2 = helloexp(t);
|
t2 = helloexp(t);
|
||||||
|
|
||||||
/* définition de {@link t3} par utilisation de la fonction {@link helloexp} sur
|
/*
|
||||||
|
* définition de {@link t3} par utilisation de la fonction {@link helloexp} sur
|
||||||
* la norme du vecteur du joystick gauche du gamepad 1 (racine carrée de {@link
|
* la norme du vecteur du joystick gauche du gamepad 1 (racine carrée de {@link
|
||||||
* x} au carré plus {@link y} au carré*/
|
* x} au carré plus {@link y} au carré
|
||||||
|
*/
|
||||||
t3 = helloexp(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
|
t3 = helloexp(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
|
||||||
|
|
||||||
telemetry.addData("Status", "Running");
|
telemetry.addData("Status", "Running");
|
||||||
|
@ -151,7 +179,6 @@ public enum RobotMode{
|
||||||
// signeBR=1;
|
// signeBR=1;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// if (Math.abs(boxRot) < 0.1){
|
// if (Math.abs(boxRot) < 0.1){
|
||||||
// boxRot = 0.4*signeBR;
|
// boxRot = 0.4*signeBR;
|
||||||
// }
|
// }
|
||||||
|
@ -174,8 +201,8 @@ public enum RobotMode{
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case NORMAL:
|
case NORMAL:
|
||||||
double ysign = Double.signum(y);
|
double ysign = Math.signum(y);
|
||||||
double xsign = Double.signum(x);
|
double xsign = Math.signum(x);
|
||||||
lpower = -ysign * t + (xsign - 2 * x) * t;
|
lpower = -ysign * t + (xsign - 2 * x) * t;
|
||||||
rpower = ysign * t + (xsign - 2 * x) * t;
|
rpower = ysign * t + (xsign - 2 * x) * t;
|
||||||
break;
|
break;
|
||||||
|
@ -194,9 +221,9 @@ public enum RobotMode{
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ELINA:
|
case ELINA:
|
||||||
double a = (-y + x) / Math.pow(2, 1 / 2);
|
a = (-y + x) / Math.pow(2, 1 / 2);
|
||||||
double b = (-y - x) / Math.pow(2, 1 / 2);
|
b = (-y - x) / Math.pow(2, 1 / 2);
|
||||||
double vmean = (Math.abs(a) + Math.abs(b)) / 4;
|
vmean = (Math.abs(a) + Math.abs(b)) / 4;
|
||||||
lpower = (a / vmean) * t3;
|
lpower = (a / vmean) * t3;
|
||||||
rpower = (b / vmean) * t3;
|
rpower = (b / vmean) * t3;
|
||||||
break;
|
break;
|
||||||
|
@ -228,7 +255,8 @@ public enum RobotMode{
|
||||||
}
|
}
|
||||||
|
|
||||||
// activation elevateur
|
// activation elevateur
|
||||||
if (sinking && Math.abs(lmelevator.getCurrentPosition()-90)<=5 && Math.abs(rmelevator.getCurrentPosition()-90)<=5){
|
if (sinking && Math.abs(lmelevator.getCurrentPosition() - 90) <= 5
|
||||||
|
&& Math.abs(rmelevator.getCurrentPosition() - 90) <= 5) {
|
||||||
lmelevator.setVelocity(100);
|
lmelevator.setVelocity(100);
|
||||||
rmelevator.setVelocity(100);
|
rmelevator.setVelocity(100);
|
||||||
lmelevator.setTargetPosition(0);
|
lmelevator.setTargetPosition(0);
|
||||||
|
@ -267,61 +295,6 @@ public enum RobotMode{
|
||||||
already_ps = false;
|
already_ps = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// commentaires supprimés dans le robot
|
|
||||||
// if (gamepad1.x && !already_x){
|
|
||||||
|
|
||||||
// int targetPos = 0;
|
|
||||||
// if(gamepad1.right_bumper){
|
|
||||||
// targetPos = -97;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // while (Math.abs(box.getCurrentPosition()-targetPos) > 30)
|
|
||||||
// // {
|
|
||||||
// // box.setVelocity(100);
|
|
||||||
// // box.setTargetPosition(targetPos);
|
|
||||||
// // box.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
|
||||||
// // }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// box.setVelocity(50);
|
|
||||||
// box.setTargetPosition(targetPos);
|
|
||||||
// box.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
|
||||||
|
|
||||||
// already_x = !already_x;
|
|
||||||
// } else if(!gamepad1.x && already_x){
|
|
||||||
// already_x = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (Math.abs(box.getCurrentPosition() - box.getTargetPosition()) < 20) {
|
|
||||||
// box.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODERS);
|
|
||||||
// box.setPower(-0.2);
|
|
||||||
// telemetry.addData("ModeChanged","without encoders");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if (gamepad1.y && already_y){
|
|
||||||
// rotation.setVelocity(200);
|
|
||||||
// // 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);
|
|
||||||
|
|
||||||
// int pos = rotation.getCurrentPosition();
|
|
||||||
// if (gamepad1.right_bumper){
|
|
||||||
// rotation.setTargetPosition(pos + 100);
|
|
||||||
// }else if (gamepad1.left_bumper){
|
|
||||||
// rotation.setTargetPosition(pos - 100);
|
|
||||||
// }
|
|
||||||
// rotation.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// activation rotation
|
// activation rotation
|
||||||
if (manualMode) {
|
if (manualMode) {
|
||||||
gamepad1.setLedColor(255, 0, 0, 10);
|
gamepad1.setLedColor(255, 0, 0, 10);
|
||||||
|
@ -348,8 +321,7 @@ public enum RobotMode{
|
||||||
rotation.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
|
rotation.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
gamepad1.setLedColor(0, 0, 255, 10);
|
gamepad1.setLedColor(0, 0, 255, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,22 +365,5 @@ public enum RobotMode{
|
||||||
telemetry.update();
|
telemetry.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void nextMode(){
|
|
||||||
RobotMode toNextMode;
|
|
||||||
switch(this.mode){
|
|
||||||
case (ESSAIFRANCK):
|
|
||||||
toNextMode = this.RobotMode.ELINA;
|
|
||||||
break;
|
|
||||||
case (ELINA):
|
|
||||||
toNextMode = this.RobotMode.NORMAL;
|
|
||||||
break;
|
|
||||||
case (NORMAL):
|
|
||||||
toNextMode = this.RobotMode.TANK;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
toNextMode = this.RobotMode.ESSAIFRANCK;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this.mode = toNextMode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue