summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/qia/qia.cc
diff options
context:
space:
mode:
Diffstat (limited to '2003/i/buzz/src/qia/qia.cc')
-rw-r--r--2003/i/buzz/src/qia/qia.cc146
1 files changed, 146 insertions, 0 deletions
diff --git a/2003/i/buzz/src/qia/qia.cc b/2003/i/buzz/src/qia/qia.cc
new file mode 100644
index 0000000..79eba39
--- /dev/null
+++ b/2003/i/buzz/src/qia/qia.cc
@@ -0,0 +1,146 @@
+// qia.cc
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+//
+#include "qia.h"
+#include "config/config.h"
+
+// Constructeur.
+QIa::QIa (bool vert)
+{
+ Config rc ("rc/qia");
+ m_pathSize = 0;
+ while (!rc.eof ())
+ {
+ if (rc.isId ("path"))
+ {
+ rc.getId ();
+ while (!rc.eof ())
+ {
+ m_path.push_back (rc.getNum ());
+ m_pathSize++;
+ }
+ }
+ else rc.noId ();
+ }
+ // Initialisation.
+ m_pathNext = 0;
+ m_vert = vert;
+}
+
+// Lance l'automate.
+void
+QIa::go (void)
+{
+ // Reset les cartes.
+ m_motor.reset ();
+ // Positionne les servos.
+ m_motor.setServo (1);
+ m_motor.setServo (8);
+ // Attend le jack.
+ m_motor.waitRound ();
+ // Démare le chrono.
+ m_date.startRound ();
+ // Lit le chemin.
+ int d;
+ while (m_pathNext < m_pathSize)
+ {
+ d = m_path[m_pathNext++];
+ if (!d)
+ // Virages.
+ turn ();
+ else
+ // Sections droites.
+ ahead (d);
+ }
+ // Stop, on bouge plus.
+ while (1) Date::wait (999);
+}
+
+// Tourne.
+void
+QIa::turn (void)
+{
+ int a = m_path[m_pathNext++];
+ m_motor.turnAngle (a);
+ while (!m_motor.finnish ()) Date::wait (50);
+}
+
+// Tout droit.
+void
+QIa::ahead (int d)
+{
+ while (!m_motor.finnish ())
+ {
+ // Fait avancer le moteur.
+ m_motor.goDistance (d);
+ // Mémorise la distance parcourue.
+ //m_motor.setDone ();
+ // Tant que ça roule.
+ while (!m_motor.finnish ())
+ {
+ Date::wait (50);
+ // Teste la barière
+ if (m_motor.getCapteurs () & 0x20)
+ {
+ while (!m_motor.getCapteurs () & 0x20)
+ {
+ Date::wait (10);
+ m_motor.readMsg ();
+ }
+// // Avance tout doucement.
+// m_motor.goDistance (150, 25);
+// // Jusqu'au capteur barrière ou rien trouvé.
+// while (!m_motor.finnish () &&
+// !(m_busp.getCapteurs ().get () & 0x02))
+// {
+// m_motor.readMsg ();
+// Date::wait (50);
+// }
+// // Arrète le moteur.
+// m_motor.stop ();
+// while (!m_motor.finnish ())
+// {
+// m_motor.readMsg ();
+// Date::wait (50);
+// }
+ // Regarde la couleur.
+ if ((m_motor.getCapteurs () & 0x80) && m_vert
+ || !(m_motor.getCapteurs () & 0x80) && !m_vert)
+ {
+// // Repart dans l'autre sens.
+// m_motor.go (-25);
+// while (m_busp.getCapteurs ().get () & 0x02)
+// {
+// m_motor.readMsg ();
+// Date::wait (50);
+// }
+// // Stop.
+// m_motor.stop ();
+// while (!m_motor.finnish ())
+// {
+// m_motor.readMsg ();
+// Date::wait (50);
+// }
+ // Retourne le palet.
+ m_motor.setServo (7);
+// // Recule.
+// m_motor.goDistance (-30);
+// // Réavance le robot.
+// m_motor.goDistance (140, 25);
+// while (!m_motor.finnish ())
+// {
+// m_motor.readMsg ();
+// Date::wait (50);
+// }
+ Date::wait (2000);
+ // Retourne les doigts.
+ m_motor.setServo (8);
+ }
+ }
+ // Lit la distance parcourue.
+ //d -= m_motor.getDone ();
+ continue;
+ }
+ }
+}