striker: use striker based on old Latino's code

pull/1/head
EmaMaker 2021-03-01 16:00:11 +01:00
parent 019831e237
commit b657d88846
5 changed files with 117 additions and 155 deletions

View File

@ -4,20 +4,9 @@
#include "sensors/sensors.h" #include "sensors/sensors.h"
#include "strategy_roles/game.h" #include "strategy_roles/game.h"
#define TILT_MULT 1.8 #define STRIKER_ATTACK_DISTANCE 125
#define TILT_DIST 170 #define STRIKER_PLUSANG 55
#define CATCH_DIST 150 #define STRIKER_PLUSANG_VISIONCONE 20
#define GOALIE_ATKSPD_LAT 150 //255
#define GOALIE_ATKSPD_BAK 150
#define GOALIE_ATKSPD_FRT 150
#define GOALIE_ATKSPD_STRK 150
#define GOALIE_ATKDIR_PLUSANG1 20
#define GOALIE_ATKDIR_PLUSANG2 35
#define GOALIE_ATKDIR_PLUSANG3 40
#define GOALIE_ATKDIR_PLUSANGBAK 40
#define GOALIE_ATKDIR_PLUSANG1_COR 60
#define GOALIE_ATKDIR_PLUSANG2_COR 70
#define GOALIE_ATKDIR_PLUSANG3_COR 70
class Striker : public Game{ class Striker : public Game{

View File

@ -4,20 +4,10 @@
#include "sensors/sensors.h" #include "sensors/sensors.h"
#include "strategy_roles/game.h" #include "strategy_roles/game.h"
#define TILT_MULT 1.8 #define TARGET_DIST 120
#define TILT_DIST 170 #define ATTACK_DIST 150
#define CATCH_DIST 150 #define ANGLE_SHIFT_STEP 5
#define GOALIE_ATKSPD_LAT 120 //255 #define STRIKER_SPD 80
#define GOALIE_ATKSPD_BAK 120
#define GOALIE_ATKSPD_FRT 120
#define GOALIE_ATKSPD_STRK 120
#define GOALIE_ATKDIR_PLUSANG1 20
#define GOALIE_ATKDIR_PLUSANG2 35
#define GOALIE_ATKDIR_PLUSANG3 40
#define GOALIE_ATKDIR_PLUSANGBAK 40
#define GOALIE_ATKDIR_PLUSANG1_COR 60
#define GOALIE_ATKDIR_PLUSANG2_COR 70
#define GOALIE_ATKDIR_PLUSANG3_COR 70
class StrikerTest : public Game{ class StrikerTest : public Game{

View File

@ -37,11 +37,9 @@ void loop() {
updateSensors(); updateSensors();
if(DEBUG.available()) testmenu->testMenu(); if(DEBUG.available()) testmenu->testMenu();
// striker_test->play(1);
striker->play(1); striker->play(1);
// keeper->play(1); // striker_test->play(1);
// keeper->play(role==0);
// drive->prepareDrive(0, 100,0);
// Last thing to do: movement and update status vector // Last thing to do: movement and update status vector
drive->drivePrepared(); drive->drivePrepared();

View File

@ -6,94 +6,61 @@
#include "math.h" #include "math.h"
Striker::Striker() : Game()
Striker::Striker() : Game() { {
init(); init();
} }
Striker::Striker(LineSystem* ls_, PositionSystem* ps_) : Game(ls_, ps_) { Striker::Striker(LineSystem *ls_, PositionSystem *ps_) : Game(ls_, ps_)
{
init(); init();
} }
void Striker::init(){ void Striker::init()
atk_speed = 0; {
atk_direction = 0; atk_speed = 0;
cstorc = 0; atk_direction = 0;
cstorc = 0;
} }
void Striker::realPlay(){ void Striker::realPlay()
if(CURRENT_DATA_READ.ballSeen) this->striker(); {
else ps->goCenter(); if (CURRENT_DATA_READ.ballSeen)
this->striker();
else
ps->goCenter();
} }
void Striker::striker() { void Striker::striker()
if(CURRENT_DATA_READ.ballAngle>= 350 || CURRENT_DATA_READ.ballAngle<= 20) { {
if(CURRENT_DATA_READ.ballDistance > 190) atk_direction = 0; int plusang = STRIKER_PLUSANG, ball_degrees2, dir, ball_deg = CURRENT_DATA_READ.ballAngle;
else atk_direction = CURRENT_DATA_READ.ballAngle;
atk_speed = GOALIE_ATKSPD_FRT; if (CURRENT_DATA_READ.ballDistance > STRIKER_ATTACK_DISTANCE)
{
drive->prepareDrive(ball_deg > 180 ? CURRENT_DATA_READ.ballAngle - 10 : CURRENT_DATA_READ.ballAngle + 10, 100, 0);
return;
} }
if(CURRENT_DATA_READ.ballAngle>= 90 && CURRENT_DATA_READ.ballAngle<= 270) {
ballBack();
atk_speed = GOALIE_ATKSPD_BAK;
}
if(CURRENT_DATA_READ.ballAngle> 10 && CURRENT_DATA_READ.ballAngle< 30) {
atk_direction = CURRENT_DATA_READ.ballAngle+ GOALIE_ATKDIR_PLUSANG1;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle>= 30 && CURRENT_DATA_READ.ballAngle< 45) {
atk_direction = CURRENT_DATA_READ.ballAngle+ GOALIE_ATKDIR_PLUSANG2;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle>= 45 && CURRENT_DATA_READ.ballAngle< 90) {
atk_direction = CURRENT_DATA_READ.ballAngle+ GOALIE_ATKDIR_PLUSANG3;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle> 270 && CURRENT_DATA_READ.ballAngle<= 315) {
atk_direction = CURRENT_DATA_READ.ballAngle- GOALIE_ATKDIR_PLUSANG3_COR;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle> 315 && CURRENT_DATA_READ.ballAngle<= 330) {
atk_direction = CURRENT_DATA_READ.ballAngle- GOALIE_ATKDIR_PLUSANG2_COR;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle> 330 && CURRENT_DATA_READ.ballAngle< 350) {
atk_direction = CURRENT_DATA_READ.ballAngle- GOALIE_ATKDIR_PLUSANG1_COR;
atk_speed = GOALIE_ATKSPD_LAT;
}
// if((CURRENT_DATA_READ.ballAngle>= 330 || CURRENT_DATA_READ.ballAngle<= 30) && CURRENT_DATA_READ.ballDistance > 190) { //storcimento
// atk_speed = GOALIE_ATKSPD_STRK; //dove i gigahertz hanno fallito
// drive->prepareDrive(atk_direction, atk_speed, cstorc);
// }
// else
drive->prepareDrive(atk_direction, atk_speed);
}
void Striker::ballBack() {
int ball_degrees2;
int dir;
int plusang;
if(CURRENT_DATA_READ.ballDistance > 130) plusang = GOALIE_ATKDIR_PLUSANGBAK;
else plusang = 0;
if(CURRENT_DATA_READ.ballAngle> 180) ball_degrees2 = CURRENT_DATA_READ.ballAngle- 360;
else ball_degrees2 = CURRENT_DATA_READ.ballAngle; if (ball_deg > 340 || ball_deg < 20)
if(ball_degrees2 > 0) dir = CURRENT_DATA_READ.ballAngle+ plusang; //45 con 8 ruote plusang -= STRIKER_PLUSANG_VISIONCONE; //se ho la palla in un range di +-20 davanti, diminuisco di 20 il plus
else dir = CURRENT_DATA_READ.ballAngle- plusang; //45 con 8 ruote if (ball_deg > 180)
if(dir < 0) dir = dir + 360; ball_degrees2 = ball_deg - 360; //ragiono in +180 -180
else dir = dir; else
atk_direction = dir; ball_degrees2 = ball_deg;
if (ball_degrees2 > 0)
dir = ball_deg + plusang; //se sto nel quadrante positivo aggiungo
else
dir = ball_deg - plusang; //se sto nel negativo sottraggo
if (dir < 0)
dir = dir + 360; //se sto nel quadrante negativo ricappotto
else
dir = dir;
drive->prepareDrive(dir, 100, 0);
} }
void Striker::storcimentoPorta()
void Striker::storcimentoPorta() { {
if (CURRENT_DATA_READ.angleAtkFix >= 5 && CURRENT_DATA_READ.angleAtkFix <= 60) cstorc+=9;
else if (CURRENT_DATA_READ.angleAtkFix <= 355 && CURRENT_DATA_READ.angleAtkFix >= 210) cstorc-=9;
else cstorc *= 0.9;
cstorc = constrain(cstorc, -45, 45);
} }

View File

@ -23,57 +23,75 @@ void StrikerTest::realPlay(){
else ps->goCenter(); else ps->goCenter();
} }
void StrikerTest::striker() { void StrikerTest::striker()
if(CURRENT_DATA_READ.ballAngle>= 350 || CURRENT_DATA_READ.ballAngle<= 20) { {
if(CURRENT_DATA_READ.ballDistance > 190) atk_direction = 0; /*First implementation of "orbital striker", a new way to approach the problem with less lines.
else atk_direction = CURRENT_DATA_READ.ballAngle; It works with robot's positions, calculating the final one using the angle shift over
atk_speed = GOALIE_ATKSPD_FRT; and over again until we have an acceptable result. That result is used to drive->prepareDrive with the speed.*/
} // if (CURRENT_DATA_READ.ballDistance > )
// drive->prepareDrive(CURRENT_DATA_READ.ballAngle, STRIKER_SPD);
// else
// {
// if (CURRENT_DATA_READ.ballAngle > 340 && CURRENT_DATA_READ.ballAngle < 20)
// {
// drive->prepareDrive(0, 100, 0);
// }
// else
// {
// int ballAngle = (90 - CURRENT_DATA_READ.ballAngle + 360) % 360;
// robotAngle = (ballAngle - 180 + 360) % 360;
if(CURRENT_DATA_READ.ballAngle>= 90 && CURRENT_DATA_READ.ballAngle<= 270) { // DEBUG.print("Ball is at angle (goniometric circle): ");
int ball_degrees2; // DEBUG.println(ballAngle);
int dir; // DEBUG.print("Robot is at angle ");
// DEBUG.println(robotAngle);
int plusang; // float robotAngle_rad = robotAngle*3.14 / 180;
if(CURRENT_DATA_READ.ballDistance > 130) plusang = GOALIE_ATKDIR_PLUSANGBAK; // robotX = CURRENT_DATA_READ.ballDistance * cos(robotAngle_rad);
else plusang = 0; // robotY = CURRENT_DATA_READ.ballDistance * sin(robotAngle_rad);
if(CURRENT_DATA_READ.ballAngle> 180) ball_degrees2 = CURRENT_DATA_READ.ballAngle- 360;
else ball_degrees2 = CURRENT_DATA_READ.ballAngle;
if(ball_degrees2 > 0) dir = CURRENT_DATA_READ.ballAngle+ plusang; //45 con 8 ruote
else dir = CURRENT_DATA_READ.ballAngle- plusang; //45 con 8 ruote
if(dir < 0) dir = dir + 360;
else dir = dir;
atk_direction = dir;
atk_speed = GOALIE_ATKSPD_BAK;
}
if(CURRENT_DATA_READ.ballAngle> 10 && CURRENT_DATA_READ.ballAngle< 30) { // DEBUG.print("Coords of the robot relative to the ball: (");
atk_direction = CURRENT_DATA_READ.ballAngle+ GOALIE_ATKDIR_PLUSANG1; // DEBUG.print(robotX);
atk_speed = GOALIE_ATKSPD_LAT; // DEBUG.print(", ");
} // DEBUG.print(robotY);
if(CURRENT_DATA_READ.ballAngle>= 30 && CURRENT_DATA_READ.ballAngle< 45) { // DEBUG.println(")");
atk_direction = CURRENT_DATA_READ.ballAngle+ GOALIE_ATKDIR_PLUSANG2;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle>= 45 && CURRENT_DATA_READ.ballAngle< 90) {
atk_direction = CURRENT_DATA_READ.ballAngle+ GOALIE_ATKDIR_PLUSANG3;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle> 270 && CURRENT_DATA_READ.ballAngle<= 315) {
atk_direction = CURRENT_DATA_READ.ballAngle- GOALIE_ATKDIR_PLUSANG3_COR;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle> 315 && CURRENT_DATA_READ.ballAngle<= 330) {
atk_direction = CURRENT_DATA_READ.ballAngle- GOALIE_ATKDIR_PLUSANG2_COR;
atk_speed = GOALIE_ATKSPD_LAT;
}
if(CURRENT_DATA_READ.ballAngle> 330 && CURRENT_DATA_READ.ballAngle< 350) {
atk_direction = CURRENT_DATA_READ.ballAngle- GOALIE_ATKDIR_PLUSANG1_COR;
atk_speed = GOALIE_ATKSPD_LAT;
}
drive->prepareDrive(atk_direction, atk_speed); // // angleDiff = min(((-robotAngle + 360) % 360), ((robotAngle + 360) % 360));
// // angleShift = min(angleDiff, ANGLE_SHIFT_STEP);
// angleShift = ANGLE_SHIFT_STEP;
// if (robotAngle >= 0 && robotAngle <= 180)
// newAngle = robotAngle - angleShift;
// else
// newAngle = robotAngle + angleShift;
// DEBUG.print("New ball-robot angle: ");
// DEBUG.println(newAngle);
// float newAngle_rad = (newAngle)*3.14 / 180;
// robotX_new = TARGET_DIST * cos(newAngle_rad);
// robotY_new = TARGET_DIST * sin(newAngle_rad);
// DEBUG.print("New coords of the robot relative to the ball: (");
// DEBUG.print(robotX_new);
// DEBUG.print(", ");
// DEBUG.print(robotY_new);
// DEBUG.println(")");
// moveAngle = (atan2((robotX_new - robotX), (robotY_new - robotY))) * 180 / 3.14;
// moveAngle = (moveAngle + 360) % 360;
// DEBUG.print("Direction to move in: ");
// DEBUG.println(moveAngle);
// drive->prepareDrive(moveAngle, STRIKER_SPD);
// }
// }
// delay(1000);
// DEBUG.println("==========");
} }