it works a little bit
This commit is contained in:
parent
c9ce88807a
commit
41ce4bf1d2
@ -18,9 +18,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
/*create trivial path towards the origin*/
|
||||
p = path_new(&t->map,&t->vehicle);
|
||||
|
||||
trial_wait_for_start(t);
|
||||
p = path_new(&t->map,&t->vehicle);
|
||||
while(t->alive){
|
||||
trial_wait_for_input(t);
|
||||
path_execute(t,p);
|
||||
|
15
src/path.c
15
src/path.c
@ -32,15 +32,13 @@ path *path_new(map* m,vehicle *v){
|
||||
/*clockwise/left turn*/
|
||||
tmp = command_new(0,BREAK,TURN_LEFT);
|
||||
g_queue_push_tail(res->commands,tmp);
|
||||
tmp = command_new(stop,BREAK,TURN_RIGHT);
|
||||
g_queue_push_tail(res->commands,tmp);
|
||||
} else {
|
||||
/*counterclockwise/right turn*/
|
||||
tmp = command_new(0,BREAK,TURN_RIGHT);
|
||||
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*/
|
||||
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){
|
||||
command* tmp;
|
||||
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*/
|
||||
while(tmp->ts - t->last_ts < 20){
|
||||
while(tmp != NULL && tmp->ts - t->last_ts < 20){
|
||||
tmp = (command*) g_queue_pop_head(p->commands);
|
||||
switch(tmp->turn){
|
||||
case TURN_HARD_LEFT: vehicle_hard_left(t); break;
|
||||
|
Loading…
Reference in New Issue
Block a user