summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ai
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/ai')
-rw-r--r--2005/i/robert/src/ai/Makefile.defs2
-rw-r--r--2005/i/robert/src/ai/ai.cc45
-rw-r--r--2005/i/robert/src/ai/ai.hh8
-rw-r--r--2005/i/robert/src/ai/test_ai.cc101
4 files changed, 124 insertions, 32 deletions
diff --git a/2005/i/robert/src/ai/Makefile.defs b/2005/i/robert/src/ai/Makefile.defs
index 6f13fcf..e64ce6e 100644
--- a/2005/i/robert/src/ai/Makefile.defs
+++ b/2005/i/robert/src/ai/Makefile.defs
@@ -7,4 +7,6 @@ $(asserv_OBJECTS) $(proto_OBJECTS) $(utils_OBJECTS) $(serial_OBJECTS) \
$(timer_OBJECTS) $(config_OBJECTS) $(scheduler_OBJECTS) $(es_OBJECTS) \
$(ovision_OBJECTS) $(video4linux_OBJECTS) $(image_OBJECTS)
+
test_ai: $(test_ai_OBJECTS)
+test_ai: LDFLAGS += -static
diff --git a/2005/i/robert/src/ai/ai.cc b/2005/i/robert/src/ai/ai.cc
index 7cd50ab..b3b4f09 100644
--- a/2005/i/robert/src/ai/ai.cc
+++ b/2005/i/robert/src/ai/ai.cc
@@ -52,7 +52,10 @@ Ai::Ai(const Config & config)
Ai::~Ai (void)
{
// On réinitialise
- init ();
+ // Initialise les moteurs
+ motor_.init();
+ // initialise la carte es
+ es_.init();
// On sync
do
{
@@ -71,8 +74,8 @@ void Ai::init(void)
// initialise la carte es
es_.init();
// on init la vision
- oVision_.init(motor_.colorState() ? Group::redSkittle :
- Group::greenSkittle);
+// oVision_.init(motor_.colorState() ? Group::redSkittle :
+// Group::greenSkittle);
while (!update());
}
@@ -235,7 +238,21 @@ Ai::setAccel (int a)
{
motor_.setAccel (a);
while (!update ());
-}/*}}}*/
+}
+
+/// Renvoye l'état du bouton de sélection de couleur.
+bool
+Ai::colorBouton (void)
+{
+ return motor_.colorState ();
+}
+/// Renvoye si l'objet devant nous est trop prêt.
+bool
+Ai::objectInFront (void)
+{
+ return es_.obsTropPres ();
+}
+/*}}}*/
// *** Les runs ***/*{{{*/
// Balistique non fiable.
@@ -268,6 +285,16 @@ Ai::runProtectFond (void)
parcourtFond ();
}
+void Ai::runVisionLine(void)
+{
+ init();
+ initTest();
+ do
+ {
+ scanVision(true);
+ basic(100);
+ }while(motor_.getY() < 1700);
+}
// Pour les Tests.
void
Ai::runTest (void)
@@ -410,11 +437,11 @@ void Ai::scanVision (bool followLine) /// XXX mettre un argument
for (int i = 0; i < (followLine ? 1 : 4) ; i++)
{
// On prend la photo
- oVision_.takeShoot();
- // On analyse la photo
- oVision_.update();
+// oVision_.takeShoot();
+// // On analyse la photo
+// oVision_.update();
// On mets la liste brute dans le vector
- skittles.push_back(oVision_.getSkittles());
+// skittles.push_back(oVision_.getSkittles());
// on tournicote
motor_.rotation(angleDepart + ((i + 1) * M_PI/4));
}
@@ -452,7 +479,7 @@ void Ai::remonteWithCam(void)
{
int x, y , angle, dist;
Zone zeSkittles = goodSkittles_.back();
- oVision_.getLoc(zeSkittles, x, y, angle, dist);
+// oVision_.getLoc(zeSkittles, x, y, angle, dist);
dist -= 9;
rotation(motor_.getA() + angle);
setMaxSpeed(2,1);
diff --git a/2005/i/robert/src/ai/ai.hh b/2005/i/robert/src/ai/ai.hh
index 8454706..6867031 100644
--- a/2005/i/robert/src/ai/ai.hh
+++ b/2005/i/robert/src/ai/ai.hh
@@ -40,7 +40,7 @@ class Ai
// Modules de controle du robot
Motor motor_;
Es es_;
- OVision oVision_;
+// OVision oVision_;
// Scheduler du robot
scheduler::Scheduler scheduler_;
scheduler::SchedulableReadFd schedulableMotor_;
@@ -87,6 +87,12 @@ class Ai
bool sync (void);
/// Reset la PWM à zéro.
void resetPwm (void);
+ /// Renvoye l'état du bouton de sélection de couleur.
+ /// Bas - vert - faux
+ /// Haut - rouge - vrai
+ bool colorBouton (void);
+ /// Renvoye si l'objet devant nous est trop prêt.
+ bool objectInFront (void);
// Balistique non fiable.
void runBalNonFiable (void);
diff --git a/2005/i/robert/src/ai/test_ai.cc b/2005/i/robert/src/ai/test_ai.cc
index f205819..03a1642 100644
--- a/2005/i/robert/src/ai/test_ai.cc
+++ b/2005/i/robert/src/ai/test_ai.cc
@@ -75,24 +75,27 @@ main (int argc, char **argv)
if (++i > argc)
throw std::runtime_error ("syntax error");
switch (argv[i][0])
- {
- case '0':
+ {
+ case '0':
// Pour un robot qui n'est pas fiable en
// asservissement
ai_.runBalNonFiable();
break;
- case '1':
+ case '1':
ai_.runBalFiable ();
break;
- case '2':
+ case '2':
ai_.runTest ();
break;
- case '3':
+ case '3':
ai_.runProtectFond ();
break;
- default:
+ case '4':
+ ai_.runVisionLine ();
+ break;
+ default:
throw std::runtime_error ("Param inconnue");
- }
+ }
break;
case 'j':
if(++i > argc)
@@ -130,34 +133,88 @@ main (int argc, char **argv)
ai_.rotation(strtod(argv[i], 0));
break;
case 'A':
- if(++i + 1 > argc)
+ if(++i > argc)
throw std::runtime_error("syntax error");
-// switch(argv[i])
-// {
-// case '0':
-// ai.moveAsc(BAS);
-// break;
-// case '1':
-// ai.moveAsc(MILIEU);
-// break;
-// case '2':
-// ai.moveAsc(HAUT);
-// break;
-// }
+ switch(argv[i][0])
+ {
+ case '0':
+ ai_.ascenceur(false);
+ break;
+ case '1':
+ ai_.ascenceur(true);
+ break;
+ default:
+ throw std::runtime_error ("Param inconnue");
+ break;
+ }
break;
case 'v':
ai_.ventouses();
break;
case 'U':
- ai_.update();
+ while (!ai_.update());
break;
case 'z':
ai_.init();
break;
+ case 't':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ ai_.temporisation (argv[i][0]);
+ case 'o':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ switch (argv[i][0])
+ {
+ case '0':
+ while (true)
+ {
+ while (!ai_.update ());
+ if (ai_.objectInFront())
+ std::cout << "Objet devant" << std::endl;
+ else
+ std::cout << "Pas d'objet devant" << std::endl;
+ }
+ break;
+ case '1':
+ while (!ai_.update ());
+ if (ai_.objectInFront())
+ std::cout << "Objet devant" << std::endl;
+ else
+ std::cout << "Pas d'objet devant" << std::endl;
+ }
+ break;
+ case 'c':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ switch (argv[i][0])
+ {
+ case '0':
+ while (true)
+ {
+ while (!ai_.update ());
+ if (ai_.colorBouton())
+ std::cout << "Couleur vraie" << std::endl;
+ else
+ std::cout << "Couleur faux" << std::endl;
+ }
+ break;
+ case '1':
+ while (!ai_.update ());
+ if (ai_.colorBouton())
+ std::cout << "Couleur V" << std::endl;
+ else
+ std::cout << "Couleur F" << std::endl;
+ break;
+ default:
+ throw std::runtime_error ("Param inconnue");
+ }
+ break;
+ break;
default:
throw std::runtime_error ("Error de syntaxe");
}
- ai_.update ();
+ ai_.update (); // XXX à virer ?
break;
}
case 'w':