// 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("ai.roundDuration")), vitesseAsc_(config.get("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); /// XXX } /// 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(); // On recule dans le mur recale (); // On avance vers la position de départ en y basic (155); // 215 - 60 = 155 // On rotate de 90 ° rotation (0); // On se recale vers x recale(); // Attend le jack "pret à partir" waitJack(false); // Attend la seconde sortie du jack(Daniel) waitJack(true); // on lance le temps Timer::startRound(); // On temporise pour laisser Taz sortir temporisation(500); // On avance pour pouvoir aller vers la boule parallèlement au socle basic(540); // 600 - 60 // Aller devant la boule goTo(1200, -975, M_PI); // Taper la boule basic(-220); // se placer devant nos quilles près du pont basic(220); // On va derière les quilles goTo(motor_.getX(),motor_.getY() - 150 ,M_PI); /// Mauvaise valeur, changer valeur // On set la vitesse à 2 int MaxLSpeedConf = motor_.getMaxLSpeed(); motor_.setMaxSpeed(2, -1); // On colle les quilles basic (-250); // 260 - 10 de marge // On retaure la vitesse motor_.setMaxSpeed(MaxLSpeedConf, -1); // On temporise.... temporisation(200); // XXX Mauvaise valeur, changer valeur } /// Attend. void Ai::wait (int t) { motor_.wait(t); throw std::runtime_error("nan faut pas utiliser"); } /// Fonction de temporisation void Ai::temporisation(int t) { int time = Timer::getRoundTime(); time += t; while (time > Timer::getRoundTime()) { update(); } } // 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) { motor_.goTo(x,y,a); do { update(); }while(!motor_.idle()); } /// Recale contre une bordure. // XXX Voir ca plus précisemment void Ai::recale (void) { motor_.recalage(); do { update(); } while(!motor_.idle()); double angle = motor_.getA(); if(angle > M_PI / 4 && angle < (3 * M_PI) / 4) // Si on point vers la droite { motor_.setPosition(motor_.getX(), -60, -M_PI / 2); } else if (angle < M_PI / 4 || angle > (7 * M_PI) / 4) // Si on pointe vers 0 { motor_.setPosition(60, motor_.getY(), 0); } else // On pointe vers y { motor_.setPosition(motor_.getX(), -2040, 0); } } /// Mouvement basic. void Ai::basic (double d) { motor_.linearMove(d); do { update(); // XXX Et si on se prend un mur????? } while (!motor_.idle()); } /// Rotation (argument en radian) void Ai::rotation (double a) { motor_.rotation(a); do { update(); }while (!motor_.idle()); // XXX Gérer le cas d'une rotation trop petite } /// Monte(vrai) ou descend(faux) l'ascenceur void Ai::ascenceur (bool monte) { if (monte) es_.monterAsc(); else es_.descendreAsc(); do { update(); } while(!es_.ascIsIdle()); } /// Désactive les ventouse void Ai::ventouses (void) /// XXX Temps à régler dans la config { es_.ventouses(); update(); } bool Ai::update (void) { scheduler_.schedule(); motor_.sync(); es_.sync(); // Gestion des cas critiques /// XXX return true; }