summaryrefslogtreecommitdiff
path: root/i/marvin/src/ai
diff options
context:
space:
mode:
authordufourj2006-05-24 12:22:45 +0000
committerdufourj2006-05-24 12:22:45 +0000
commit55e5056593ad021213e97c6418382ac051d85d93 (patch)
tree362c719cf38bb4d6e4949dc0b72bb73cc8304112 /i/marvin/src/ai
parent75192e6d726a30bde79482cdcdf11477233165a6 (diff)
Ai :
- commit de travaille. Es : - merge des fonctions du barillet. ES : - protection contre l'analyse quand les capteurs sont pas pret ; - fonction de gestion capteur RVB frontaux seulement.
Diffstat (limited to 'i/marvin/src/ai')
-rw-r--r--i/marvin/src/ai/ai.cc34
-rw-r--r--i/marvin/src/ai/ai.hh9
-rw-r--r--i/marvin/src/ai/test_ai.cc38
3 files changed, 75 insertions, 6 deletions
diff --git a/i/marvin/src/ai/ai.cc b/i/marvin/src/ai/ai.cc
index d869eae..1ad1df3 100644
--- a/i/marvin/src/ai/ai.cc
+++ b/i/marvin/src/ai/ai.cc
@@ -38,13 +38,14 @@ Ai::~Ai(void)
{
// On réinitialise
// Initialise les moteurs
- motor_.init();
+ // XXX
+// motor_.init ();
// initialise la carte es
- es_.init();
+ es_.reset ();
// On sync
do
{
- scheduler_.schedule(500, true);
+ scheduler_.schedule (500, true);
}
while (!sync ());
}
@@ -53,9 +54,30 @@ void
Ai::init(void)
{
// Initialisation de motor
- motor_.init();
+ motor_.init ();
// Initialisation de la carte Es
- es_.init();
+ es_.reset ();
// Paf on sync
- while(!update());
+ while (!update ());
}
+
+/// Synchronize data of under class
+bool
+Ai::sync (void)
+{
+ return es_.sync () && motor_.sync ();
+}
+
+/// Wait for something to happened
+bool Ai::update (void)
+{
+ scheduler_.schedule (100, true);
+ bool retour = sync ();
+ // On vérifie que le match n'est pas fini
+ if (Timer::getRoundTime () > roundDuration_)
+ throw std::runtime_error ("Fin de match, merci d'avoir
+ participé !");
+ return retour;
+}
+
+
diff --git a/i/marvin/src/ai/ai.hh b/i/marvin/src/ai/ai.hh
index 89f2cd3..bde4c4a 100644
--- a/i/marvin/src/ai/ai.hh
+++ b/i/marvin/src/ai/ai.hh
@@ -25,12 +25,21 @@
// }}}
/// Intelligence supérieur(à celui d'une balle de ping-pong) artificielle
/// (comme une blonde) du robot.
+
+#include "motor/motor.hh"
+#include "es/es.hh"
+#include "scheduler/scheduler.hh"
+#include "scheduler/schedulable_read_fd.hh"
+#include "log/log.hh"
+
class Ai
{
private:
// Modules de contrôles du robot
Motor motor_;
Es es_;
+ /// Logger
+ Log log_;
// Le scheduler
scheduler::Scheduler scheduler_;
scheduler::SchedulableReadFd schedulableMotor_;
diff --git a/i/marvin/src/ai/test_ai.cc b/i/marvin/src/ai/test_ai.cc
new file mode 100644
index 0000000..9412277
--- /dev/null
+++ b/i/marvin/src/ai/test_ai.cc
@@ -0,0 +1,38 @@
+// test_ai.cc
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// 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 "tester/tester.hh"
+#include "ai/ai.hh"
+
+class TestAI : public Tester
+{
+ private:
+ Ai ai_;
+ /// Called after each command
+ void postcall (void)
+ {
+ // Update ?
+ }
+}