From 92ab7db17fe5b2d46e1d9f44fb470b8ea82144b3 Mon Sep 17 00:00:00 2001 From: Vytor Calixto <vytorcalixto@gmail.com> Date: Mon, 23 Nov 2015 18:34:50 -0200 Subject: [PATCH] Corrigido angulo --- main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 45296d4..4e722c8 100644 --- a/main.c +++ b/main.c @@ -45,6 +45,12 @@ double angleFromOrigin(int x, int y) { return acos(x/hip) * 180/PI; } +double angleFromPoint(int ox, int oy, int x, int y) { + //ox e oy são os pontos da nova referência + double hip = distance(o)nx, oy, x, y); + return acos((ox-x)/hip) * 180/PI; +} + void moverRobo(Robot *r, int x, int y){ /* Deveríamos "acionar os motores" * e realmente movimentar o robô @@ -87,11 +93,12 @@ int main(int argc, char const *argv[]) { for(int i=0; i < t_size; ++i) { // Pega o ângulo entre a posição do robô e o próximo ponto frame += tuplas[i].t; - double angle = angleFromOrigin(tuplas[i].x, tuplas[i].y); + double angle = angleFromPoint(r.x, r.y, tuplas[i].x, tuplas[i].y); + double turn = angle - r.theta; // angulo para girar o robo //printf("DEBUG: %f %f\n", angle, r.theta); fprintf(graph, "%d %d %d %f\n", tuplas[i].x, tuplas[i].y, frame, angle - r.theta); // Gira o robô - r.theta = angle; + r.theta += turn; // calcula a velocidade para as rodas distancia = distance(r.x, r.y, tuplas[i].x, tuplas[i].y); velocidade = velocity(distancia, tuplas[i].t); -- GitLab