summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ai/ai.cc
blob: 12e8f889c778cb9e5ac83a5a50b6b68f96a457df (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
164
165
166
167
168
// ai.cc
// robert - programme du robot 2005. {{{
//
// Copyright (C) 2005 Nicolas Haller
//
// 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.
//
// }}}

#include "ai.hh"
#include "config/config.hh"
#include "timer/timer.hh"
#include "ovision/see/ovision.hh"

static void
callback (void)
{
}

/// Constructeur
Ai::Ai(const Config & config)
    :motor_(config), es_(config), 
     schedulableMotor_ (callback, motor_.getFd ()),
     schedulableEs_ (callback, es_.getFd ()),
     roundDuration_(config.get<int>("ai.roundDuration")),
     vitesseAsc_(config.get<int>("ai.vitesseAsc"))
{
    scheduler_.insert (schedulableMotor_);
    scheduler_.insert (schedulableEs_);
}

/// Initialise le robot
void Ai::init(void)
{
    // Initialise les moteurs
    motor_.init();
    // initialise la carte es
    es_.init();
    // on init la vision
    oVision_.init(motor_.colorState() ? Group::redSkittle : 
	    			   Group::greenSkittle);
}

/// stop le robot
void Ai::stop(void)
{
    // Stop les moteurs
    motor_.stop();
}

/// Lance le robot
void Ai::run(void)
{
    // Attend l'entr�e du jack "pret � initialiser"
    waitJack(false);
    // Attend la premi�re sortie du jack(init)
    waitJack(true);
    //Initialise le robot
    init();
    // Attend le jack "pret � partir"
    waitJack(false);
    // Attend la seconde sortie du jack(Daniel)
    waitJack(true);
    // on lance le temps
    Timer::startRound();
    // Aller devant la boule
    goTo(10, 10, 0); // XXX Mauvaise valeur, changer valeur
    // Taper la boule
    basic(1245665486);  // XXX Mauvaise valeur, changer valeur
    // se placer devant nos quilles pr�s du pont
    basic(5568786);  // XXX Mauvaise valeur, changer valeur
    rotation(-M_PI / 2);
    goTo(4546,42424242, M_PI); // XXX Mauvaise valeur, changer valeur
    basic(56465456);  // XXX Mauvaise valeur, changer valeur
    // Apr�s attendre...  XXX Ou voir un truc qui bouge
    // Un truc
    // Detecter les quilles tomb�es (voir si se d�placer proches du rb adverses serait utiles)
    // Y Aller
    // remonter les quilles (voir si sharp sur ventouses serait utiles)
    // reculer
    // redetecter le tout
}

/// Attend.
void Ai::wait (int t)
{
}

// Attend le jack entr� (false) ou sorti (true).
void Ai::waitJack (bool out)
{
    while (motor_.jackState() != out)
	update();
}

/// Rejoint un point. (argument en mm)
void Ai::goTo (double x, double y ,double a)
{
    while (motor_.getX() != x || motor_.getY() != y)
    {
	motor_.goTo(x,y,a);
	update();
    }
}

/// Recale contre une bordure.
// XXX Voir ca plus pr�cisemment
void Ai::recale (void)
{
}

/// Mouvement basic.
void Ai::basic (double d)
{
    do
    {
	motor_.linearMove(d);
	update(); // XXX Et si on se prend un mur?????
    }
    while (!motor_.idle());
}

/// Rotation (argument en radian)
void Ai::rotation (double a)
{
    do
    {
	motor_.rotation(a);
	update();
    }while (!motor_.idle());
}

/// Monte(vrai) ou descend(faux) l'ascenceur
void Ai::ascenceur (bool monte)
{
    while(es_.getAscCurPos() != monte ? true : false)
    {
	//es_.moveAsc(monte);
	// XXX On peut r�gler la vitesse de l'asc( config min max acc haut et bas entier unit� ons'entape)
	update();
    }
}

/// D�sactive les ventouse
void Ai::ventouses (void) /// XXX Temps � r�gler dans la config
{
    es_.ventouses();
}

void Ai::update (void)
{
}