summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/space.hh
blob: 0a3b224e4294f498af33068cfe0e4f4f1e905256 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// 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 <iostream>
#include <stdio.h>

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

//#define NB_NODES_X 	5
//#define NB_NODES_Y  	3

//#define START_WEIGHT_MIN 	0.1
//#define START_WEIGHT_MAX 	0.9


struct SETUP_POINT
{
    int x, y;
    int distx, disty;
};


/// Etalonnage des distances et localisation de la balle
class Space
{
    /// Classe config
    OConfig *oconfig;
    
    /// tableau d'index des distances
    double *tabX;
    double *tabY;
    
    /// liste des distances etalonnees
    std::vector<SETUP_POINT> setupTab; 

    /// hautdddeur de l'image
    int imgHeight; 

    /// largeur de l'image
    int imgWidth; 

    double aY, bY, cY;

  public:

    // Constructeur
    Space (int width, int height);

    // Destructeur
    ~Space ();

    /// Position d'un objet dans le referentiel du robot
    void GetLoc(int locImgX, int locImgY, int &locX, int &locY);
    void GetLoc(int locImgX, int locImgY, double &locX, double &locY);

    /// Donne la position reelle sur la table de la balle
    void GetPos(double locX, double locY, double posRobotX, double posRobotY, double angleRobot, double &posX, double &posY);

    /// Ajoute un point pour l'etalonnage
    void AddSetupPoint(int x, int y, int distx, int disty);

    /// Chargement des points a partir d'un fichier
    void LoadFromFile();

    /// Etalonnage des distances
    int Setup(double aY, double bY, double cY);

  protected:

    /// Donne les coefficients d'une ligne
    void FindCoeffLine (double x1, double y1, double x2, 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 (int y = 100);

    /// Cree un fichier avec l'erreur en fonction des it�rations
    void LogErrorPoint (FILE *f, int iter);
};

#endif // space_h