it works a little bit

This commit is contained in:
Johannes Reinhardt 2008-07-12 03:47:36 +02:00
parent c9ce88807a
commit 41ce4bf1d2
2 changed files with 11 additions and 6 deletions

View File

@ -18,9 +18,9 @@ int main(int argc, char **argv) {
} }
/*create trivial path towards the origin*/ /*create trivial path towards the origin*/
p = path_new(&t->map,&t->vehicle);
trial_wait_for_start(t); trial_wait_for_start(t);
p = path_new(&t->map,&t->vehicle);
while(t->alive){ while(t->alive){
trial_wait_for_input(t); trial_wait_for_input(t);
path_execute(t,p); path_execute(t,p);

View File

@ -32,15 +32,13 @@ path *path_new(map* m,vehicle *v){
/*clockwise/left turn*/ /*clockwise/left turn*/
tmp = command_new(0,BREAK,TURN_LEFT); tmp = command_new(0,BREAK,TURN_LEFT);
g_queue_push_tail(res->commands,tmp); g_queue_push_tail(res->commands,tmp);
tmp = command_new(stop,BREAK,TURN_RIGHT);
g_queue_push_tail(res->commands,tmp);
} else { } else {
/*counterclockwise/right turn*/ /*counterclockwise/right turn*/
tmp = command_new(0,BREAK,TURN_RIGHT); tmp = command_new(0,BREAK,TURN_RIGHT);
g_queue_push_tail(res->commands,tmp); g_queue_push_tail(res->commands,tmp);
tmp = command_new(stop,BREAK,TURN_LEFT);
g_queue_push_tail(res->commands,tmp);
} }
tmp = command_new(stop,BREAK,TURN_STRAIGHT);
g_queue_push_tail(res->commands,tmp);
/*start driving*/ /*start driving*/
tmp = command_new(stop,ACCEL,TURN_STRAIGHT); tmp = command_new(stop,ACCEL,TURN_STRAIGHT);
@ -51,8 +49,15 @@ 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;
tmp = (command*) g_queue_peek_head(p->commands); tmp = (command*) g_queue_peek_head(p->commands);
if(tmp == NULL){
fprintf(stderr,"warning: cannot execute empty path\n");
}
if(t == NULL){
fprintf(stderr,"trial is null\n");
return;
}
/*magic number for latency, send messages that much earlier*/ /*magic number for latency, send messages that much earlier*/
while(tmp->ts - t->last_ts < 20){ while(tmp != NULL && tmp->ts - t->last_ts < 20){
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;