Dependencies:   BufferedSerial

Committer:
xaficz
Date:
Mon May 24 15:32:13 2021 +0000
Revision:
7:5fa6f21eb739
Parent:
4:53ac11e9e8b9
4__zenaga

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xaficz 4:53ac11e9e8b9 1 #include "mbed.h"
xaficz 4:53ac11e9e8b9 2 #include "BufferedSerial.h"
xaficz 4:53ac11e9e8b9 3 #include "Robot.h"
xaficz 4:53ac11e9e8b9 4 #include "Communication.h"
xaficz 4:53ac11e9e8b9 5 #include "math.h"
xaficz 4:53ac11e9e8b9 6 #include "rplidar.h"
xaficz 4:53ac11e9e8b9 7
xaficz 4:53ac11e9e8b9 8 #include <stdio.h>
xaficz 4:53ac11e9e8b9 9 #include <stdlib.h>
xaficz 4:53ac11e9e8b9 10
xaficz 4:53ac11e9e8b9 11 int Cells_x[80]; // Array que Contem as Coordenadas x das Células
xaficz 4:53ac11e9e8b9 12 int Count_x; // Contador (de Células)
xaficz 4:53ac11e9e8b9 13 int m_new_x; // Declive
xaficz 4:53ac11e9e8b9 14 int slope_error_new_x; // Erro Assossiado ao Declive da Reta
xaficz 4:53ac11e9e8b9 15
xaficz 4:53ac11e9e8b9 16 int *x_bresenham(int x1, int y1, int x2, int y2){
xaficz 4:53ac11e9e8b9 17
xaficz 4:53ac11e9e8b9 18 for(int i=0; i<=79; i++){
xaficz 4:53ac11e9e8b9 19 Cells_x[i] = 0;
xaficz 4:53ac11e9e8b9 20 }
xaficz 4:53ac11e9e8b9 21
xaficz 4:53ac11e9e8b9 22 m_new_x = 2 * (y2 - y1);
xaficz 4:53ac11e9e8b9 23
xaficz 4:53ac11e9e8b9 24 slope_error_new_x = m_new_x - (x2 - x1);
xaficz 4:53ac11e9e8b9 25
xaficz 4:53ac11e9e8b9 26 Count_x = -1;
xaficz 4:53ac11e9e8b9 27
xaficz 4:53ac11e9e8b9 28 for (int x = x1; x <= x2; x++){
xaficz 4:53ac11e9e8b9 29
xaficz 4:53ac11e9e8b9 30 Count_x = Count_x + 1;
xaficz 4:53ac11e9e8b9 31
xaficz 4:53ac11e9e8b9 32 Cells_x[Count_x] = x;
xaficz 4:53ac11e9e8b9 33
xaficz 4:53ac11e9e8b9 34 slope_error_new_x += m_new_x;
xaficz 4:53ac11e9e8b9 35
xaficz 4:53ac11e9e8b9 36 if (slope_error_new_x >= 0)
xaficz 4:53ac11e9e8b9 37 {
xaficz 4:53ac11e9e8b9 38 y1++;
xaficz 4:53ac11e9e8b9 39 slope_error_new_x -= 2 * (x2 - x1);
xaficz 4:53ac11e9e8b9 40 }
xaficz 4:53ac11e9e8b9 41
xaficz 4:53ac11e9e8b9 42 }
xaficz 4:53ac11e9e8b9 43
xaficz 4:53ac11e9e8b9 44 Count_x = Count_x + 1;
xaficz 4:53ac11e9e8b9 45 Cells_x[79] = Count_x;
xaficz 4:53ac11e9e8b9 46
xaficz 4:53ac11e9e8b9 47 return Cells_x;
xaficz 4:53ac11e9e8b9 48 }