// 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" /// Constructeur Ai::Ai(const Config & config) :motor_(config), es_(config), roundDuration_(config.get("ai.roundDuration")), vitesseAsc_(config.set("ai.vitesseAsc")) { } /// Initialise le robot void Ai::init(void) { // Initialise les moteurs motor_.init(); // initialise la carte es es_.init(); // on init la vision ovision_.init(es_.getColor() ? Group::ZoneType::RedSkittle : Group::ZoneType::GreenColor); } /// 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::start_round(); // Aller devant la boule goTo(x, y, 0); // Taper la boule basic(d); // se placer devant nos quilles près du pont basic(-d); rotation(-M_PI / 2); goTo(x,y, M_PI); basic(-d); // 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 le jack entré (false) ou sorti (true). void Ai::waitJack (bool out) { while (es_.stateJack() != 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) { while(!es_.capteursContact()) { motor_.recalage(); update(); } } /// 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_.stateAsc() != 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(); while(!es_.stateVentouses()) // XXX Ca, ca doit servir à rien update(); }