summaryrefslogtreecommitdiff
path: root/i/marvin/src/ai
diff options
context:
space:
mode:
authordufourj2006-05-24 20:13:50 +0000
committerdufourj2006-05-24 20:13:50 +0000
commit08c46b0aa2c1791ca404a60ca0f75e4687553076 (patch)
treed0b97fb8acc6da521a1be51de87c113090be0d91 /i/marvin/src/ai
parent78a8f07f655dc7ff426d87001f3ca4d6a8365ded (diff)
Ai :
- rajout de parametres ; - rajout de fonctions. Es : - fonctions de gettage de jack/couleur de sélection.
Diffstat (limited to 'i/marvin/src/ai')
-rw-r--r--i/marvin/src/ai/ai.cc93
-rw-r--r--i/marvin/src/ai/ai.hh11
2 files changed, 89 insertions, 15 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)
diff --git a/i/marvin/src/ai/ai.hh b/i/marvin/src/ai/ai.hh
index 2883be9..25bba63 100644
--- a/i/marvin/src/ai/ai.hh
+++ b/i/marvin/src/ai/ai.hh
@@ -45,7 +45,9 @@ class Ai
scheduler::SchedulableReadFd schedulableMotor_;
scheduler::SchedulableReadFd schedulableEs_;
// Paramètres générales du robot
- const int RoundDuration_;
+ const int round_duration_;
+ const int schedule_time_;
+ const int reference_sensor_mask_;
public:
/// Constructeur
Ai(const Config & config);
@@ -57,7 +59,6 @@ class Ai
/// Arrête complêtement le robot
void stop(void);
/// Fonction de tempo
- /// XXX Vérifier que ce soit bien des milisec
void temporisation (int msec);
/// Attend le jack rentre(false) ou sorte (true)
void waitJack (bool out);
@@ -65,6 +66,12 @@ class Ai
bool update (void);
/// La célèbre fonction sync
bool sync (void);
+ /// Stop the mouvement of the motor
+ void stop (void);
+ /// Init things for a match.
+ void prepare (void);
+ /// Reference sensors
+ void referenceSensors (void);
/// programme d'homologation du robal
void progHomoloRobal(void);
};