summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/space.hh
blob: 7e9f7e83d791ddd7214be0976b320a95c1e25a3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// robert - programme du robot 2005 
// 
// Copyright (C) 2005 Olivier Gaillard
//
// Robot APB Team/Efrei 2005.
//        Web: http://assos.efrei.fr/robot/
//      Email: robot AT efrei DOT fr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#ifndef space_h
#define space_h

#include <vector>
#include <cstdio>

#include "group.hh"
#include "oconfig.hh"

/// Etalonnage des distances et localisation de la balle
class Space
{
    /// Classe config
    OConfig *oconfig_;
    /// hauteur de l'image
    int imgHeight_; 
    /// largeur de l'image
    int imgWidth_; 
    /// tableau d'index des distances
    double *tabX_, *tabY_;
    /// liste des distances etalonnees
    struct SetupPoint;
    std::vector<SetupPoint> setupTab; 
    double aY_, bY_, cY_;

  public:
    /// Constructeur
    Space (const int width, const int height);
    /// Destructeur
    ~Space ();
    /// Position d'un objet dans le referentiel du robot
    void getLoc (const int locImgX, const int locImgY, int &locX, int &locY_);
    void getLoc (const int locImgX, const int locImgY, double &locX, double &locY_);
    /// Donne la position reelle sur la table de la balle
    void getPos (const double locX, const double locY, const double posRobotX, 
		 const double posRobotY, const double angleRobot, double &posX, double &posY);
    /// Give Real Location dist and angle
    void getRealLoc (Zone &zone, int &x, int &y, int &angle, int &dist);
    /// Ajoute un point pour l'etalonnage
    void addSetupPoint (const int x, const int y, const int distx, const int disty);
    /// Chargement des points a partir d'un fichier
    void loadFromFile ();
    /// Etalonnage des distances
    int setup (const double aY_, const double bY_, const double cY_);

  private:
    struct SetupPoint 
      {
	int x, y;
	int distx, disty;
      };
    /// Donne les coefficients d'une ligne
    void findCoeffLine (const double x1, const double y1, const double x2, const double y2, double &a, double &b);
    /// Cree un fichier gnuplot avec la courbe des points donn�s par la courbe x et y
    void createGnuPlotFile (const int y = 100);
    /// Cree un fichier avec l'erreur en fonction des it�rations
    void logErrorPoint (FILE *f, const int iter);
};

#endif // space_h