Skip to content
Snippets Groups Projects
Commit 1bcc4327 authored by remi.greub's avatar remi.greub
Browse files

corrections de l'acceleration random bot + detection end of LCD

parent d928db45
No related branches found
No related tags found
No related merge requests found
...@@ -150,20 +150,19 @@ void Algo_main_ball(void *params){ ...@@ -150,20 +150,19 @@ void Algo_main_ball(void *params){
un_ou_moins_un_x = -1; un_ou_moins_un_x = -1;
ball->ball.pos.x += ball->ball.radius/2; ball->ball.pos.x += ball->ball.radius/2;
} }
if(CollisionState & TOUCH_UP){
un_ou_moins_un_y = -1;
ball->ball.pos.y += ball->ball.radius/2;
}
if(CollisionState & TOUCH_RIGHT){ if(CollisionState & TOUCH_RIGHT){
un_ou_moins_un_x = -1; un_ou_moins_un_x = -1;
ball->ball.pos.x -= ball->ball.radius/2; ball->ball.pos.x -= ball->ball.radius/2;
} }
if(CollisionState & TOUCH_UP){
un_ou_moins_un_y = -1;
ball->ball.pos.y += ball->ball.radius/2;
}
if(CollisionState & TOUCH_DOWN){ if(CollisionState & TOUCH_DOWN){
un_ou_moins_un_y = -1; un_ou_moins_un_y = -1;
ball->ball.pos.y -= ball->ball.radius/2; ball->ball.pos.y -= ball->ball.radius/2;
} }
}else{ }else{
//lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, LCD_BLACK);
accel_read(&ball_acc); accel_read(&ball_acc);
ball->ball.speed.x = ((ball_acc.accel_x*0.1)+ball->ball.speed.x)*(un_ou_moins_un_x); ball->ball.speed.x = ((ball_acc.accel_x*0.1)+ball->ball.speed.x)*(un_ou_moins_un_x);
ball->ball.speed.y = ((ball_acc.accel_y*0.1)+ball->ball.speed.y)*(un_ou_moins_un_y); ball->ball.speed.y = ((ball_acc.accel_y*0.1)+ball->ball.speed.y)*(un_ou_moins_un_y);
...@@ -173,18 +172,19 @@ void Algo_main_ball(void *params){ ...@@ -173,18 +172,19 @@ void Algo_main_ball(void *params){
un_ou_moins_un_y = 1; un_ou_moins_un_y = 1;
un_ou_moins_un_x = 1; un_ou_moins_un_x = 1;
} }
//}
//détection des collisions sur les bords de l'ecran LCD
if(ball->ball.pos.x <= ball->ball.radius){ if(ball->ball.pos.x <= ball->ball.radius){
ball->ball.pos.x = ball->ball.radius+1; ball->ball.pos.x = ball->ball.radius+1;
} }
if(ball->ball.pos.y <= ball->ball.radius){ if(ball->ball.pos.y <= ball->ball.radius){
ball->ball.pos.y = ball->ball.radius+1; ball->ball.pos.y = ball->ball.radius+1;
} }
if(ball->ball.pos.x == LCD_MAX_WIDTH-ball->ball.radius){ if(ball->ball.pos.x >= LCD_MAX_WIDTH-ball->ball.radius){
ball->ball.pos.x -= ball->ball.radius; ball->ball.pos.x = LCD_MAX_WIDTH-ball->ball.radius;
} }
if(ball->ball.pos.y == LCD_MAX_HEIGHT-ball->ball.radius){ if(ball->ball.pos.y >= LCD_MAX_HEIGHT-ball->ball.radius){
ball->ball.pos.y -= ball->ball.radius; ball->ball.pos.y = LCD_MAX_HEIGHT-ball->ball.radius;
} }
lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color); lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color);
vTaskDelay((portTickType)20/portTICK_RATE_MS); vTaskDelay((portTickType)20/portTICK_RATE_MS);
...@@ -221,10 +221,9 @@ void Algo_bots(void *params){ ...@@ -221,10 +221,9 @@ void Algo_bots(void *params){
ball->ball.pos.y -= ball->ball.radius/2; ball->ball.pos.y -= ball->ball.radius/2;
} }
}else{ }else{
//lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, LCD_BLACK);
RandAccel(&ball_acc); RandAccel(&ball_acc);
ball->ball.speed.x = ((ball_acc.accel_x*0.08)+ball->ball.speed.x)*(un_ou_moins_un_x); ball->ball.speed.x = ((ball_acc.accel_x*0.1)+ball->ball.speed.x)*(un_ou_moins_un_x);
ball->ball.speed.y = ((ball_acc.accel_y*0.08)+ball->ball.speed.y)*(un_ou_moins_un_y); ball->ball.speed.y = ((ball_acc.accel_y*0.1)+ball->ball.speed.y)*(un_ou_moins_un_y);
ball->ball.pos.x = ball->ball.pos.x + ball->ball.speed.x*(un_ou_moins_un_x); ball->ball.pos.x = ball->ball.pos.x + ball->ball.speed.x*(un_ou_moins_un_x);
ball->ball.pos.y = ball->ball.pos.y + ball->ball.speed.y*(un_ou_moins_un_y); ball->ball.pos.y = ball->ball.pos.y + ball->ball.speed.y*(un_ou_moins_un_y);
...@@ -238,11 +237,11 @@ void Algo_bots(void *params){ ...@@ -238,11 +237,11 @@ void Algo_bots(void *params){
if(ball->ball.pos.y <= ball->ball.radius){ if(ball->ball.pos.y <= ball->ball.radius){
ball->ball.pos.y = ball->ball.radius+1; ball->ball.pos.y = ball->ball.radius+1;
} }
if(ball->ball.pos.x == LCD_MAX_WIDTH-ball->ball.radius){ if(ball->ball.pos.x >= LCD_MAX_WIDTH-ball->ball.radius){
ball->ball.pos.x -= ball->ball.radius; ball->ball.pos.x = LCD_MAX_WIDTH-ball->ball.radius;
} }
if(ball->ball.pos.y == LCD_MAX_HEIGHT-ball->ball.radius){ if(ball->ball.pos.y >= LCD_MAX_HEIGHT-ball->ball.radius){
ball->ball.pos.y -= ball->ball.radius; ball->ball.pos.y = LCD_MAX_HEIGHT-ball->ball.radius;
} }
lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color); lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color);
vTaskDelay((portTickType)20/portTICK_RATE_MS); vTaskDelay((portTickType)20/portTICK_RATE_MS);
...@@ -250,12 +249,14 @@ void Algo_bots(void *params){ ...@@ -250,12 +249,14 @@ void Algo_bots(void *params){
} }
} }
//random d'accélérations
void RandAccel(accel_t *accel){ void RandAccel(accel_t *accel){
float x = rnd32()%500; float x = (float)(rnd32()%100)-50;
float y = rnd32()%500; float y = (float)(rnd32()%100)-50;
accel->accel_x = x/100; accel->accel_x = x/100;
accel->accel_y = y/100; accel->accel_y = y/100;
accel->accel_z = (float)(rnd32()%500)/100; //accel->accel_z = (float)(rnd32()%500)/100;
accel->magneto_x = 0; accel->magneto_x = 0;
accel->magneto_y = 0; accel->magneto_y = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment