summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/qia
diff options
context:
space:
mode:
authorschodet2003-09-10 20:18:46 +0000
committerschodet2003-09-10 20:18:46 +0000
commit78c6eb9bba686db209f9eb0886b5f3b2c0af3a33 (patch)
tree6a5d77e05cd6dcaa88eca8fa6921fc35abd31296 /2003/i/buzz/src/qia
parente40722474578d38fb31f4aa97af49904eda75544 (diff)
Apres 2003
Diffstat (limited to '2003/i/buzz/src/qia')
-rw-r--r--2003/i/buzz/src/qia/Makefile.defs4
-rw-r--r--2003/i/buzz/src/qia/qbuzz.cc16
-rw-r--r--2003/i/buzz/src/qia/qia.cc146
-rw-r--r--2003/i/buzz/src/qia/qia.h34
4 files changed, 200 insertions, 0 deletions
diff --git a/2003/i/buzz/src/qia/Makefile.defs b/2003/i/buzz/src/qia/Makefile.defs
new file mode 100644
index 0000000..df06f6a
--- /dev/null
+++ b/2003/i/buzz/src/qia/Makefile.defs
@@ -0,0 +1,4 @@
+TARGETS += qbuzz
+qbuzz_SOURCES = qbuzz.cc qia.cc motor.a serial.a erreur.a config.a date.a
+
+qbuzz: $(qbuzz_SOURCES:%.cc=%.o)
diff --git a/2003/i/buzz/src/qia/qbuzz.cc b/2003/i/buzz/src/qia/qbuzz.cc
new file mode 100644
index 0000000..e0e4fe6
--- /dev/null
+++ b/2003/i/buzz/src/qia/qbuzz.cc
@@ -0,0 +1,16 @@
+// qbuzz.cc
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+#include "motor/motor.h"
+#include "busp/busp.h"
+#include "qia.h"
+
+
+int
+main (int argc, char **argv)
+{
+ bool vert = argc >= 2 && argv[1][0] == 'v';
+
+ QIa qia (vert);
+ qia.go ();
+}
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;
+ }
+ }
+}
diff --git a/2003/i/buzz/src/qia/qia.h b/2003/i/buzz/src/qia/qia.h
new file mode 100644
index 0000000..069d057
--- /dev/null
+++ b/2003/i/buzz/src/qia/qia.h
@@ -0,0 +1,34 @@
+#ifndef qia_h
+#define qia_h
+// qia.h - Ia, vite fait...
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+#include "motor/motor.h"
+#include "date/date.h"
+#include "busp/busp.h"
+
+#include <vector>
+
+
+class QIa
+{
+ // Objets instanciés
+ Motor m_motor;
+ Date m_date;
+ // Chemin utilisé.
+ vector<int> m_path;
+ int m_pathNext, m_pathSize;
+ // Couleur des palets.
+ bool m_vert;
+ public:
+ // Constructeur.
+ QIa (bool vert);
+ // Lance l'automate.
+ void go (void);
+ // Tourne.
+ void turn (void);
+ // Tout droit.
+ void ahead (int d);
+};
+
+#endif // qia_h