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

ajout d'une balle random

parent 8b8e4596
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
#define GOAL_H_WALL (LCD_MAX_WIDTH-(2*BALL_RADIUS+1+WALL_WIDTH)) #define GOAL_H_WALL (LCD_MAX_WIDTH-(2*BALL_RADIUS+1+WALL_WIDTH))
#define GOAL_V_WALL (LCD_MAX_HEIGHT-(2*BALL_RADIUS+1+WALL_WIDTH)-1) #define GOAL_V_WALL (LCD_MAX_HEIGHT-(2*BALL_RADIUS+1+WALL_WIDTH)-1)
#define NUM_THREADS 5
// Ball identifiers // Ball identifiers
enum { enum {
NONE = -1, // NONE is used if ball has reached the goal (winner field) NONE = -1, // NONE is used if ball has reached the goal (winner field)
...@@ -86,6 +88,8 @@ void slave_info_rx(void *data, int len) ...@@ -86,6 +88,8 @@ void slave_info_rx(void *data, int len)
} }
void Algo_main_ball(void *params); void Algo_main_ball(void *params);
void Algo_bots(void *params);
void RandAccel(accel_t *accel);
int main(void) int main(void)
{ {
...@@ -113,9 +117,15 @@ int main(void) ...@@ -113,9 +117,15 @@ int main(void)
accel_read(&ball_accel); // example: reading of the accelerometer accel_read(&ball_accel); // example: reading of the accelerometer
// creating tasks... // creating tasks...
/*for(int i = 0; i<NUM_THREADS; i++){
}*/
xTaskCreate(Algo_main_ball, (signed portCHAR *)"Masterball", xTaskCreate(Algo_main_ball, (signed portCHAR *)"Masterball",
configMINIMAL_STACK_SIZE, &ball_param_th[0], tskIDLE_PRIORITY+1, configMINIMAL_STACK_SIZE, &ball_param_th[0], tskIDLE_PRIORITY+1,
NULL); NULL);
xTaskCreate(Algo_bots, (signed portCHAR *)"libreball1",
configMINIMAL_STACK_SIZE, &ball_param_th[2], tskIDLE_PRIORITY+1,
NULL);
vTaskStartScheduler(); // launch scheduler vTaskStartScheduler(); // launch scheduler
LPC_TIM0->TCR = 1; LPC_TIM0->TCR = 1;
...@@ -181,3 +191,74 @@ void Algo_main_ball(void *params){ ...@@ -181,3 +191,74 @@ void Algo_main_ball(void *params){
} }
} }
void Algo_bots(void *params){
ball_param_th_t *ball = (ball_param_th_t *)params;
accel_t ball_acc;
int un_ou_moins_un_x = 1, un_ou_moins_un_y = 1;
while(1){
lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, LCD_BLACK);
int CollisionState = test_collision(&ball->ball);
if(CollisionState != NO_COLLISION){
//ralentissement de 10% de la vitesse de la balle
ball->ball.speed.x = ball->ball.speed.x - (ball->ball.speed.x/10);
ball->ball.speed.y = ball->ball.speed.y - (ball->ball.speed.y/10);
if(CollisionState & TOUCH_LEFT){
un_ou_moins_un_x = -1;
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){
un_ou_moins_un_x = -1;
ball->ball.pos.x -= ball->ball.radius/2;
}
if(CollisionState & TOUCH_DOWN){
un_ou_moins_un_y = -1;
ball->ball.pos.y -= ball->ball.radius/2;
}
}else{
//lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, LCD_BLACK);
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.y = ((ball_acc.accel_y*0.08)+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.y = ball->ball.pos.y + ball->ball.speed.y*(un_ou_moins_un_y);
un_ou_moins_un_y = 1;
un_ou_moins_un_x = 1;
}
//}
if(ball->ball.pos.x <= ball->ball.radius){
ball->ball.pos.x = ball->ball.radius+1;
}
if(ball->ball.pos.y <= ball->ball.radius){
ball->ball.pos.y = ball->ball.radius+1;
}
if(ball->ball.pos.x == LCD_MAX_WIDTH-ball->ball.radius){
ball->ball.pos.x -= ball->ball.radius;
}
if(ball->ball.pos.y == LCD_MAX_HEIGHT-ball->ball.radius){
ball->ball.pos.y -= ball->ball.radius;
}
lcd_filled_circle(ball->ball.pos.x, ball->ball.pos.y, ball->ball.radius, ball->ball.color);
vTaskDelay((portTickType)20/portTICK_RATE_MS);
}
}
void RandAccel(accel_t *accel){
float x = rnd32()%500;
float y = rnd32()%500;
accel->accel_x = x/100;
accel->accel_y = y/100;
accel->accel_z = (float)(rnd32()%500)/100;
accel->magneto_x = 0;
accel->magneto_y = 0;
accel->magneto_z = 0;
accel->temperature = 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