]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
Main.cc file editing (change the comment and the variable) from Martin Synek
authormartin <martin@kate.(none)>
Tue, 30 Nov 2010 14:25:23 +0000 (15:25 +0100)
committermartin <martin@kate.(none)>
Tue, 30 Nov 2010 14:25:23 +0000 (15:25 +0100)
src/hokuyo/shape-detect/main.cc

index 2a4d377635892af98ed49973673995fa341316e8..58beea729b3065c010c8c4a534f50fd7cfb3dd59 100644 (file)
@@ -6,36 +6,26 @@
 #include <math.h>
 #include <vector>
 
-// konstanta PI
 #define PI 3.14159265
 
-// krok laseru (rozliseni)
+// resolution laser (step)
 #define RESOLUTION 0.331
 
-// presnost (v procentech)
-//#define ACCURACY 3
-
 using namespace std;
 
-// definice datoveho typu Point
 typedef struct {double x,y;} Point;
 
-// vypocet primek
-void detect_line(vector<int> &input_date, vector<Point> &kartez, vector<Point> &lines, double eps) {
+void detect_line(vector<int> &input_data, vector<Point> &cartes, vector<Point> &lines, double eps) {
   
-  // pomocny bod
   Point point;
 
-  // uhel polarni souradnice fi
   double fi;
-
-  // zmerena vzdalenost
   int r;
   
-  // vypocet kartezskych souradnic  
-  for (int i = 0; i < input_date.size()-1; i +=2) { 
-    r = (input_date[i+1] <= 19) ? 0 : input_date[i+1];
-    fi = (RESOLUTION * input_date[i] - 45) * PI/180;
+  // cartesian coordinates 
+  for (int i = 0; i < input_data.size()-1; i +=2) { 
+    r = (input_data[i+1] <= 19) ? 0 : input_data[i+1];
+    fi = (RESOLUTION * input_data[i] - 45) * PI/180;
         
     point.x = r * cos(fi);
     point.y = r * sin(fi);
@@ -43,120 +33,95 @@ void detect_line(vector<int> &input_date, vector<Point> &kartez, vector<Point> &
     point.x = (point.x == -0) ? 0 : point.x;
     point.y = (point.y == -0) ? 0 : point.y;
     
-    kartez.push_back(point);
+    cartes.push_back(point);
   }
   
-  // hledani primek (usecek) pomoci smeroveho vektoru a obecne rovnice primky
-  // obecna rovnice: ax + by + c = 0
-  
-  // parametr c
   double c;
   
-  // normalovy vektor a posledni bod nalezici primce
   Point n_vector, end_point;
   
-  // temp
   bool tmp = true;
-    
-  // primka
   double line;
   
-  for (int i = 0; i < kartez.size()-1; i++) {
+  for (int i = 0; i < cartes.size()-1; i++) {
 
-    cout << "BOD: "<< kartez[i].x << " " << kartez[i].y << endl;
-    
-    if (kartez[i].x == 0 && kartez[i].y == 0) {
+    if (cartes[i].x == 0 && cartes[i].y == 0) {
       tmp = true;
       continue;
     }
     
     if (tmp) {
-      cout << "nova primka: ";
-      lines.push_back(kartez[i]);
+      lines.push_back(cartes[i]);
       
-      end_point = kartez[i+1];
+      end_point = cartes[i+1];
 
-      n_vector.x = -1 * (kartez[i+1].y - kartez[i].y);
-      n_vector.y =  1 * (kartez[i+1].x - kartez[i].x);
+      n_vector.x = -1 * (cartes[i+1].y - cartes[i].y);
+      n_vector.y =  1 * (cartes[i+1].x - cartes[i].x);
     
-      c = -1*n_vector.x*kartez[i].x - n_vector.y*kartez[i].y;
-      
-      cout << "nx: " << n_vector.x << " ny: " << n_vector.y << " c: " << c << endl;
+      c = -1*n_vector.x*cartes[i].x - n_vector.y*cartes[i].y;
       
       i++;
       tmp = false;
     } else {
-      cout << "dalsi bod na primce?: nx: " << n_vector.x << " ny: " << n_vector.y  << " c: " << c << endl;
       
-      line = n_vector.x*kartez[i].x + n_vector.y*kartez[i].y + c;
+      line = n_vector.x*cartes[i].x + n_vector.y*cartes[i].y + c;
       
-      cout << "odchylka: " << line << endl;
-
       if (line < (0+eps) && line > (0-eps)) {
-        end_point = kartez[i];
-        
-        cout << "ANO: X:" << end_point.x << " Y: " << end_point.y << endl;
+        end_point = cartes[i];
         
       } else {
-        cout << "4" << endl;
         lines.push_back(end_point);
         
-        cout << "NE: X:" << end_point.x << " Y: " << end_point.y << endl;
-        
         tmp = true;
       }
     }
-    cout << endl;  
   }
 }
 
 int main(int argc, char** argv) {
   
-  // kontrola vstupniho argumentu
   if (argc < 3) {
-    cout << "Chyby vstupni soubor." << endl;
+    cout << "Error: Invalid number of input parameters." << endl;
     return 1;
   }
  
-  // vector vstupnich dat
-  vector<int> input_date;
-  
-  // vector kartezskych souradnic
-  vector<Point> kartez;
-  
-  // vector zjistenych primek
+  vector<int> input_data;
+  vector<Point> cartes;
   vector<Point> lines;
   
-  // odchylka bodu od primky
+  //  departure point from the line
   double eps = atof(argv[2]);
   
-  // nacteni vstupniho souboru - mapy
   ifstream infile (argv[1], ios_base::in);
   
-  string line;         // radek vstupniho souboru
-  int number;          // cislo prectene ze souboru
-  int size_line;       // pocet znaku na radku
+  string line;         // line input file
+  int number;          // number from input file
     
   while (getline(infile, line, ',')) {
     if (line != "\n") {
       stringstream strStream(line);
       strStream >> number;
-      input_date.push_back(number);
+      input_data.push_back(number);
     }
   }
   
-  detect_line(input_date, kartez, lines, eps);
+  detect_line(input_data, cartes, lines, eps);
   
-  // ulozeni do souboru
+  // save file
   FILE *file = fopen("output_data","w");
-/*
-  for (int i = 0; i < kartez.size(); i += 1)
-    fprintf(file, "%f, %f\n", kartez[i].x, kartez[i].y);
-*/
+
   for (int i = 0; i < lines.size(); i += 1)
     fprintf(file, "%f, %f\n", lines[i].x, lines[i].y);
 
   fclose(file);
+
+  file = fopen("cartes_data","w");
+
+  for (int i = 0; i < cartes.size(); i += 1)
+    fprintf(file, "%f, %f\n", cartes[i].x, cartes[i].y);
+
+  fclose(file);
+
   
   return 0;
 }