summaryrefslogtreecommitdiff
path: root/i/chuck/src/ai/ai.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/chuck/src/ai/ai.cc')
-rw-r--r--i/chuck/src/ai/ai.cc283
1 files changed, 206 insertions, 77 deletions
diff --git a/i/chuck/src/ai/ai.cc b/i/chuck/src/ai/ai.cc
index da62abd..c84dcd5 100644
--- a/i/chuck/src/ai/ai.cc
+++ b/i/chuck/src/ai/ai.cc
@@ -1,4 +1,4 @@
-// ai.cc
+//ai.cc
// chuck - programme du robot 2007 {{{
//
// Copyright (C) 2007 Romain Becquet
@@ -48,7 +48,7 @@ Ai::Ai (const Config & config)
Ai::~Ai(void)
{
- // On réinitialise
+ // On réinitialise
// Initialise les moteurs
// XXX
motor_.reset();
@@ -81,6 +81,7 @@ Ai::stop (void)
motor_.stop ();
// XXX In fact, we should wait a little here...
while (!update ());
+ temporisation (500);
}
/// Synchronize data of under class
@@ -99,7 +100,7 @@ Ai::update (void)
/// Wait schedule_time
scheduler_.schedule (schedule_time_, true);
bool retour = sync ();
- // On vérifie que le match n'est pas fini
+ // On vérifie que le match n'est pas fini
if (Timer::getRoundTime () > round_duration_)
throw std::runtime_error ("End of match ! You win !");
return retour;
@@ -137,6 +138,7 @@ Ai::prepare (void)
{
es_.lcdPrint("");
es_.lcdPrint("Prepa match...");
+ es_.initservo();
es_.lcdPrint("G ma couleur");
es_.lcdPrint("Inserer Jack");
std::cout<<"insere jak"<<std::endl;
@@ -155,23 +157,21 @@ Ai::prepare (void)
motor_.getAsserv().setPos(0,0,0);
// Ok the match begin ! Go go go !
Timer::startRound ();
- //on fait tomber le roulo apré le top départ
- es_.roulo_tombe();
- temporisation(1500);
- es_.roulo_roule(0xDD);
- es_.setOthersStat (0);
- std::cout<<"le roulo auré du tombé"<<std::endl;
+ //on fait tomber le roulo apré le top départ
+ rouloAction();
+ std::cout<<"le roulo auré du tombé"<<std::endl;
// Shut up fucking beach !
es_.setOthersStat (0);
es_.setOthersStat (0);
while (!update ());
+ es_.launchSharpDetection();
}
/// Some after after a match
void
Ai::afterMatch(void)
{
- // On attend de mettre le jack après le match
+ // On attend de mettre le jack après le match
es_.lcdPrint("FIN DU MATCH");
// es_.lcdPrint("Inserer jack...");
while (!update());
@@ -186,96 +186,172 @@ Ai::afterMatch(void)
while (!update());
}
+void Ai::progH2(void)
+{
+ init();
+ prepare();
+ es_.roulo_roule(0x00);
+ motorMove(2660.,0.);
+ es_.roulo_roule(0x50);
+ motorMove(1000.,0.);
+
+}
/// programme d'homologation du robal
void Ai::progHomoloRobal(void)
{
- /// On init le robal
- prepare();
+// double dummy, aStart, aEnd;
+
+ // Init of cards
+ init ();
+ /// On prépare le robot
+
+ prepare();
+ log_("match") << "fin prepare";
+/// Faire des crêpes...
while (!update ());
- temporisation (1000);
+ /// En avant guingamp
+ log_ ("match") << "Eloignement du bord";
+ motorMove(1500,0.);//On fonce tout droit
while (!update ());
- /// on avance un poil parce que le mur c'est mal
- std::cout << "Move !" << std::endl;
- motorMove(500, 0);
- std::cout << "Rotate !" << std::endl;
- motorRotate(-0.54);
- std::cout << "Move !" << std::endl;
- motorMove(1200, 0);
- std::cout << "Rotate !" << std::endl;
- motorRotate(1.40);
- motorMove(500, 0);
-// temporisation (100);
- std::cout << "Find hole !" << std::endl;
-
- /// On tourne XXX
-/// motorRotate(-M_PI/4);
- /// On cherche au moins une balle (sinon c'est con)
-/// motorMove(1000, 0); /// XXX Voir la distance
- /// XXX Avancer d'une certaine facon pour choper des balles
- /// XXX Ouais ba y'a encore ddes truc à faire là
- /// On cherche un tru (repositionnement??)
-/// motor_.lockGoodHole();
-/// while (!update ());
-/// motor_.findHole();
-/// while (!update ());
- /// On trouve un trou, chouette
- /// Aspirer le trou
- //es_.extraitBalle();
- /// mettre une baballe
+ /// On tourner de 45°
+ log_ ("match") << "Petite rotation de 35°";
+ motorRotate((0.8)*(coefcolor));
+ while(!update());
+ std::cout<<"première rot"<<std::endl;
+ ///On avance a travers les ordures euh on est sensé en ramacer
+ std::cout<<"je traverse en diag"<<std::endl;
+ motorMove(1420.,0.);
+
+
+ log_("match") << "Start rotation";
+ ///On se positionne pour la marche arrière
+ motorRotate(R45*(5)*(coefcolor));
+
+ ///tuuutuuuutuuuuu je fait mon crénau
+ log_ ("match") << "Creneau";
+ //bool ok = motor_.docreno();
+ std::cout<<"je recule"<<std::endl;
+ temporisation (1000);
+// motorMove(-500.,0.);
+ fuckTheWall ();
+
+ log_ ("match") << "fin fuck";
+motorMove(200.0,0.);
+ motorRotate(R90*coefcolor*(-2));
+
+do
+{
+fuckTheWall();
+
+// Move asc up;
+ moveAsc (true);
+temporisation(500);
+
+ es_.roulo_roule (0);
+bougeAsc(0xff,0x05,false);
+ temporisation(200);
+ bougeAsc(0xff,0x05,true);
+ temporisation(200);
+bougeAsc(0xff,0x05,false);
+ temporisation(200);
+ bougeAsc(0xff,0x05,true);
+ temporisation(200);
+
+ /*es_.roulo_roule (0);*/
+ while(!update());
+ temporisation(2000);
+
+
+ // Move asc down
+ moveAsc (false /* down */);
+
+ temporisation(2000);
+ motorMove(100.,0.);
+}while(1);
+ es_.roulo_roule (0);
+
+
+// // Move asc up
+// moveAsc (true /* up */);
+// temporisation(2000);
+//
+// // Move asc down
+// moveAsc (false /* down */);
+// temporisation(2000);
+
+while(!update());
+ temporisation(2000);
+ /*rouloAction();*/
+
+ /*
while (!update ());
- temporisation (3000);
+ //on avance un peu
+ motorMove(400.,0.);
+ //direction le tas d'ordure
while (!update ());
- temporisation (3000);
- motorMove(300, 0);
+ motorRotate(R45*(-1)*coefcolor);
+ motorMove(450.,0.);
+
while (!update ());
- temporisation (3000);
+ //demitour
+ motorRotate(R90);
while (!update ());
- temporisation (3000);
- motorMove(300, 0);
- /// Tourner 3 fois en chantant du Mickael Jackson
- /// Again....
- /// Fin du match
- afterMatch();
+
+ motorMove(450.,0.);
+*/
+
+ /* Save angle */
+ /*motor_.getPosition (dummy, dummy, aStart);*/
+ /* afterMatch();*/
+}
+
+void
+Ai::fuckTheWall (void)
+{
+ motor_.fuckTheWall ();
+ do
+ {
+ update ();
+ } while (!motor_.finish ());
}
void
Ai::progMatch(void)
{
- double dummy, aStart, aEnd;
+ double dummy, aStart; // aEnd;
// Init of cards
init ();
- /// On prépare le robot
+ /// On prépare le robot
prepare();
- /// Faire des crêpes...
+ log_("match") << "fin prepare";
+ /// Faire des crêpes...
while (!update ());
/// En avant guingamp
log_ ("match") << "Eloignement du bord";
- motorMove(1300,0);//On fonce tout droit
+ motorMove(1700.,0.);//On fonce tout droit
while (!update ());
- /// On tourner de 45°
- log_ ("match") << "Petite rotation de 45°";
- motorRotate(R45*(coefcolor));
+ /// On tourner de 45°
+ log_ ("match") << "Petite rotation de 45°";
+ motorRotate(R35*(coefcolor));
- std::cout<<"première rot"<<std::endl;
- ///On avance a travers les ordures euh on est sensé en ramacer
- motorMove(1900.,0.);
+ std::cout<<"première rot"<<std::endl;
+ ///On avance a travers les ordures euh on est sensé en ramacer
+ std::cout<<"je traverse en diag"<<std::endl;
+ motorMove(1000.,0.);
-
-
-
- while(!update())
- {
-
- ///On se positionne pour la marche arrière
+ log_("match") << "fin prepare";
+ ///On se positionne pour la marche arrière
motorRotate(R45*(5)*(coefcolor));
- ///tuuutuuuutuuuuu je fait mon crénau
+ ///tuuutuuuutuuuuu je fait mon crénau
log_ ("match") << "Creneau";
//bool ok = motor_.docreno();
- motorMove(-500.,0.);
- es_.bouge_ascenceur(0x50,0xFF,0x00);
-
+
+ motorMove(-10.,0.);
+ std::cout<<"je recule"<<std::endl;
+ es_.bouge_ascenceur();
+ temporisation(2000);
while (!update ());
//on avance un peu
motorMove(400.,0.);
@@ -291,26 +367,23 @@ Ai::progMatch(void)
motorMove(450.,0.);
- }
/* Save angle */
motor_.getPosition (dummy, dummy, aStart);
afterMatch();
}
-/// Avance le robal et dit si il a finit (true) ou si il a bloqué
+/// Avance le robal et dit si il a finit (true) ou si il a bloqué
bool
Ai::motorMove (double d, double a)
{
double xStart, yStart, xCur, yCur, dummy;
motor_.getPosition (xStart, yStart, dummy);
-
motor_.move(d, a); /// XXX Voir la distance
do
{
update ();
if(es_.getSharpAck())
{
- // Stop !
stop ();
// Go back a little bit
motor_.move (-100, 0);
@@ -318,6 +391,7 @@ Ai::motorMove (double d, double a)
{
update ();
} while (!motor_.finish ());
+ temporisation (1000);
// Get current position
motor_.getPosition (xCur, yCur, dummy);
// Re eanble sharps
@@ -325,7 +399,7 @@ Ai::motorMove (double d, double a)
// Go to the position we want first
double xDiff = xStart - xCur;
double yDiff = yStart - yCur;
- motor_.move (sqrt (xDiff * xDiff + yDiff * yDiff), 0);
+ motor_.move (d - sqrt (xDiff * xDiff + yDiff * yDiff), 0);
}
}
while (!motor_.finish ()/* && !motor_.blocked()*/);
@@ -355,5 +429,60 @@ Ai::avoidrobot(void)
{
es_.launchSharpDetection();
+
+}
+void
+Ai::launchSharp (void)
+{
+ es_.launchSharpDetection ();
+ while (!update ());
+}
+///action du roulo
+void
+Ai::rouloAction(void)
+{
+ es_.roulo_tombe();
+ temporisation(1500);
+ es_.roulo_roule(0x50);
+}
+void
+Ai::test_ascenseur (void)
+{
+ es_.moveAsc (0x70, 0xde, true);
+ while (!update ());
+ temporisation (6000);
+ es_.moveAsc (0x70, 0xFF, false);
+ temporisation (1000);
+ es_.moveAsc (0x70, 0x30, false);
+// es_.bougeascDown ();
+ while (!update ());
+}
+
+void
+Ai::moveAsc (bool up)
+{
+ if (up)
+ {
+ bougeAsc (0x70, 0xE5, up);
+ while (!update ());
+ temporisation (6000);
+ }
+ else
+ {
+ bougeAsc (0x70, 0xFF, up);
+ while (!update ());
+ temporisation (4000);
+ bougeAsc (0x70, 0x30, up);
+ while (!update ());
+ temporisation (1000);
+ }
+ while (!update ());
+}
+
+void
+Ai::bougeAsc (int speed, int time, bool up)
+{
+ es_.moveAsc (speed, time, up);
+ while (!update ());
}