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);
while(t->alive){
path_execute(t,p);
trial_wait_for_input(t);
trial_check_input(t);
}
path_free(p);

View File

@ -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;