diff --git a/src/main.c b/src/main.c index 664c7fd..4b693ee 100644 --- a/src/main.c +++ b/src/main.c @@ -23,7 +23,7 @@ int main(int argc, char **argv) { p = path_new(&t->map,&t->vehicle); while(t->alive){ path_execute(t,p); - trial_wait_for_input(t); + trial_check_input(t); } path_free(p); diff --git a/src/path.c b/src/path.c index 26a821a..b85766a 100644 --- a/src/path.c +++ b/src/path.c @@ -26,8 +26,9 @@ path *path_new(map* m,vehicle *v){ /* Calculate a trivial path to the origin*/ /* Turn towards origin, take shorter direction*/ - angle = atan(v->y/v->x); - stop = abs(angle - v->dir)/m->max_turn; + angle = atan(v->y/v->x)*180/M_PI; + stop = abs(angle - v->dir)/m->max_turn*1000; + printf("Angle: %f stop: %f\n",angle,stop); if(angle - v->dir > 0){ /*clockwise/left turn*/ 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){ command* tmp; + timestamp now; tmp = (command*) g_queue_peek_head(p->commands); - if(tmp == NULL){ + /*if(tmp == NULL){ fprintf(stderr,"warning: cannot execute empty path\n"); - } + }*/ if(t == NULL){ fprintf(stderr,"trial is null\n"); return; } + + now = timestamp_get_curts(t); + /*fprintf(stderr,"Now: %d TS: %d\n",now,clock());*/ /*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); switch(tmp->turn){ case TURN_HARD_LEFT: vehicle_hard_left(t); break;