summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/map.hh
blob: dca9ee06f7842720526b49080fc63475ecf49df2 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// 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 map_h
#define map_h

#include <list>
#include "group.hh"
#include "oconfig.hh"
#include "space.hh"
#include "motor/motor.hh"


#define LOCKED 1
#define UNLOCKED 0


/// Structure stockant les balles
struct tBALL {
    /// position de la balle
    double position[2];

    /// score balle pour le choix de la prochaine balle a aller chercher
    double score;

    /// score precalcule sans distance pour eviter les calculs redondants
    double preScore;

    // zone balle, facilite le calcul de la distance robot-balle
    int zone;

    /// probabilite que la balle sot a la zone indique par la map
    int skepticism;

    /// balle vu seulement partiellement par la camera
    bool partial;

    /// pr�cision de la position de la balle pour mettre � jour sa position
    int precision;

    /// marqueur pour savoir si la balle a quitte le champ de vision par le bas
    int bottom;
};


/// Classe Map
class Map 
{
    /// Variables configurables
    OConfig *oconfig; 
    Space *space;
//    Motor &motor;
//    const Tracker &tracker;

    /// position des goals
    double posGoal[2]; 
    
    /// Liste de balles trouvees
    std::list<tBALL> ball;
    
    /// balle locke ?
    bool lock;
    
    /// Palmier sur l'image ?
    bool treeFound;

    /// Position du palmier � l'�cran
    double posTree[2];
    
    /// Ajoute une balle a la map
    void AddBall(double *pos, ZONE *pZone);

    /// Supprime une balle de la map
    void DelBall(std::list<tBALL>::iterator &iter);

    /// Test si une balle trouv� correspond a une balle de la map
    int TestSimilarBall(ZONE *pBall , std::list<tBALL>::iterator &iter);
    
    /// Distance robot-balle
    double Dist(double *pos1, double *pos2);
    double Dist(double pos1X, double pos1Y, double pos2X, double pos2Y);

    /// Calcul de l'angle robot-balle
    double Angle (double ballPosY, double robotPosY, double distRobotBall);
	
    /// Balle ayant le plus haut score
    std::list<tBALL>::iterator curBall;

    /// Permet de savoir si une balle est dans curBall
    bool checkCurBall;
    
  public:

    /// Balle ayant la plus grand score
    int goodBall;

    /// Zone ou est situe le robot
    int zoneRobot;
    
    /// Constructeurs.
    Map (Space *space);

    /// Destructeur.
    ~Map (void);

    /// Retourne si une balle est locke
    bool IsLock ();

    /// Lock une balle pour savoir quel balle le robot suit
    void SetLock (bool value);

    /// Presence de palmier sur l'image
    bool IsTree ();

    /// Ajoute des balles a la liste
    void AddBallsToMap (Group *group);

    /// Met a jour les scores des balles
    void UpdateMap ();

    //Affiche les balles de la map
    void ShowBalls ();

    /// Donne la position du 1er arbre trouv� sur la map
    bool GetTreePos (double &x, double &y);

    /// Accessors
    /// Renvoie l'iterator sur la balle courante
    const std::list<tBALL>::iterator &GetCurBall ();

    /// Donne la position de la balle la plus proche ou locke
    /// Retourne NULL si la balle locke est perdu
    bool GetCurBallPos (double &x, double &y);

    /// Donne la position dans le r�f�rentiel de la table
    void GetPosFromLoc (int locImgX, int locImgY, double &posX, double &posY);
  
  protected:
};


#endif // map_h