diff --git a/src/path.c b/src/path.c index cd33a08..1290bb5 100644 --- a/src/path.c +++ b/src/path.c @@ -1,4 +1,5 @@ - +#include +#include #include #include "path.h" @@ -8,6 +9,7 @@ command *command_new(timestamp ts, accel_t a, turn_t t){ res->ts = ts; res->accel = a; res->turn = t; + return res; } void command_free(command* c){ @@ -22,25 +24,26 @@ path *path_new(map* m,vehicle *v){ /* Calculate a trivial path to the origin*/ /* Turn towards origin, take shorter direction*/ - angle = atan(v->y/y->x); + angle = atan(v->y/v->x); stop = abs(angle - v->dir)/m->max_turn; if(angle - v->dir > 0){ /*clockwise/left turn*/ tmp = command_new(0,BREAK,TURN_LEFT); - g_push_tail(res-commands,tmp); + g_queue_push_tail(res->commands,tmp); tmp = command_new(stop,BREAK,TURN_RIGHT); - g_push_tail(res-commands,tmp); - else { + g_queue_push_tail(res->commands,tmp); + } else { /*counterclockwise/right turn*/ tmp = command_new(0,BREAK,TURN_RIGHT); - g_push_tail(res-commands,tmp); + g_queue_push_tail(res->commands,tmp); tmp = command_new(stop,BREAK,TURN_LEFT); - g_push_tail(res-commands,tmp); + g_queue_push_tail(res->commands,tmp); } /*start driving*/ tmp = command_new(stop,ACCEL,TURN_STRAIGHT); - g_push_tail(res-commands,tmp); + g_queue_push_tail(res->commands,tmp); + return res; } void path_execute(trial* t,path* p){ @@ -73,7 +76,7 @@ void path_free(path* p){ length = g_queue_get_length(p->commands); if(length > 0){ fprintf(stderr,"freeing non-empty path\n"); - while(g_queue_get_length(p->commands > 0)){ + while(g_queue_get_length(p->commands) > 0){ tmp = g_queue_pop_head(p->commands); command_free(tmp); }