some fixes for main and paths

This commit is contained in:
Johannes Reinhardt 2008-07-12 10:43:11 +02:00
parent 7983343bc4
commit df94f21d65
2 changed files with 11 additions and 6 deletions

View File

@ -23,7 +23,7 @@ int main(int argc, char **argv) {
p = path_new(&t->map,&t->vehicle); p = path_new(&t->map,&t->vehicle);
while(t->alive){ while(t->alive){
path_execute(t,p); path_execute(t,p);
trial_wait_for_input(t); trial_check_input(t);
} }
path_free(p); path_free(p);

View File

@ -26,8 +26,9 @@ path *path_new(map* m,vehicle *v){
/* Calculate a trivial path to the origin*/ /* Calculate a trivial path to the origin*/
/* Turn towards origin, take shorter direction*/ /* Turn towards origin, take shorter direction*/
angle = atan(v->y/v->x); angle = atan(v->y/v->x)*180/M_PI;
stop = abs(angle - v->dir)/m->max_turn; stop = abs(angle - v->dir)/m->max_turn*1000;
printf("Angle: %f stop: %f\n",angle,stop);
if(angle - v->dir > 0){ if(angle - v->dir > 0){
/*clockwise/left turn*/ /*clockwise/left turn*/
tmp = command_new(0,BREAK,TURN_LEFT); tmp = command_new(0,BREAK,TURN_LEFT);
@ -48,16 +49,20 @@ path *path_new(map* m,vehicle *v){
void path_execute(trial* t,path* p){ void path_execute(trial* t,path* p){
command* tmp; command* tmp;
timestamp now;
tmp = (command*) g_queue_peek_head(p->commands); tmp = (command*) g_queue_peek_head(p->commands);
if(tmp == NULL){ /*if(tmp == NULL){
fprintf(stderr,"warning: cannot execute empty path\n"); fprintf(stderr,"warning: cannot execute empty path\n");
} }*/
if(t == NULL){ if(t == NULL){
fprintf(stderr,"trial is null\n"); fprintf(stderr,"trial is null\n");
return; return;
} }
now = timestamp_get_curts(t);
/*fprintf(stderr,"Now: %d TS: %d\n",now,clock());*/
/*magic number for latency, send messages that much earlier*/ /*magic number for latency, send messages that much earlier*/
while(tmp != NULL && tmp->ts - t->last_ts < 20){ while(tmp != NULL && now - 20 > tmp->ts){
tmp = (command*) g_queue_pop_head(p->commands); tmp = (command*) g_queue_pop_head(p->commands);
switch(tmp->turn){ switch(tmp->turn){
case TURN_HARD_LEFT: vehicle_hard_left(t); break; case TURN_HARD_LEFT: vehicle_hard_left(t); break;