summaryrefslogtreecommitdiff
path: root/i/marvin/src/ai/ai.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/ai/ai.cc')
-rw-r--r--i/marvin/src/ai/ai.cc93
1 files changed, 80 insertions, 13 deletions
diff --git a/i/marvin/src/ai/ai.cc b/i/marvin/src/ai/ai.cc
index a24dcc7..1adcf5e 100644
--- a/i/marvin/src/ai/ai.cc
+++ b/i/marvin/src/ai/ai.cc
@@ -24,14 +24,16 @@
#include "ai.hh"
//constructeur
-Ai::Ai(const Config & config)
- :motor_(config), es_(config),
+Ai::Ai (const Config & config)
+ : motor_(config), es_(config), log_ ("Ai"),
schedulableMotor_(callback, motor_.getFd()),
schedulableEs_(callback, es_.getFd()),
- roundDuration_(config.get<int>("ai.roundDuration"))
+ round_duration_ (config.get<int> ("ai.round_duration")),
+ schedule_time_ (config.get<int> ("ai.schedule_time")),
+ reference_sensor_mask_ (config.get<int> ("ai.ref_sensor_mask"))
{
- scheduler_.insert(schedulableMotor_);
- scheduler_.insert(schedulableEs_);
+ scheduler_.insert (schedulableMotor_);
+ scheduler_.insert (schedulableEs_);
}
Ai::~Ai(void)
@@ -39,7 +41,7 @@ Ai::~Ai(void)
// On réinitialise
// Initialise les moteurs
// XXX
-// motor_.init ();
+ motor_.reset ();
// initialise la carte es
es_.reset ();
// On sync
@@ -49,18 +51,28 @@ Ai::~Ai(void)
}
while (!sync ());
}
+
// Initialisation du robal
void
-Ai::init(void)
+Ai::init (void)
{
// Initialisation de motor
- motor_.init ();
+ motor_.reset ();
// Initialisation de la carte Es
es_.reset ();
// Paf on sync
while (!update ());
}
+/// Stop the mouvement of the motor
+void
+Ai::stop (void)
+{
+ motor_.stop ();
+ // XXX In fact, we should wait a little here...
+ while (!update ());
+}
+
/// Synchronize data of under class
bool
Ai::sync (void)
@@ -69,17 +81,72 @@ Ai::sync (void)
}
/// Wait for something to happened
-bool Ai::update (void)
+bool
+Ai::update (void)
{
- scheduler_.schedule (100, true);
+ /// Wait schedule_time
+ scheduler_.schedule (schedule_time_, 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é !");
+ if (Timer::getRoundTime () > round_duration_)
+ throw std::runtime_error ("End of match ! You win !");
return retour;
}
+/// Function to wait a little but still syncing data
+void
+Ai::temporisation(int msec)
+{
+ // Get current time of process
+ int time = Timer::getProgramTime();
+ time += msec;
+ // Update until we have spend enough time
+ do
+ {
+ update();
+ }
+ while (time > Timer::getProgramTime());
+}
+
+/// Wait until jack is out (true) or in (false)
+void
+Ai::waitJack (bool out)
+{
+ do
+ {
+ udpate ();
+ }
+ while (es_.isJackOut () != out);
+}
+
+/// Init things for a match.
+void
+Ai::prepare (void)
+{
+ // XXX We should check if the jack is not already in
+ // We first wait for the jack to be put inside
+ waitJack (false);
+ // We reference all the color
+ referenceSensors ();
+ // We first wait for the jack to be put inside
+ waitJack (true);
+ // Ok the match begin ! Go go go !
+ Timer::startRound ();
+}
+
+/// Reference sensors
+void
+Ai::referenceSensors (void)
+{
+ // Reference sensors
+ es_.refColor (reference_sensor_mask_);
+ // Update data
+ while (!update ());
+ // Disable capturing all sensors
+ es_.enableAllSensors (false);
+ // Update data
+ while (!update ());
+}
/// programme d'homologation du robal
void Ai::progHomoloRobal(void)