summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleblanc2007-03-10 17:42:07 +0000
committerleblanc2007-03-10 17:42:07 +0000
commit06ecd390219972734cb70c6ceb5aa74cadb0a042 (patch)
tree27dd6546eb5cbcf2f947d64853ea6580be8a615c
parent0cf1e33721cdd1af0b33e6ed8a120da2ec1dbea3 (diff)
Copie de es-2006 en es-2007.
-rw-r--r--n/es-2006/src/Makefile2
-rw-r--r--n/es-2007/README24
-rw-r--r--n/es-2007/pcb/es-2006.bom27
-rw-r--r--n/es-2007/pcb/es-2006.brdbin0 -> 52148 bytes
-rw-r--r--n/es-2007/pcb/es-2006.schbin0 -> 303853 bytes
-rw-r--r--n/es-2007/src/Makefile14
-rw-r--r--n/es-2007/src/ack.c53
-rw-r--r--n/es-2007/src/ack.h56
-rw-r--r--n/es-2007/src/avrconfig.h92
-rw-r--r--n/es-2007/src/barillet.c622
-rw-r--r--n/es-2007/src/barillet.h73
-rw-r--r--n/es-2007/src/lcd.c65
-rw-r--r--n/es-2007/src/lcd.h45
-rw-r--r--n/es-2007/src/main.c475
-rw-r--r--n/es-2007/src/others.h90
-rw-r--r--n/es-2007/src/sensor_rvb.c413
-rw-r--r--n/es-2007/src/sensor_rvb.h96
-rw-r--r--n/es-2007/src/servo_motor.c185
-rw-r--r--n/es-2007/src/servo_motor.h61
-rw-r--r--n/es-2007/src/sharp.c106
-rw-r--r--n/es-2007/src/sharp.h70
-rw-r--r--n/es-2007/src/sniff_rvb.c190
-rw-r--r--n/es-2007/src/sniff_rvb.h71
-rw-r--r--n/es-2007/src/timer_1.c50
-rw-r--r--n/es-2007/src/timer_1.h41
-rw-r--r--n/es-2007/src/timer_main.h51
26 files changed, 2971 insertions, 1 deletions
diff --git a/n/es-2006/src/Makefile b/n/es-2006/src/Makefile
index a431de8..4239ea6 100644
--- a/n/es-2006/src/Makefile
+++ b/n/es-2006/src/Makefile
@@ -1,5 +1,5 @@
BASE = ../../avr
-PROGS = es
+AVR_PROGS = es
es_SOURCES = main.c sensor_rvb.c sniff_rvb.c timer_1.c barillet.c \
servo_motor.c sharp.c lcd.c ack.c
MODULES = proto uart utils adc twi
diff --git a/n/es-2007/README b/n/es-2007/README
new file mode 100644
index 0000000..1687713
--- /dev/null
+++ b/n/es-2007/README
@@ -0,0 +1,24 @@
+es - Input/Output general purpose board.
+
+General purpose board using an AVR.
+
+
+Copyright (C) 2006 Thomas Lambert & Dufour Jérémy
+
+Robot APB Team/Efrei 2006.
+ 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.
diff --git a/n/es-2007/pcb/es-2006.bom b/n/es-2007/pcb/es-2006.bom
new file mode 100644
index 0000000..533c492
--- /dev/null
+++ b/n/es-2007/pcb/es-2006.bom
@@ -0,0 +1,27 @@
+Qté Valeur Kermit Farnell Prix Description
+11 973-1156 0.50 Embase droite KK 3
+11 143-127 0.23 Connecteur KK 3
+2 973-1679 0.65 Embase droite KK 5
+2 146-256 0.26 Connecteur KK 5
+1 973-1148 0.41 Embase droite KK 2
+1 143-126 0.18 Connecteur KK 2
+1 110-6735 1.43 Embase coudée HE10-14
+1 109-7035 0.98 Fiche femelle HE10-14
+2 109-6980 0.88 Embase coudée HE10-10
+2 109-7034 0.88 Fiche femelle HE10-10
+1 109-6979 0.78 Embase coudée HE10-6
+1 110-6769 0.72 Fiche femelle HE10-6
+1 917-1355 10.38 ATMEGA64-16AU
+1 972-5962 3.12 MAX232 SOIC
+1 975-6078 0.60 Regu 5V 7805
+1 con Connecteur à la con (rad)
+1 14.7456 950-9852 2.18 Quartz
+1 Led
+1 1.8k 924-0551 0.032 Résistance 1206
+4 470 924-0489 0.032 Résistance 1206
+1 0 924-0276 0.032 Résistance 1206
+2 22p 499-249 0.099 Capacité 1206
+4 100n 644-316 0.181 Capacité 1206
+1 100u 921-130 920-435 0.082 Capacité 2.5-5
+2 47u 286-369 286-369 0.121 Capacité 2-5
+5 1u 967-208 197-476 0.122 Capacité 1206
diff --git a/n/es-2007/pcb/es-2006.brd b/n/es-2007/pcb/es-2006.brd
new file mode 100644
index 0000000..412449c
--- /dev/null
+++ b/n/es-2007/pcb/es-2006.brd
Binary files differ
diff --git a/n/es-2007/pcb/es-2006.sch b/n/es-2007/pcb/es-2006.sch
new file mode 100644
index 0000000..eaf29c2
--- /dev/null
+++ b/n/es-2007/pcb/es-2006.sch
Binary files differ
diff --git a/n/es-2007/src/Makefile b/n/es-2007/src/Makefile
new file mode 100644
index 0000000..4239ea6
--- /dev/null
+++ b/n/es-2007/src/Makefile
@@ -0,0 +1,14 @@
+BASE = ../../avr
+AVR_PROGS = es
+es_SOURCES = main.c sensor_rvb.c sniff_rvb.c timer_1.c barillet.c \
+ servo_motor.c sharp.c lcd.c ack.c
+MODULES = proto uart utils adc twi
+CONFIGFILE = avrconfig.h
+# atmega8, atmega8535, atmega128...
+AVR_MCU = atmega64
+# -O2 : speed
+# -Os : size
+OPTIMIZE = -O2
+HOST_LIBS = -lm
+
+include $(BASE)/make/Makefile.gen
diff --git a/n/es-2007/src/ack.c b/n/es-2007/src/ack.c
new file mode 100644
index 0000000..7d75d6c
--- /dev/null
+++ b/n/es-2007/src/ack.c
@@ -0,0 +1,53 @@
+/* ack.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * 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 "ack.h"
+
+/* Do not use, it's only for the main */
+int8_t ack_value;
+
+/** Reset ack status */
+void ack_reset (void)
+{
+ ack_value = ACK_NOTHING;
+}
+
+/** Init to nothing. */
+void ack_init (void)
+{
+ ack_reset ();
+}
+
+/* Set an ack */
+void ack_set (uint8_t ack_code)
+{
+ ack_value = ack_code;
+}
+
+/* Get current ack */
+uint8_t ack_get (void)
+{
+ return ack_value;
+}
+
diff --git a/n/es-2007/src/ack.h b/n/es-2007/src/ack.h
new file mode 100644
index 0000000..53a2927
--- /dev/null
+++ b/n/es-2007/src/ack.h
@@ -0,0 +1,56 @@
+#ifndef ack_h
+#define ack_h
+// ack.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// 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 "common.h"
+
+/** Module for telling upper class something important has occured ! */
+
+/** List here what you want to tell to the world and put a description.
+ * You must use a different number for each code and it must be lower than 255
+ * of course ! */
+#define ACK_NOTHING 0 /* Nothing to ack */
+#define ACK_CONTACT_FRONT 1 /* Something in the front */
+#define ACK_BARILLET_BALL_FRONT 2 /* A ball has been get from the front
+ */
+#define ACK_BARILLET_BALL_REAR 3 /* Ball in the rear */
+
+#define ACK_BARILLET_BALL_ARRIVED 4 /* Ball is comming */
+
+// FIXME, inline ? static ?
+
+/** Reset ack status */
+void ack_reset (void);
+
+/** Init to nothing. */
+void ack_init (void);
+
+/* Set an ack */
+void ack_set (uint8_t ack_code);
+
+/* Get current ack */
+uint8_t ack_get (void);
+
+#endif // ack_h
diff --git a/n/es-2007/src/avrconfig.h b/n/es-2007/src/avrconfig.h
new file mode 100644
index 0000000..eced8a7
--- /dev/null
+++ b/n/es-2007/src/avrconfig.h
@@ -0,0 +1,92 @@
+#ifndef avrconfig_h
+#define avrconfig_h
+/* avrconfig.h */
+/* asserv - Position & speed motor control on AVR. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * 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.
+ *
+ * }}} */
+
+/* I'am a twi master ! */
+#define TWI_SL_RCPT_SIZE 1
+#define TWI_SL_SEND_SIZE 1
+
+#define TWI_MASTER_ENABLE 1
+
+/* global */
+/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
+ * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
+#define AC_FREQ 14745600
+
+/* uart - UART module. */
+/** Select hardware uart for primary uart: 0, 1 or -1 to disable. */
+#define AC_UART0_PORT 1
+/** Baudrate: 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800,
+ * 115200, 230400, 250000, 500000, 1000000. */
+#define AC_UART0_BAUDRATE 115200
+/** Send mode:
+ * - POLLING: no interrupts.
+ * - RING: interrupts, ring buffer. */
+#define AC_UART0_SEND_MODE RING
+/** Recv mode, same as send mode. */
+#define AC_UART0_RECV_MODE RING
+/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
+#define AC_UART0_CHAR_SIZE 8
+/** Parity : ODD, EVEN, NONE. */
+#define AC_UART0_PARITY EVEN
+/** Stop bits : 1, 2. */
+#define AC_UART0_STOP_BITS 1
+/** Send buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_SEND_BUFFER_SIZE 32
+/** Recv buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_RECV_BUFFER_SIZE 32
+/** If the send buffer is full when putc:
+ * - DROP: drop the new byte.
+ * - WAIT: wait until there is room in the send buffer. */
+#define AC_UART0_SEND_BUFFER_FULL WAIT
+/** In HOST compilation:
+ * - STDIO: use stdin/out.
+ * - PTS: use pseudo terminal. */
+#define AC_UART0_HOST_DRIVER PTS
+/** Same thing for secondary port. */
+#define AC_UART1_PORT -1
+#define AC_UART1_BAUDRATE 115200
+#define AC_UART1_SEND_MODE RING
+#define AC_UART1_RECV_MODE RING
+#define AC_UART1_CHAR_SIZE 8
+#define AC_UART1_PARITY EVEN
+#define AC_UART1_STOP_BITS 1
+#define AC_UART1_SEND_BUFFER_SIZE 32
+#define AC_UART1_RECV_BUFFER_SIZE 32
+#define AC_UART1_SEND_BUFFER_FULL WAIT
+#define AC_UART1_HOST_DRIVER PTS
+
+/* proto - Protocol module. */
+/** Maximum argument size. */
+#define AC_PROTO_ARGS_MAX_SIZE 32
+/** Callback function name. */
+#define AC_PROTO_CALLBACK proto_callback
+/** Putchar function name. */
+#define AC_PROTO_PUTC uart0_putc
+/** Support for quote parameter. */
+#define AC_PROTO_QUOTE 1
+
+#endif /* avrconfig_h */
diff --git a/n/es-2007/src/barillet.c b/n/es-2007/src/barillet.c
new file mode 100644
index 0000000..86e8da3
--- /dev/null
+++ b/n/es-2007/src/barillet.c
@@ -0,0 +1,622 @@
+/* barillet.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Lambert Thomas
+ *
+ * Robot APB Team/Efrei 2006.
+ * 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 "barillet.h"
+#include "modules/utils/utils.h"
+#include "common.h"
+#include "io.h"
+#include "modules/proto/proto.h"
+#include "ack.h"
+
+/* utilisation de OCR1A pour le moteur barillet
+ OCR1B pour la turbine 1 => avant
+ OCR1C pour la turbine 2 => arriere
+
+ SIG_INTERRUPT7 pour la fourche montee de balle arriere
+ SIG_INTERRUPT6 pour la fourche montee de balle avant
+ SIG_INTERRUPT5 pour la fourche barillet 2 => celle pres de la carte de puissance
+ SIG_INTERRUPT4 pour la fourche barillet 1 => celle pres de la carte de es-2006
+ */
+#define OCR_BAR OCR1A
+#define OCR_TURB_AVANT OCR1B
+#define OCR_TURB_ARRIERE OCR1C
+
+/* XXX verifier que les turbines sont en vitesse lente si inutilisé */
+/* XXX verifier que le sens de rotation du barillet est 0 si inutilisé */
+
+/* XXX XXX passer en 16 bits */
+/* vitesse de rotation maximale du barillet */
+#define VITESSE_BAR_MAX_ 0x03FF
+
+/* vitesse de rotation minimale du barillet */
+#define VITESSE_BAR_MIN_ 0x01FF /* XXX a etalonner */
+
+/* vitesse de rotation maximale des turbines */
+#define VITESSE_TURB_MAX_ 0x0333
+
+/* vitesse de rotation minimale des turbines */
+#define VITESSE_TURB_MIN_ 0x0100
+
+/* delai d'une µs pour la carte puissance */
+#define DELAY_ 1
+
+/* delai de 500 µs pour la vidange */
+#define DELAY_VIDANGE_ 500
+
+/* Define de l'etat_en_cours_.
+ * Lexique :
+ * AV : trou avant.
+ * AR : trou arrière.
+ * EX : extraction/montée.
+ * DEP : depot/descente.
+ * sans rien (ex AR_EX) : on a reçu un ordre, mais on n'a pas encore vu de
+ * balle.
+ * VU : balle devant le capteur.
+ * PASSE : balle n'est plus devant le capteur, on attend qu'elle arrive à
+ * destination (tombe ou monte).
+ * FIN : opération réalisée avec succès, on l'indique à l'uart.
+ */
+
+#define ETAT_ROTATION 0x80
+/** Retourne une valeur non nulle si c'est une rotation. */
+#define EST_CE_UNE_ROTATION(e) ((e) & ETAT_ROTATION)
+/** Passe à l'état suivant si on est dans un etat rotation. */
+#define ETAT_SUIVANT_ROTATION(e) (((e) & ~ETAT_ROTATION) + 1)
+
+/** Etat initial au reset. */
+#define RESET (0x00)
+/** Initialisation de la position zero du barillet. */
+#define INIT (0x01)
+/** Attente sans rien faire. */
+#define SLEEP (0x02)
+/** Prêt à agir. */
+#define STAND_BY (0x03)
+/** Prêt à agir sauf pour faire monter des balles. les turbines sont au minimum */
+#define STAND_BY_FULL (0x04)
+/** il faudra remettre les turbines au minimum */
+#define STAND_BY_ARRET (0x05)
+
+
+#define ROTATION (0x10 | ETAT_ROTATION)
+#define ROTATION_FIN (0x11)
+#define AV_EX_VU (0x20)
+#define AV_EX_PASSE (0x21)
+#define AV_EX_SOLO (0x22)
+#define AV_EX_ROTATION (0x23 | ETAT_ROTATION)
+#define AV_EX_FIN (0x24)
+#define AR_EX (0x30)
+#define AR_EX_VU (0x31)
+#define AR_EX_PASSE (0x32)
+#define AR_EX_ROTATION (0x33 | ETAT_ROTATION)
+#define AR_EX_FIN (0x34)
+#define AR_DEP (0x40)
+#define AR_DEP_VU (0x41)
+#define AR_DEP_PASSE (0x42)
+#define AR_DEP_FIN (0x43)
+#define VIDANGE_1 (0x50 | ETAT_ROTATION)
+#define VIDANGE_2 (0x51)
+#define VIDANGE_3 (0x52 | ETAT_ROTATION)
+#define VIDANGE_4 (0x53)
+#define VIDANGE_5 (0x54)
+
+/* at barillet. */
+volatile uint8_t etat_en_cours_;
+
+/* Etat des fourches barillet. */
+volatile uint8_t fourche_barillet_prec_;
+
+/* position relative au barillet */
+volatile uint8_t pos_actuel_;
+volatile uint8_t pos_final_;
+volatile uint8_t pos_lenteur_;
+
+/* variable de vidange */
+uint8_t vidange_;
+
+/* compteur de vidange */
+uint8_t compt_vidange;
+
+/* Compteur utilisé pour les time out ou les passages de balle. */
+volatile uint16_t attente_;
+
+/* fonctions static dans le fichier */
+static void rotation_barillet (uint8_t pos_final, uint8_t etat);
+static void pos_bar(void);
+
+
+/* Initialisation pour tout ce qui concerne le barillet */
+inline void
+barillet_init (void)
+{
+ /* initialisation des registres du timer 1 pour la PWM total*/
+
+ ///*******************************
+ // * a inserer dans es_config *
+ // * *****************************/
+ //
+ // TCCR1A =
+ // regv (COM1A1, COM1A0, COM1B1, COM1B0, COM1C1, COM1C0, WGM11, WGM10,
+ // 1, 0, 1, 0, 1, 0, 1, 1);
+ //
+ // TCCR1B =
+ // regv ( ICNC1, ICES1, 5, WGM13, WGM12, CS12, CS11, CS10,
+ // 0, 0, 0, 0, 1, 0, 0, 1);
+ //
+ ///********************************/
+
+ /* initialisation des sorties sur le port B pour moteur et turbines */
+ DDRB |= _BV(7) | _BV(6) | _BV (5) | _BV (4);
+
+ /* initialisation des entrees du port E pour les interruptions */
+ DDRE &= ~(_BV(7) | _BV(6) | _BV (5) | _BV (4));
+ PORTE |= _BV(7) | _BV(6);
+
+ /* mode PWM = 0 */
+ OCR_BAR = 0; /* vitesse moteur barillet nulle */
+ utils_delay_us ( DELAY_ ); /* attente_ d'1 µs pour la puiss_barillet */
+
+ OCR_TURB_AVANT = 0; /* vitesse turb nulle */
+ OCR_TURB_ARRIERE = 0; /* vitesse turb nulle */
+
+ /* initialisation sens rotation */
+ PORTB &= ~_BV(4);
+
+ /* interruption autorisees INT7 INT6 INT5 INT4 à chaque changement logique */
+ EICRB = regv ( ISC71, ISC70, ISC61, ISC60, ISC51, ISC50, ISC41, ISC40,
+ 0, 1, 0, 1, 0, 1, 0, 1);
+
+ EIFR |= _BV(7) | _BV(6) | _BV(5) | _BV(4);
+ EIMSK |= _BV(7) | _BV(6) | _BV(5) | _BV(4);
+
+ /* initialisation de la position du barillet */
+ pos_actuel_ = 0;
+ pos_final_ = 0;
+ pos_lenteur_ = 0;
+ etat_en_cours_ = RESET;
+ attente_ = 0;
+ fourche_barillet_prec_ = (PINE >> 4) & 3;
+ vidange_ = 0;
+ compt_vidange = 0;
+}
+
+
+/********************************
+ * fonction appelee dans le main *
+ * ******************************/
+
+/** Initialise la position zero du barillet. */
+void
+barillet_init_zero (void)
+{
+ if (etat_en_cours_ == RESET)
+ {
+ OCR_BAR = VITESSE_BAR_MIN_;
+ etat_en_cours_ = INIT;
+ }
+}
+
+/* Lancement des turbines en vitesse lente */
+void
+barillet_debut_lancement (void)
+{
+ if (etat_en_cours_ == SLEEP || etat_en_cours_ == STAND_BY || etat_en_cours_ == STAND_BY_ARRET)
+ {
+ /* Commencer a faire tourner les turbines. */
+ OCR_TURB_AVANT = VITESSE_TURB_MIN_;
+ OCR_TURB_ARRIERE = VITESSE_TURB_MIN_;
+ etat_en_cours_ = STAND_BY_FULL;
+ }
+}
+
+
+/* Lance la procédure de collecte de toutes les balles de la table. */
+void
+barillet_lancement (void)
+{
+ if (etat_en_cours_ == STAND_BY_FULL)
+ {
+ /* Commencer a faire tourner les turbines. */
+ OCR_TURB_AVANT = VITESSE_TURB_MAX_;
+ OCR_TURB_ARRIERE = VITESSE_TURB_MIN_;
+ etat_en_cours_ = STAND_BY;
+ }
+}
+
+/* Dodo. - fin du match - */
+void
+barillet_sleep (void)
+{
+ if (etat_en_cours_ == STAND_BY || etat_en_cours_ == STAND_BY_FULL)
+ {
+ OCR_TURB_AVANT = 0;
+ OCR_TURB_ARRIERE = 0;
+ }
+}
+
+/* Demande de rotation. */
+void
+rotation (uint8_t pos_final)
+{
+ if (etat_en_cours_ == STAND_BY || etat_en_cours_ == STAND_BY_FULL)
+ rotation_barillet (pos_final, ROTATION);
+}
+
+/* Demande d'extraction. */
+void
+extraction (void)
+{
+ if (etat_en_cours_ == STAND_BY || etat_en_cours_ == STAND_BY_FULL)
+ {
+ etat_en_cours_ = AR_EX;
+ OCR_TURB_AVANT = VITESSE_TURB_MIN_;
+ OCR_TURB_ARRIERE = VITESSE_TURB_MAX_;
+ }
+}
+
+/* Demande de depot. */
+void
+depot_balle (void)
+{
+ if (etat_en_cours_ == STAND_BY || etat_en_cours_ == STAND_BY_FULL)
+ {
+ etat_en_cours_ = AR_DEP;
+ OCR_TURB_AVANT = VITESSE_TURB_MIN_;
+ OCR_TURB_ARRIERE = 0;
+ attente_ = 200;
+ }
+}
+
+/* vidange total du barillet */
+/*************
+ * ATTENTION * cette fonction peut etre appele a tout moment
+ * ***********/
+void
+vidange_barillet(void)
+{
+ OCR_TURB_ARRIERE = VITESSE_TURB_MIN_;
+ OCR_TURB_AVANT = VITESSE_TURB_MIN_;
+ compt_vidange = 0;
+ etat_en_cours_ = VIDANGE_1;
+ rotation_barillet( 0x26, VIDANGE_1 );
+}
+
+
+void sequenceur_barillet()
+{
+ /* DEBUG *
+ static uint8_t old_pos_actuel = 0;
+ if (old_pos_actuel != pos_actuel_)
+ {
+ proto_send2b('W', pos_actuel_, fourche_barillet_prec_);
+ old_pos_actuel = pos_actuel_;
+ }
+ */
+ if (attente_)
+ {
+ attente_--;
+ return;
+ }
+ switch(etat_en_cours_)
+ {
+ case RESET:
+ break;
+ case SLEEP:
+ break;
+ case STAND_BY:
+ break;
+ case STAND_BY_FULL:
+ break;
+ case STAND_BY_ARRET:
+ break;
+ case ROTATION_FIN:
+ // XXX ack
+ etat_en_cours_ = STAND_BY_FULL;
+ break;
+ case AV_EX_VU:
+ /* Time out en cas de deux balles dans le trou avant. */
+ case AV_EX_PASSE:
+ OCR_TURB_AVANT = VITESSE_TURB_MIN_ - 17;
+ if (PINE & _BV(6))
+ etat_en_cours_ = AV_EX_SOLO;
+ break;
+ case AV_EX_SOLO:
+ ack_set (ACK_BARILLET_BALL_ARRIVED);
+ rotation_barillet ((pos_actuel_ + 8) % 40, AV_EX_ROTATION);
+ break;
+ case AV_EX_FIN:
+ ack_set (ACK_BARILLET_BALL_FRONT);
+ etat_en_cours_ = STAND_BY_FULL;
+ break;
+ case AR_EX:
+ break;
+ case AR_EX_VU:
+ break;
+ case AR_EX_PASSE:
+ ack_set (ACK_BARILLET_BALL_ARRIVED);
+ rotation_barillet ((pos_actuel_ + 8) % 40, AR_EX_ROTATION);
+ break;
+ case AR_EX_FIN:
+ ack_set (ACK_BARILLET_BALL_REAR);
+ etat_en_cours_ = STAND_BY_FULL;
+ break;
+ case AR_DEP:
+ // info PC104 que le timer est arrivé à expiration.
+ etat_en_cours_ = STAND_BY_FULL;
+ break;
+ case AR_DEP_VU:
+ etat_en_cours_ = STAND_BY_FULL;
+ break;
+ case AR_DEP_PASSE:
+ OCR_TURB_ARRIERE = VITESSE_TURB_MIN_;
+ etat_en_cours_ = AR_DEP_FIN;
+ break;
+ case AR_DEP_FIN:
+ etat_en_cours_ = STAND_BY_ARRET;
+ break;
+
+ /* revoir les fonctions a apeller */
+ case VIDANGE_1:
+ break;
+ case VIDANGE_2:
+ /* ouverture du servo moteur */
+ servo_motor_open_trash();
+ etat_en_cours_ = VIDANGE_3;
+ rotation_barillet (0, VIDANGE_3);
+ break;
+ case VIDANGE_3:
+ /* rotation du barillet en cours */
+ break;
+ case VIDANGE_4:
+ attente_ = 300;
+ etat_en_cours_ = VIDANGE_5;
+ break;
+ case VIDANGE_5:
+ compt_vidange = compt_vidange + 1;
+ if ( compt_vidange == 5 )
+ /* vidange terminee */
+ {
+ servo_motor_close_trash();
+ etat_en_cours_ = STAND_BY_FULL;
+ }
+ if ( compt_vidange <= 4 )
+ {
+ etat_en_cours_ = VIDANGE_3;
+ rotation_barillet( ( (pos_actuel_ + 8)%40), VIDANGE_3);
+ }
+ break;
+ default : break;
+ }
+}
+
+/** Démare une rotation du barillet. */
+static void
+rotation_barillet (uint8_t pos_final, uint8_t etat)
+{
+ uint8_t dist_trigo, dist_pas_trigo;
+ uint8_t pos_actuel;
+ /* Ça a l'air con comme ça, mais en fait la première ligne recopie
+ * l'argument dans la variable globale et la seconde recopie la variable
+ * globale dans la variable locale. Intérêt ? La variable globale est
+ * volatile donc lente à accéder. La variable locale ne l'est pas, donc on
+ * garde sa valeur dans un registre. Cool non ? */
+ pos_final_ = pos_final;
+ pos_actuel = pos_actuel_;
+ if (pos_final != pos_actuel)
+ {
+ /* Affecter le bon sens de rotation */
+ dist_trigo = (40 + pos_final - pos_actuel) % 40;
+ dist_pas_trigo = (40 + pos_actuel - pos_final) % 40;
+ if (dist_trigo < dist_pas_trigo)
+ {
+ /* Tourne dans le sens trigo. */
+ PORTB &= ~_BV(4);
+ pos_lenteur_ = (pos_final + (40 - 2)) % 40;
+ }
+ else
+ {
+ PORTB |= _BV(4);
+ pos_lenteur_ = (pos_final + 2) % 40;
+ }
+ /* Delay pour la commutation du pont en H. */
+ utils_delay_us (DELAY_);
+ if (etat != AV_EX_ROTATION )
+ {
+ OCR_TURB_AVANT = VITESSE_TURB_MIN_;
+ }
+ OCR_TURB_ARRIERE = VITESSE_TURB_MIN_;
+ /* Affectation de la vitesse du barillet. */
+ if ((dist_pas_trigo <= 2) || (dist_trigo <= 2))
+ {
+ OCR_BAR = VITESSE_BAR_MIN_;
+ }
+ else
+ {
+ OCR_BAR = VITESSE_BAR_MAX_;
+ }
+ etat_en_cours_ = etat;
+ }
+ else
+ etat_en_cours_ = ETAT_SUIVANT_ROTATION (etat);
+}
+
+/* gestion de la position du barillet */
+static void
+pos_bar (void)
+{
+ uint8_t concat, fourche;
+ /* Ici, on place dans concat une valeur 0000nnoo, avec nn la nouvelle
+ * valeur, et oo l'ancienne valeur des fourches, et on mémorise la
+ * nouvelle valeur pour le prochain passage dans le coin. */
+ fourche = (PINE >> 4) & 3;
+ concat = (fourche << 2) | fourche_barillet_prec_;
+ fourche_barillet_prec_ = fourche;
+ switch ( concat )
+ { // actu prec
+ case 1 : // 00 01
+ case 7 : // 01 11
+ case 8 : // 10 00
+ case 14 : // 11 10
+ if ( pos_actuel_ == 0 )
+ {
+ pos_actuel_ = 40;
+ }
+ --pos_actuel_;
+ break;
+ case 2 : // 00 10
+ case 4 : // 01 00
+ case 11 : // 10 11
+ case 13 : // 11 01
+ ++pos_actuel_;
+ if ( pos_actuel_ == 40 )
+ {
+ pos_actuel_ = 0;
+ }
+ break;
+ default :
+ break;
+ }
+ /* Transitions. */
+ if (EST_CE_UNE_ROTATION (etat_en_cours_))
+ {
+ if (pos_actuel_ == pos_lenteur_)
+ {
+ OCR_BAR = VITESSE_BAR_MIN_;
+ }
+ else if (pos_actuel_ == pos_final_)
+ {
+ OCR_BAR = 0;
+ etat_en_cours_ = ETAT_SUIVANT_ROTATION (etat_en_cours_);
+ }
+ }
+ /* Pour l'initialisation, il faut être sur une position ou les deux
+ * fourches sont non coupées, et la troisième fourche aussi. */
+ else if (etat_en_cours_ == INIT && (fourche == 3) && (PINF & 0x01))
+ {
+ OCR_BAR = 0;
+ pos_actuel_ = 0;
+ etat_en_cours_ = SLEEP;
+ }
+}
+
+/**************************************
+ * CHANGEMENT DE VITESSE DES TURBINES *
+ **************************************/
+void vitesse_turbine(uint8_t turbine, uint16_t vitesse)
+{
+ if ( turbine == 1 )
+ {
+ if (vitesse > VITESSE_TURB_MAX_)
+ OCR_TURB_AVANT = VITESSE_TURB_MAX_;
+ else
+ OCR_TURB_AVANT = vitesse;
+ }
+ else if ( turbine == 2 )
+ {
+ if (vitesse > VITESSE_TURB_MAX_)
+ OCR_TURB_ARRIERE = VITESSE_TURB_MAX_;
+ else
+ OCR_TURB_ARRIERE = vitesse;
+ }
+ else if ( turbine == 3 ) // moteur barillet
+ {
+ if (vitesse > VITESSE_BAR_MAX_)
+ OCR_BAR = VITESSE_BAR_MAX_;
+ else
+ OCR_BAR = vitesse;
+ }
+}
+
+/**** changement de sens ****/
+void sens(uint8_t sens_rotat)
+{
+ if ( sens_rotat == 0 )
+ {
+ PORTB |= _BV(4);
+ }
+ else if ( sens_rotat == 1 )
+ {
+ PORTB &= ~_BV(4);
+ }
+}
+
+
+/* ***************
+ * INTERRUPTIONS *
+ * ***************/
+
+/* interruption fourche optique turbine avant */
+SIGNAL (SIG_INTERRUPT6)
+{
+ if (etat_en_cours_ == STAND_BY)
+ {
+ etat_en_cours_ = AV_EX_VU;
+ attente_ = 500;
+ }
+ else if (etat_en_cours_ == AV_EX_VU)
+ {
+ etat_en_cours_ = AV_EX_PASSE;
+ attente_ = 200;
+ }
+}
+
+/* interruption fourche optique turbine arriere */
+SIGNAL (SIG_INTERRUPT7)
+{
+ if (etat_en_cours_ == AR_EX)
+ {
+ etat_en_cours_ = AR_EX_VU;
+ }
+ else if (etat_en_cours_ == AR_EX_VU)
+ {
+ etat_en_cours_ = AR_EX_PASSE;
+ attente_ = 200;
+ }
+ if (etat_en_cours_ == AR_DEP)
+ {
+ // dans le cas d'une descente, il se peut qu'il n'y ai
+ // pas de balle
+ etat_en_cours_ = AR_DEP_VU;
+ attente_ = 400;
+ }
+ else if (etat_en_cours_ == AR_DEP_VU)
+ {
+ etat_en_cours_ = AR_DEP_PASSE;
+ attente_ = 400;
+ }
+}
+
+/* interruption fourche optique barillet 1 */
+SIGNAL ( SIG_INTERRUPT5 )
+{
+ pos_bar();
+}
+
+/* interruption fourche optique barillet 1 */
+SIGNAL ( SIG_INTERRUPT4 )
+{
+ pos_bar();
+}
+
+/* XXX dans la PC104, apres un depot, il faudra remmetre le barillet dans une des positions 00, 08, 10, 18, 20 ( position exa ) */
diff --git a/n/es-2007/src/barillet.h b/n/es-2007/src/barillet.h
new file mode 100644
index 0000000..bad365f
--- /dev/null
+++ b/n/es-2007/src/barillet.h
@@ -0,0 +1,73 @@
+#ifndef barillet_h
+#define barillet_h
+
+// barillet/ .h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Lembert Thomas
+//
+// Robot APB Team/Efrei 2004.
+// 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 "common.h"
+#include "servo_motor.h"
+
+/* fonction d'initialisation */
+void barillet_init(void);
+
+/** Initialise la position zero du barillet. */
+void barillet_init_zero (void);
+
+/* fonction appelee pour lancer le barillet */
+void barillet_debut_lancement (void);
+/* fonction appelee juste apres */
+void barillet_lancement (void);
+
+/* changement de vitesse turbine */
+void vitesse_turbine(uint8_t num_turb, uint16_t vitesse);
+
+/* changement de sens */
+void sens( uint8_t sens_rotat );
+
+/* fonction main de la gestion du barillet */
+void sequenceur_barillet(void);
+
+/* fonction pour setter une rotation */
+void rotation(uint8_t pos_fin);
+
+/* fonction pour setter une extraction */
+void extraction(void);
+
+/* fonction pour setter un depot de balle */
+void depot_balle(void);
+
+/* Dodo. */
+void barillet_sleep (void);
+
+/*******************************************
+ * A UTILISER EN CAS D'ULTIME NECESSITE *
+ * FONCTION NON SECURISE POUR ETRE UTILISE *
+ * A LA FIN D4UN MATCH POUR LE VIDANGER *
+ * *****************************************/
+/* fonction pour vider le barillet */
+void vidange_barillet(void);
+
+#endif
+
diff --git a/n/es-2007/src/lcd.c b/n/es-2007/src/lcd.c
new file mode 100644
index 0000000..ac8d96b
--- /dev/null
+++ b/n/es-2007/src/lcd.c
@@ -0,0 +1,65 @@
+/* lcd.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * 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 "lcd.h"
+
+#include "modules/twi/twi.h"
+#include "modules/proto/proto.h"
+#include "modules/utils/utils.h"
+
+uint8_t grub_greeting[32] = "Booting ! Press 1 > NFS 2 > Auto";
+
+// TODO, inline ?
+// Prefers 16 char management, and ask the LCD to rotate line...
+
+/* Init communication with the LCD. */
+void lcd_init (void)
+{
+ /* Init twi */
+ twi_init (TWI_LCD_ADDR);
+}
+
+/* Print something on the LCD */
+inline uint8_t lcd_print (uint8_t *string, uint8_t size)
+{
+ /* Send to the LCD */
+ return twi_ms_send (TWI_LCD_ADDR, string, size);
+}
+
+/* What key is pressed into the LCD keyboard ? */
+uint8_t lcd_key (void)
+{
+ static uint8_t buffer_read;
+ twi_ms_read (TWI_LCD_ADDR, &buffer_read, 1);
+ return buffer_read;
+}
+
+/* Tell the LCD we have seen the Grub ! */
+void lcd_grub_booting (void)
+{
+ lcd_print (&grub_greeting[16], 16);
+ utils_delay_ms (4);
+ lcd_print (grub_greeting, 16);
+ utils_delay_ms (4);
+}
diff --git a/n/es-2007/src/lcd.h b/n/es-2007/src/lcd.h
new file mode 100644
index 0000000..4b20ad0
--- /dev/null
+++ b/n/es-2007/src/lcd.h
@@ -0,0 +1,45 @@
+#ifndef lcd_h
+#define lcd_h
+// lcd.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// 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.
+//
+// }}}
+/** Communication with the LCD card. */
+
+#include "common.h"
+
+#define TWI_LCD_ADDR 0x02
+
+/* Init communication with the LCD. */
+void lcd_init (void);
+
+/* Print something on the LCD */
+uint8_t lcd_print (uint8_t *string, uint8_t size);
+
+/* What key is pressed into the LCD keyboard ? */
+uint8_t lcd_key (void);
+
+/* Tell the LCD we have seen the Grub ! */
+void lcd_grub_booting (void);
+
+#endif // lcd_h
diff --git a/n/es-2007/src/main.c b/n/es-2007/src/main.c
new file mode 100644
index 0000000..e377c55
--- /dev/null
+++ b/n/es-2007/src/main.c
@@ -0,0 +1,475 @@
+/* main.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * 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 "common.h"
+#include "io.h"
+#include "modules/uart/uart.h"
+#include "modules/proto/proto.h"
+#include "modules/uart/uart.h"
+#include "modules/utils/utils.h"
+#include "modules/utils/byte.h"
+
+#include "timer_main.h" /* main timer */
+#include "sensor_rvb.h" /* RVB sensors management */
+#include "sniff_rvb.h" /* RVB sensors analysis */
+#include "timer_1.h" /* timer/counter 1 */
+#include "others.h" /* define game color mode + jack + frontal sensor */
+#include "servo_motor.h"/* Servo motor module */
+#include "sharp.h" /* SHarps module */
+#include "lcd.h" /* Communication with the LCD card */
+#include "ack.h" /* Ack module */
+#include "barillet.h"
+
+/* Statistics for RVB sensors */
+uint8_t sensor_rvb_stat_enable[RVB_MAX_SENSOR], sensor_rvb_stats[RVB_MAX_SENSOR];
+/* Statistics for RVB analysis. */
+uint8_t sniff_rvb_stat_enable[RVB_MAX_SENSOR], sniff_rvb_stats[RVB_MAX_SENSOR];
+
+/* Statistics for RVB ball sensors. */
+uint8_t sniff_ball_stat_enable, sniff_ball_stats;
+
+/* Config and statistics for SHarps */
+uint8_t sharp_stat_enable[SHARP_NUMBER], sharp_stat_freq[SHARP_NUMBER];
+uint8_t sharp_enable[SHARP_NUMBER], sharp_enable_freq[SHARP_NUMBER];
+
+/* Stats for colour selection and jack */
+uint8_t others_jackcolor_stat_enable, others_jackcolor_stats;
+
+/* Stat for RVB front sensors */
+uint8_t sniff_rvb_front_enable, sniff_rvb_front_stats;
+/* Stat for RVB hole sensor */
+uint8_t sniff_rvb_hole_enable, sniff_rvb_hole_stats;
+
+/* XXX Debug stats */
+uint8_t main_stats[4];
+uint8_t main_stats_freq, main_stats_enable;
+
+/* Twi */
+uint8_t twi_buffer_read;
+
+/* Keyboard LCD update frequency */
+uint8_t lcd_key_enable, lcd_key_freq;
+
+/* Enable stat for ack */
+uint8_t main_ack_freq, main_ack_enable;
+
+/* Grub enable */
+uint16_t grub_enable;
+
+/** Call when we receive some data from proto (uart) */
+void
+proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
+{
+ /* This macro combine command and size in one integer. */
+#define c(cmd, size) (cmd << 8 | size)
+
+ uint8_t compt;
+ uint16_t temp_16b;
+
+ switch (c (cmd, size))
+ {
+ /* Reset */
+ case c ('z', 0):
+ utils_reset ();
+ break;
+
+ /* Main stats / Debug */
+ case c ('Z', 1):
+ main_stats_freq = main_stats_enable = args[0];
+ break;
+
+ case c ('f', 0):
+ /* Shut up ! */
+ ack_reset ();
+ /* Tell us quickly next time please */
+ main_ack_freq = 1;
+ break;
+
+ case c ('F', 1):
+ /* Change the frequency of ack */
+ main_ack_enable = args[0];
+ /* Tell us quickly next time please */
+ main_ack_freq = 1;
+ break;
+
+ /*** RVB ***/
+ /* RVB sensors configuration */
+ case c ('p', 2):
+ sensor_rvb_config (args[0], args[1]);
+ break;
+ /* RVB sniff configuration */
+ case c ('x', 5):
+ sniff_rvb_config (args[0], v8_to_v16 (args[1], args[2]),
+ v8_to_v16 (args[3], args[4]));
+ break;
+ /* RVB sensors stats */
+ case c ('S', 3):
+ temp_16b = v8_to_v16 (args[0], args[1]);
+ for (compt = 0; compt < RVB_MAX_SENSOR; compt++)
+ if (temp_16b & _BV(compt))
+ sensor_rvb_stat_enable[compt] = sensor_rvb_stats[compt] =
+ args[2];
+ break;
+ /* Set current color as reference */
+ case c ('r', 3):
+ temp_16b = v8_to_v16 (args[0], args[1]);
+ for (compt = 0; compt < RVB_MAX_SENSOR; compt++)
+ if (temp_16b & _BV(compt))
+ sniff_rvb_set_ref_color (compt, args[2]);
+ break;
+ /* Print stats of the colour seen by the sensor */
+ case c ('A', 3):
+ temp_16b = v8_to_v16 (args[0], args[1]);
+ for (compt = 0; compt < RVB_MAX_SENSOR; compt++)
+ if (temp_16b & _BV(compt))
+ sniff_rvb_stat_enable[compt] = sniff_rvb_stats[compt] =
+ args[2];
+ break;
+ /* Print stats for ball */
+ case c ('B', 1):
+ sniff_ball_stats = sniff_ball_stat_enable = args[0];
+ break;
+ /* Print stats for front RVB Sniff */
+ case c ('C', 1):
+ sniff_rvb_front_enable = sniff_rvb_front_stats = args[0];
+ break;
+ /* RVB Hole sensor */
+ case c ('D', 1):
+ sniff_rvb_hole_enable = sniff_rvb_hole_stats = args[0];
+ break;
+ /* Enable all sensors */
+ case c ('u', 1):
+ sensor_rvb_upper_sensors (args[0]);
+ break;
+
+ /* Selection color & jack */
+ case c ('O', 1):
+ others_jackcolor_stat_enable = others_jackcolor_stats = args[0];
+ break;
+
+ /* Communication with the servo motor */
+ case c ('m', 2):
+ servo_motor_set_pos (args[0], args[1]);
+ break;
+
+ /* SHarps */
+ /* Update frequency */
+ case c ('h', 2):
+ for (compt = 0; compt < SHARP_NUMBER; compt++)
+ if (args[0] & _BV(compt))
+ sharp_enable[compt] = sharp_enable_freq[compt] = args[1];
+ break;
+ /* Stats frequency */
+ case c ('H', 2):
+ for (compt = 0; compt < SHARP_NUMBER; compt++)
+ if (args[0] & _BV(compt))
+ sharp_stat_enable[compt] = sharp_stat_freq[compt] = args[1];
+ break;
+ case c ('o', 5):
+ sharp_config_threshold (args[0], v8_to_v16 (args[1], args[2]),
+ v8_to_v16 (args[3], args[4]));
+ break;
+
+ /* LCD */
+ case c ('l', 16):
+ lcd_print (args, 16);
+ break;
+ case c ('L', 1):
+ lcd_key_freq = lcd_key_enable = args[0];
+ break;
+
+ /* Grub ! */
+ case c ('G', 0):
+ grub_enable = 2000;
+ lcd_grub_booting ();
+ return;
+
+/* tests primaires pour le barillet */
+ case c ('v',3):
+ temp_16b = v8_to_v16 (args[1], args[2]);
+ vitesse_turbine( args[0], temp_16b);
+ break;
+
+ case c('w',1):
+ sens(args[0]);
+ break;
+
+/* tests plus complexes de la gestion du barillet */
+
+ /* Initialise la position du barillet. */
+ case c ('i', 0):
+ barillet_init_zero ();
+ break;
+ /* bon on commence - le jack est parti */
+ case c ('g', 0):
+ barillet_debut_lancement();
+ break;
+ /* on passe en vitesse turbine rapide */
+ case c ('h',0):
+ barillet_lancement();
+ break;
+ /* Coucouche panier. */
+ case c ('s', 0):
+ barillet_sleep ();
+ break;
+ /* deposer une balle du barillet */
+ case c ('d', 0):
+ depot_balle();
+ break;
+ /* extraire une balle */
+ case c ('e', 0):
+ extraction();
+ break;
+ /* rotation du barillet */
+ case c ('t', 1):
+ rotation(args[0]);
+ break;
+ /* vidange du barillet */
+ case c ('n', 0):
+ vidange_barillet();
+ break;
+
+ /* Unknown commands */
+ default:
+ proto_send0 ('?');
+ return;
+ }
+ /* When no error acknoledge. */
+ proto_send (cmd, size, args);
+#undef c
+}
+
+int
+main (void)
+{
+ uint8_t compt;
+
+ /* Serial port */
+ uart0_init ();
+ /* Main timer init */
+ timer_main_init ();
+ /* Init timer/counter 1 for RVB & PWM
+ * /!\ Must be called before RVB/PWM init /!\ */
+ timer1_init ();
+ /* Init RVB sensors system */
+ sensor_rvb_init ();
+ /* Init Color button init */
+ others_init();
+ /* barillet init */
+ barillet_init();
+ /* Servo motor init */
+ servo_motor_init ();
+ /* Sharp init */
+ sharp_init ();
+ /* LCD init */
+ lcd_init ();
+ /* Ack init */
+ ack_init ();
+
+ /* Enable interrupts */
+ sei ();
+
+ /* We are ready ! */
+ proto_send0 ('z');
+
+ while (1)
+ {
+ /* Wait 4.44 ms */
+ // FIXME Try to put this down and make some test before if it
+ // possible.
+ timer_main_wait ();
+
+ if (main_stats_enable && !--main_stats_freq)
+ {
+ main_stats_freq = main_stats_enable;
+ proto_send4b ('Z', main_stats[0], main_stats[1], main_stats[2],
+ main_stats[3]);
+ }
+
+ main_stats[0] = TCNT0;
+
+ /* Ack management */
+ compt = ack_get ();
+ if (compt)
+ if (main_ack_enable && !--main_ack_freq)
+ {
+ main_ack_freq = main_ack_enable;
+ proto_send1b ('F', compt);
+ }
+
+ /* Front contact */
+ others_contact_update ();
+
+ /* RVB Sensors stats */
+ for (compt = 0; compt < RVB_MAX_SENSOR; compt++)
+ {
+ if (sensor_rvb_stat_enable[compt] && !--sensor_rvb_stats[compt])
+ {
+ /* Re init stats system for this sensor */
+ sensor_rvb_stats[compt] = sensor_rvb_stat_enable[compt];
+ // FIXME useless 16 bit value.
+ proto_send5w ('S', compt, sensor_rvb_values[compt][0],
+ sensor_rvb_values[compt][1],
+ sensor_rvb_values[compt][2],
+ sensor_rvb_values[compt][3]);
+ }
+ /* RVB Sensors analysis stats */
+ if (sniff_rvb_stat_enable[compt] && !--sniff_rvb_stats[compt])
+ {
+ /* Re init stats system for this sensor */
+ sniff_rvb_stats[compt] = sniff_rvb_stat_enable[compt];
+ proto_send2b ('A', compt, sniff_rvb_analysis_color (compt, RVB_SNIFF_ALL_COLORS));
+ }
+ }
+
+ /* Print stats for ball */
+ if (sniff_ball_stat_enable && !--sniff_ball_stats)
+ {
+ /* Re init stats system for this sensor */
+ sniff_ball_stats = sniff_ball_stat_enable;
+ proto_send2b ('B', sniff_rvb_analysis_ball (7), sniff_rvb_analysis_ball (8));
+ }
+ /* Print stats for front sensors */
+ if (sniff_rvb_front_enable && !--sniff_rvb_front_stats)
+ {
+ if (sensor_rvb_state_sleeeping ())
+ {
+ /* Re init stats system for this sensor */
+ sniff_rvb_front_stats = sniff_rvb_front_enable;
+ proto_send2b
+ ('C', sniff_rvb_analysis_color (4, RVB_SNIFF_ALL_COLORS),
+ sniff_rvb_analysis_color (6, RVB_SNIFF_ALL_COLORS));
+ }
+ else
+ sniff_rvb_front_stats = 1;
+ }
+ /* RVB Hole */
+ if (sniff_rvb_hole_enable && !--sniff_rvb_hole_stats)
+ {
+ if (sensor_rvb_state_sleeeping ())
+ {
+ /* Re init stats system for this sensor */
+ sniff_rvb_hole_stats = sniff_rvb_hole_enable;
+ proto_send1b
+ ('D', sniff_rvb_analysis_color (5, RVB_SNIFF_ALL_COLORS));
+ }
+ else
+ sniff_rvb_hole_stats = 1;
+ }
+
+ main_stats[1] = TCNT0;
+
+ /* Update all the asserv pin comunication */
+ sensor_rvb_update_asserv_pins ();
+
+ if (others_jackcolor_stat_enable && !--others_jackcolor_stats)
+ {
+ others_jackcolor_stats = others_jackcolor_stat_enable;
+ proto_send1b ('O', other_jack_color ());
+ }
+ /* LCD */
+ if (lcd_key_enable && !--lcd_key_freq)
+ {
+ lcd_key_freq = lcd_key_enable;
+ if ((twi_buffer_read = lcd_key ()))
+ proto_send1b ('L', twi_buffer_read);
+ }
+
+ if (grub_enable)
+ {
+ uint8_t ret;
+ grub_enable--;
+ utils_delay_ms (4);
+ switch (ret = lcd_key ())
+ {
+ case 0x31:
+ /* NFS -> CR */
+ uart0_putc (10);
+ utils_delay_ms (4);
+ lcd_print (" ", 16);
+ utils_delay_ms (4);
+ lcd_print (">>> NFS <<<", 16);
+ grub_enable = 0;
+ break;
+ case 0x32:
+ /* Autonomous -> v CR */
+ uart0_putc ('v');
+ uart0_putc (10);
+ utils_delay_ms (4);
+ lcd_print (" ", 16);
+ utils_delay_ms (4);
+ lcd_print (">> Automous <<", 16);
+ grub_enable = 0;
+ break;
+ case 0x0:
+ if (!grub_enable)
+ {
+ lcd_print (" ", 16);
+ utils_delay_ms (4);
+ utils_delay_ms (4);
+ lcd_print ("> Default NFS <", 16);
+ }
+ }
+
+ }
+
+ /* gestion du barilet */
+ sequenceur_barillet ();
+
+ /* Sharps */
+ for (compt = 0; compt < SHARP_NUMBER; compt++)
+ {
+ /* Update */
+ if (sharp_enable[compt] && !--sharp_enable_freq[compt])
+ {
+ /* Re init update system for this sharp */
+ sharp_enable_freq[compt] = sharp_enable[compt];
+ sharp_update_values (compt);
+ }
+ /* Stats */
+ if (sharp_stat_enable[compt] && !--sharp_stat_freq[compt])
+ {
+ /* Re init stats system for this sharp */
+ sharp_stat_freq[compt] = sharp_stat_enable[compt];
+ /* XXX 16 bits sucks */
+ proto_send2w ('H', compt, sharp_values[compt]);
+ }
+ }
+
+ main_stats[2] = TCNT0;
+
+ /* Get data for serial port */
+ while (uart0_poll ())
+ proto_accept (uart0_getc ());
+
+ /* Update RVB sensors data.
+ * I want this to be done as later as possible, and espceically after
+ * commands has been parsed ! */
+ sensor_rvb_start_capture ();
+
+ main_stats[3] = TCNT0;
+ }
+}
+
diff --git a/n/es-2007/src/others.h b/n/es-2007/src/others.h
new file mode 100644
index 0000000..9b9611f
--- /dev/null
+++ b/n/es-2007/src/others.h
@@ -0,0 +1,90 @@
+#ifndef others_h
+#define others_h
+// others.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Patrick Goncalves - (Dufour Jérémy)
+//
+// Robot APB Team/Efrei 2004.
+// 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 "io.h"
+#include "common.h"
+
+#include "ack.h"
+
+/* pin responsible for the color mode */
+#define JACK_PIN 0
+#define SELECT_COLOR_PIN 1
+#define CONTACT_PIN 2
+
+/* (to be set 1 <-> 0) */
+#define BLUE_COLOR_GAME_MODE _BV(0) /* 0000 0000 = 0 */
+#define RED_COLOR_GAME_MODE _BV(SELECT_COLOR_PIN) /* 0000 0010 = 2 */
+
+/* READ PINA */
+/* access to value of pins of PORTA */
+#define GET_PIN_OF_PORTA(n) ( PINA & _BV(n) )
+
+/** return the value of pin select color */
+inline uint8_t others_selectcoul (void)
+{
+ return GET_PIN_OF_PORTA (SELECT_COLOR_PIN);
+}
+
+/** return the value of pin jack */
+inline uint8_t others_jack (void)
+{
+ return !GET_PIN_OF_PORTA (JACK_PIN);
+}
+
+/** return the value of pin contact */
+inline uint8_t others_contact (void)
+{
+ return !GET_PIN_OF_PORTA (CONTACT_PIN);
+}
+
+/** Update ack if some contact happened ! */
+inline void others_contact_update (void)
+{
+ if (others_contact ())
+ ack_set (ACK_CONTACT_FRONT);
+}
+
+/** Return the jack and the select_colour at the same time */
+inline uint8_t other_jack_color (void)
+{
+ return (PINA & 0x03);
+}
+
+/** Initialisation of color button (put select color pin in mode 'IN') */
+inline void others_init(void)
+{
+ /* init DDRA (0 default) */
+
+ /* DDR = 0 pin in mode IN */
+ /* XXXX XXXX & 1111 1101 = XXXX XX0X */
+ /* DDRA &= ~_BV(SELECT_COLOR_PIN); */
+
+ /* pull up in mode in */
+ PORTA |= _BV(SELECT_COLOR_PIN) | _BV(JACK_PIN) | _BV(CONTACT_PIN);
+}
+
+#endif // others_h
diff --git a/n/es-2007/src/sensor_rvb.c b/n/es-2007/src/sensor_rvb.c
new file mode 100644
index 0000000..46b2598
--- /dev/null
+++ b/n/es-2007/src/sensor_rvb.c
@@ -0,0 +1,413 @@
+/* sensor_rvb.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * 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 "sensor_rvb.h"
+
+#include "io.h"
+#include "modules/utils/utils.h" /* regv */
+#include "modules/proto/proto.h"
+
+#include "sniff_rvb.h"
+#include "timer_1.h"
+
+/**
+ * Somes defines.
+ **/
+/** Colors selection pins. */
+#define S1RVB 7
+#define S0RVB 6
+/** Max input capture before considering we can start the real capture.
+ * (default value) */
+#define RVB_MAX_FALSE_IC 3
+/** Max overflow of the timer 1 before thinking the sensor is HS. */
+/* TODO Find a way to compute this value */
+#define RVB_MAX_OVERFLOW 253
+/** Wait time between IO change in ns. */
+#define RVB_SENSOR_DELAY_IO 125
+/** All the possible states. */
+#define RVB_STATE_SLEEP 0 /* Doing nothing */
+#define RVB_STATE_NEXT_SENSOR 1 /* Selecting a sensor */
+#define RVB_STATE_WAIT_IC 20 /* Waiting for the first input capture */
+#define RVB_STATE_WAIT_IC2 (RVB_STATE_WAIT_IC + 1) /* 2nd and more false
+ input captures */
+#define RVB_STATE_START_CAPTURE 2 /* After waiting enough IC, starting capture */
+#define RVB_STATE_STOP_CAPTURE 3 /* We can compute a value */
+#define RVB_STATE_NEXT_COLOR 4 /* Selecting another color */
+#define RVB_STATE_WATCH 5 /* For debuging */
+
+
+/*** Config ***/
+/** Max input capture before considering we can start the real capture. */
+// FIXME volatile
+uint8_t sensor_rvb_conf_max_false_ic_;
+/** Max overflow of the timer 1 before thinking the sensor is HS. */
+uint8_t sensor_rvb_conf_max_ov_;
+/** RVB sensor state flag. */
+volatile uint8_t sensor_rvb_state_;
+/** Internal computed result for one color. */
+volatile uint16_t sensor_rvb_value_;
+/** Sensor used actually for computing value. */
+volatile uint8_t sensor_rvb_number_;
+/** Color of the actual sensor. */
+volatile uint8_t sensor_rvb_color_;
+/** Number of overflow interruption since last edge change. */
+volatile uint8_t sensor_rvb_overflow_count_;
+/** Results table for 9 RVB sensors (RVCB) */
+volatile uint16_t sensor_rvb_values[RVB_MAX_SENSOR][RVB_MAX_INDEX];
+/** Count the number of IC before starting a good capture. */
+uint8_t sensor_rvb_ic_count_;
+/** Barillet sensors are enabled ? */
+volatile uint8_t sensor_rvb_barillet_flag_;
+volatile uint8_t sensor_rvb_low_sensor_flag_;
+/** We are not pooling all the sensors */
+volatile uint8_t sensor_rvb_cur_;
+
+/** Update everything for you. */
+inline void sensor_rvb_update (void);
+
+/** Are you sleeping */
+uint8_t
+sensor_rvb_state_sleeeping (void)
+{
+ return (sensor_rvb_state_ == RVB_STATE_SLEEP ? 1 : 0);
+}
+/** Select a color :
+ * 0 : red ;
+ * 1 : blue ;
+ * 2 : clear ;
+ * 3 : green. */
+inline uint8_t
+sensor_rvb_color_select (uint8_t sensor_rvb_color)
+{
+ switch (sensor_rvb_color)
+ {
+ case RVB_INDEX_RED:
+ case RVB_INDEX_BLUE:
+ case RVB_INDEX_CLEAR:
+ case RVB_INDEX_GREEN:
+ /* Select the color */
+ PORTF = (PORTF & ~0xC0) | (sensor_rvb_color << 6);
+ /* Wait a little */
+ utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ /* Color exists */
+ return 1;
+ default:
+ /* Error */
+ return 0;
+ }
+}
+
+/** Enable a RVB sensor. */
+uint8_t
+sensor_rvb_sensor_select (uint8_t sensor_rvb_num)
+{
+ switch (sensor_rvb_num)
+ {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ PORTC = ~_BV(sensor_rvb_num);
+ break;
+ case 5:
+ /* If we also want the other sensors */
+ if (sensor_rvb_low_sensor_flag_)
+ {
+ /* Normal behaviour */
+ PORTC = ~_BV(5);
+ }
+ else
+ {
+ /* Alternatively one sensor of the following */
+ if (sensor_rvb_cur_ == 0)
+ PORTC = ~_BV(5);
+ else
+ PORTC = 0x7F;
+ if (++sensor_rvb_cur_ == 2)
+ sensor_rvb_cur_ = 0;
+ }
+ break;
+ case 6:
+ if (!sensor_rvb_low_sensor_flag_)
+ {
+ /* High for disable */
+ PORTC = 0xff;
+ PORTD |= _BV(6);
+ /* Wait a little */
+ utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ return 0;
+ }
+ else
+ PORTC = ~_BV(6);
+ break;
+ case 7:
+ PORTC = 0x7F;
+ break;
+ case 8:
+ PORTD &= ~_BV(6);
+ break;
+ case 9:
+ PORTC = ~_BV(0);
+ break;
+ default:
+ /* High for disable */
+ PORTC = 0xff;
+ PORTD |= _BV(6);
+ /* Wait a little */
+ utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ return 0;
+ }
+ /* Wait a little */
+ utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ return 1;
+}
+
+/** Initialisation of the RVB sensors module. */
+void
+sensor_rvb_init (void)
+{
+ /* Init config */
+ sensor_rvb_conf_max_false_ic_ = RVB_MAX_FALSE_IC;
+ sensor_rvb_conf_max_ov_ = RVB_MAX_OVERFLOW;
+ /* No sensor selected */
+ sensor_rvb_sensor_select (0);
+ /* Put ENA* pins in output */
+ DDRC = 0xff;
+ DDRD |= _BV(6);
+ /* Put color selector pins in output */
+ DDRF |= _BV(S0RVB) | _BV(S1RVB);
+ /* Put asserv color states pins in output */
+ DDRA |= _BV(7) | _BV(6) | _BV(5) | _BV(4);
+ /* Nothing to do for the moment */
+ sensor_rvb_state_ = RVB_STATE_SLEEP;
+}
+
+/** Configure some internal variables. */
+void
+sensor_rvb_config (uint8_t false_ic, uint8_t max_ov)
+{
+ sensor_rvb_conf_max_false_ic_ = false_ic;
+ sensor_rvb_conf_max_ov_ = max_ov;
+}
+
+/** Start updating RVBC values for sensors. */
+void
+sensor_rvb_start_capture (void)
+{
+ /* Are we already getting a sensor ? */
+ if (sensor_rvb_state_ == RVB_STATE_SLEEP)
+ {
+ sensor_rvb_state_ = RVB_STATE_NEXT_SENSOR;
+ /* Start with sensor one */
+ sensor_rvb_number_ = 0;
+ /* Select it and launch capture */
+ sensor_rvb_update ();
+ /* Ensure we have no pending interrupt for IC1. */
+ TIFR = _BV (ICF1);
+ TIFR = _BV (TOV1);
+ /* Enable interrupt for IC1 and counter overflow */
+ TIMSK |= _BV (TICIE1);
+ TIMSK |= _BV (TOIE1);
+ }
+}
+
+/** Update everything for you. */
+void
+sensor_rvb_update (void)
+{
+ if (sensor_rvb_state_ == RVB_STATE_NEXT_COLOR)
+ {
+ /* Select the color */
+ if (!sensor_rvb_color_select (++sensor_rvb_color_))
+ {
+ /* No more colors for this sensor, next sensor please */
+ sensor_rvb_state_ = RVB_STATE_NEXT_SENSOR;
+ }
+ else
+ {
+ sensor_rvb_state_ = RVB_STATE_WAIT_IC;
+ /* Ensure we have no pending interrupt for IC1. */
+ TIFR = _BV (ICF1);
+ /* Enable interrupt for IC1 */
+ TIMSK |= _BV (TICIE1);
+ }
+ }
+ if (sensor_rvb_state_ == RVB_STATE_NEXT_SENSOR)
+ {
+ /* Disable sensors */
+ sensor_rvb_sensor_select (0);
+ /* Select sensor */
+ if (!sensor_rvb_sensor_select (++sensor_rvb_number_))
+ {
+ /* Disable IC1 and TC1 overflow interrupts */
+ TIMSK &= ~_BV (TICIE1);
+ TIMSK &= ~_BV (TOIE1);
+ /* Finish ! Go to sleep */
+ sensor_rvb_state_ = RVB_STATE_SLEEP;
+ return;
+ }
+ /* Start with first color */
+ sensor_rvb_color_select (sensor_rvb_color_ = 0);
+ sensor_rvb_state_ = RVB_STATE_WAIT_IC;
+ sensor_rvb_overflow_count_ = 0;
+ /* Ensure we have no pending interrupt for IC1. */
+ TIFR = _BV (ICF1);
+ /* Enable interrupt for IC1 */
+ TIMSK |= _BV (TICIE1);
+ }
+}
+
+/** Timer 1 overflow. */
+SIGNAL (SIG_OVERFLOW1)
+{
+ switch (sensor_rvb_state_)
+ {
+ case RVB_STATE_STOP_CAPTURE:
+ ++sensor_rvb_overflow_count_;
+ break;
+ case RVB_STATE_WAIT_IC:
+ case RVB_STATE_WAIT_IC2:
+ // XXX >= Sucks !
+ // TODO : check this >= and the IC2 used
+ if (++sensor_rvb_overflow_count_ >= sensor_rvb_conf_max_ov_)
+ {
+ /* Invalidate the sensor */
+ if (!sensor_rvb_low_sensor_flag_ && (sensor_rvb_number_ == 5))
+ if (sensor_rvb_cur_ == 0)
+ sensor_rvb_values[6][0] = RVB_INVALID_CAPTURE;
+ else
+ sensor_rvb_values[4][0] = RVB_INVALID_CAPTURE;
+ else
+ sensor_rvb_values[sensor_rvb_number_ - 1][0] = RVB_INVALID_CAPTURE;
+ /* Disable IC interrupt */
+ TIMSK &= ~_BV (TICIE1);
+ /* Ask for next sensor */
+ sensor_rvb_state_ = RVB_STATE_NEXT_SENSOR;
+ sensor_rvb_update ();
+ }
+ break;
+ }
+}
+
+/** Interrupt on falling edge for Input Capture 1. */
+SIGNAL (SIG_INPUT_CAPTURE1)
+{
+ /* Save it earlier ! */
+ uint16_t ic1_cache = ICR1;
+ uint16_t result;
+ switch (sensor_rvb_state_)
+ {
+ case RVB_STATE_WAIT_IC:
+ sensor_rvb_ic_count_ = sensor_rvb_conf_max_false_ic_;
+ sensor_rvb_state_ = RVB_STATE_WAIT_IC2;
+ /* nobreak */
+ case RVB_STATE_WAIT_IC2:
+ if (!--sensor_rvb_ic_count_)
+ /* Last ignored capture */
+ sensor_rvb_state_ = RVB_STATE_START_CAPTURE;
+ break;
+ case RVB_STATE_START_CAPTURE:
+ /* Manage case when overflow occured before IC but we are called first
+ * */
+ if (!(ic1_cache & (TC1_TOP & ~(TC1_TOP >> 1))))
+ TIFR = _BV (TOV1);
+ /* Save capture start */
+ sensor_rvb_value_ = ic1_cache;
+ /* Reset overflow_count */
+ sensor_rvb_overflow_count_ = 0;
+ /* New capture */
+ sensor_rvb_state_ = RVB_STATE_STOP_CAPTURE;
+ break;
+ case RVB_STATE_STOP_CAPTURE:
+ /* Compute value */
+ result = ic1_cache + sensor_rvb_overflow_count_ * (TC1_TOP + 1) -
+ sensor_rvb_value_;
+ if (!sensor_rvb_low_sensor_flag_ && (sensor_rvb_number_ == 5))
+ if (sensor_rvb_cur_ == 0)
+ sensor_rvb_values[6][sensor_rvb_color_] = result;
+ else
+ sensor_rvb_values[4][sensor_rvb_color_] = result;
+ else
+ sensor_rvb_values[sensor_rvb_number_ - 1][sensor_rvb_color_] =
+ result;
+ /* Disable IC interrupt */
+ TIMSK &= ~_BV (TICIE1);
+ sensor_rvb_state_ = RVB_STATE_NEXT_COLOR;
+ /* Next please */
+ sensor_rvb_update ();
+ break;
+ }
+}
+
+/** Update pins connected to the asserv AVR with the colors seen by the
+ * sensors. */
+void
+sensor_rvb_update_asserv_pins (void)
+{
+ uint8_t compt;
+
+ if (sensor_rvb_state_ == RVB_STATE_SLEEP)
+ {
+ for (compt = 0; compt < 4; compt++)
+ {
+ /* Is sensor capture valid */
+ if (sensor_rvb_values[compt][0] < RVB_INVALID_CAPTURE)
+ {
+ if (sniff_rvb_analysis_color (compt, RVB_SNIFF_ONLY_GREEN)
+ != RVB_SNIFF_GREEN)
+ PORTA |= _BV (compt + 4);
+ else
+ PORTA &= ~_BV (compt + 4);
+ }
+ }
+ }
+
+ // TODO:
+ // - called the desired sensors with sensor_rvb_analysis_color ;
+ // - choose with Ni ;
+ // - do we need to update all the pins ?
+ // - this functions have to be hightly configurable : for example, choose
+ // if we can select frequency of update ;
+ // - manage a case for knowing the mode of the robot in order to select
+ // which pins we should update.
+}
+
+/** Enable/disable capture for black & white sensors (the ones inside the
+ * barillet).
+ */
+void
+sensor_rvb_upper_sensors (uint8_t enable)
+{
+ if (enable)
+ sensor_rvb_low_sensor_flag_ = 1;
+ else
+ {
+ /* Invalidate all capture */
+ // XXX Good idea ?
+ sensor_rvb_low_sensor_flag_ = 0;
+ sensor_rvb_values[8][0] =
+ sensor_rvb_values[7][0] = RVB_INVALID_CAPTURE;
+ }
+}
+
diff --git a/n/es-2007/src/sensor_rvb.h b/n/es-2007/src/sensor_rvb.h
new file mode 100644
index 0000000..3ffeadc
--- /dev/null
+++ b/n/es-2007/src/sensor_rvb.h
@@ -0,0 +1,96 @@
+#ifndef sensor_rvb_h
+#define sensor_rvb_h
+// sensor_rvb.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// 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 "common.h"
+#include "io.h"
+
+/** Manage all the RVB sensors.
+ * Connectors used :
+ ENARVB7 PORTC7
+ ENARVB6 PORTC6
+ ENARVB5 PORTC5
+ ENARVB4 PORTC4
+ ENARVB3 PORTC3
+ ENARVB2 PORTC2
+ ENARVB1 PORTC1
+ ENANB1 PORTD6
+ ENANB2 PORTC0
+ OUTRVB PORTD7/PORTD4(IC1)
+ S0RVB PORTF6
+ S1RVB PORTF7
+
+ Sensors actualy send us a frequency for a specific color. We have pins
+ (ENA*) for selecting the sensor we want to use, some (S[01]RVB) for the
+ color we want to watch and one (OUTRVB) for the output frequency.
+ It uses the Input Capture and the Overflow interrupts.
+*/
+
+/** Maximum number of sensors we manage. */
+#define RVB_MAX_SENSOR 9
+/** Define the colors indexes. */
+#define RVB_INDEX_RED 0
+#define RVB_INDEX_BLUE 1
+#define RVB_INDEX_CLEAR 2
+#define RVB_INDEX_GREEN 3
+/** Define the number of color the sensor can manages. */
+#define RVB_MAX_INDEX 4
+/** Is it an invalid value for sensor */
+#define RVB_INVALID_CAPTURE 0xE000
+
+/** Results table for 9 RVB sensors (RVCB) :
+ * Values are in the folowing order : Red, Blue, Clear, Green. */
+extern volatile uint16_t sensor_rvb_values[RVB_MAX_SENSOR][RVB_MAX_INDEX];
+
+/** Initialisation of the RVB sensors module. */
+void sensor_rvb_init (void);
+
+/** Start a capture RVBC values for sensors if we are not already doing one. */
+void sensor_rvb_start_capture (void);
+
+/** Configure some internal variables.
+ * - false_ic : maximum input capture to ignore before begining the real
+ * capture.
+ * - max_ov : maximum overflow of the timer/counter 1 before setting the
+ * sensor dead. uint8_t !
+ */
+void sensor_rvb_config (uint8_t false_ic, uint8_t max_ov);
+
+/** Update pins connected to the asserv AVR with the colors seen by the
+ * sensors. */
+void sensor_rvb_update_asserv_pins (void);
+
+/** Enable/disable capture for black & white sensors (the ones inside the
+ * barillet).
+ * - enable : 1 if you want this sensor to be captured, 0 otherwise.
+ */
+void sensor_rvb_upper_sensors (uint8_t enable);
+
+/** Are you sleeping */
+uint8_t sensor_rvb_state_sleeeping (void);
+
+
+#endif // sensor_rvb_h
diff --git a/n/es-2007/src/servo_motor.c b/n/es-2007/src/servo_motor.c
new file mode 100644
index 0000000..84e4d80
--- /dev/null
+++ b/n/es-2007/src/servo_motor.c
@@ -0,0 +1,185 @@
+/* servo_motor.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * 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 "servo_motor.h"
+
+#include "io.h"
+#include "common.h"
+#include "modules/utils/utils.h"
+#include "modules/utils/byte.h"
+
+/** TOP of the timer/counter 2. */
+#define TC2_TOP 0xFF
+/** Prescaler of the timer/counter2. */
+#define TC2_PRESCALER 256
+/** Delay a full cycle in TIC before restarting should last (in 100µs). */
+/* time * AC_FREQ / TC2_PRESCALER */
+#define SRVM_CYCLE_DELAY 1152
+/** The servo motor identifier. */
+#define SRVM_TRASH_PIN 0 /* the trash system */
+#define SRVM_TOTEML_PIN 3 /* first totem */
+#define SRVM_TOTEMR_PIN 2 /* second totem */
+/** Table for the time spend by each servo in high position. */
+volatile uint8_t servo_time[3] = { SRVM_TRASH_POS_CLOSE, SRVM_RIGHT_POS_IN, SRVM_LEFT_POS_IN };
+/** Different states of this module. */
+
+#define SRVM_STATE_SLEEP 0
+#define SRVM_STATE_TRASH 1
+#define SRVM_STATE_TOTEM1 2
+#define SRVM_STATE_TOTEM2 3
+
+/** State variable. */
+volatile uint8_t servo_motor_state;
+/** Time the TC2 have to sleep after manage all the servo motor. */
+volatile uint16_t srvm_need_to_sleep;
+
+/** Init the servo motor system. */
+void
+servo_motor_init (void)
+{
+ /* All the pins are in out mode */
+ DDRB |= _BV (SRVM_TRASH_PIN) | _BV (SRVM_TOTEML_PIN) |
+ _BV (SRVM_TOTEMR_PIN);
+ /* We are sleeping */
+ servo_motor_state = SRVM_STATE_SLEEP;
+ /* Prescaler 256 => 4.44 ms TOP */
+ TCCR2 = regv (FOC2, WGM20, COM21, COM20, WGM21, CS22, CS21, CS20,
+ 0, 0, 0, 0, 0, 1, 0, 0);
+ /* Enable overflow interrupt */
+ TIMSK |= _BV (TOIE2);
+ /* Iniate to delay */
+ srvm_need_to_sleep = SRVM_CYCLE_DELAY;
+}
+
+/** Ask the servo motor to go to a position. */
+void
+servo_motor_set_pos (uint8_t servo_mask, uint8_t servo_pos)
+{
+ uint8_t num;
+ /* for each servo motor */
+ for (num = 0; num < 3; num++)
+ if (servo_mask & _BV (num))
+ {
+ /* Set the value and bound it */
+ servo_time[num] = servo_pos;
+ /* Trash */
+ if (num == 0)
+ UTILS_BOUND (servo_time[num], SRVM_TRASH_POS_OPEN,
+ SRVM_TRASH_POS_CLOSE);
+ /* Totem1 */
+ else if (num == 1)
+ UTILS_BOUND (servo_time[num], SRVM_RIGHT_POS_OUT,
+ SRVM_RIGHT_POS_IN);
+ /* Totem Left */
+ else if (num == 2)
+ UTILS_BOUND (servo_time[num], SRVM_LEFT_POS_IN,
+ SRVM_LEFT_POS_OUT);
+ }
+}
+
+/** What is your current position my dear servo motor ? */
+inline uint8_t
+servo_motor_get_pos (uint8_t servo_num)
+{
+ return servo_time[servo_num];
+}
+
+SIGNAL (SIG_OVERFLOW2)
+{
+ /* Overflow count for time sleeping */
+ static int8_t srvm_ov_for_sleeping = -1;
+
+ switch (servo_motor_state)
+ {
+ case SRVM_STATE_SLEEP:
+ /* We remove from the TOP the number of TIC of this servo */
+ TCNT2 = TC2_TOP - servo_time[servo_motor_state];
+ /* We activate the pin */
+ PORTB |= _BV (SRVM_TRASH_PIN);
+ /* We remove the TIC of this servo from the main one */
+ srvm_need_to_sleep -= servo_time[servo_motor_state];
+ /* Next state */
+ servo_motor_state = SRVM_STATE_TRASH;
+ break;
+ case SRVM_STATE_TRASH:
+ /* We remove from the TOP the number of TIC of this servo */
+ TCNT2 = TC2_TOP - servo_time[servo_motor_state];
+ /* Unactivate previous pin */
+ PORTB &= ~_BV (SRVM_TRASH_PIN);
+ /* We activate the pin */
+ PORTB |= _BV (SRVM_TOTEML_PIN);
+ /* We remove the TIC of this servo from the main one */
+ srvm_need_to_sleep -= servo_time[servo_motor_state];
+ /* Next state */
+ servo_motor_state = SRVM_STATE_TOTEM1;
+ break;
+ case SRVM_STATE_TOTEM1:
+ /* We remove from the TOP the number of TIC of this servo */
+ TCNT2 = TC2_TOP - servo_time[servo_motor_state];
+ /* Unactivate previous pin */
+ PORTB &= ~_BV (SRVM_TOTEML_PIN);
+ /* We activate the pin */
+ PORTB |= _BV (SRVM_TOTEMR_PIN);
+ /* We remove the TIC of this servo from the main one */
+ srvm_need_to_sleep -= servo_time[servo_motor_state];
+ /* Next state */
+ servo_motor_state = SRVM_STATE_TOTEM2;
+ break;
+ case SRVM_STATE_TOTEM2:
+ if (srvm_ov_for_sleeping == -1)
+ {
+ /* We need to wait some TIC */
+ TCNT2 = TC2_TOP - v16_to_v8 (srvm_need_to_sleep, 0);
+ /* Unactivate previous pin */
+ PORTB &= ~_BV (SRVM_TOTEMR_PIN);
+ /* Calculate the OV */
+ srvm_ov_for_sleeping = srvm_need_to_sleep >> 8;
+ }
+ else
+ {
+ if (--srvm_ov_for_sleeping == -1)
+ {
+ /* Next state */
+ servo_motor_state = SRVM_STATE_SLEEP;
+ /* Re init */
+ srvm_need_to_sleep = SRVM_CYCLE_DELAY;
+ }
+ }
+ break;
+ }
+}
+
+/** Open the trash. */
+void
+servo_motor_open_trash (void)
+{
+ servo_motor_set_pos (1, SRVM_TRASH_POS_OPEN);
+}
+
+/** Close the trash. */
+void
+servo_motor_close_trash (void)
+{
+ servo_motor_set_pos (1, SRVM_TRASH_POS_CLOSE);
+}
diff --git a/n/es-2007/src/servo_motor.h b/n/es-2007/src/servo_motor.h
new file mode 100644
index 0000000..455ce4d
--- /dev/null
+++ b/n/es-2007/src/servo_motor.h
@@ -0,0 +1,61 @@
+#ifndef servo_motor_h
+#define servo_motor_h
+// servo_motor.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// 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.
+//
+// }}}
+
+/** Module for controlling the servo motor for the totems. */
+
+#include "common.h"
+
+/** All the states used to comunicate with this module. */
+#define SRVM_LEFT_POS_IN 95
+#define SRVM_LEFT_POS_OUT 130
+#define SRVM_RIGHT_POS_IN 78
+#define SRVM_RIGHT_POS_OUT 45
+#define SRVM_TRASH_POS_OPEN 68 /* 44 */
+#define SRVM_TRASH_POS_CLOSE 100 /* 64 */
+
+/** Init the servo motor system. */
+void servo_motor_init (void);
+
+/** Ask the servo motor to go to a position.
+ * - servo_mask: mask for sensor ;
+ * - servo_pos : desired position.
+ */
+void servo_motor_set_pos (uint8_t servo_mask, uint8_t servo_pos);
+
+/** What is your current position my dear servo motor ?
+ * - servo_num : sensor number (not a mask) ;
+ * - return : desired position.
+ */
+uint8_t servo_motor_get_pos (uint8_t servo_num);
+
+/** Open the trash. */
+void servo_motor_open_trash (void);
+
+/** Close the trash. */
+void servo_motor_close_trash (void);
+
+#endif // servo_motor_h
diff --git a/n/es-2007/src/sharp.c b/n/es-2007/src/sharp.c
new file mode 100644
index 0000000..167b86b
--- /dev/null
+++ b/n/es-2007/src/sharp.c
@@ -0,0 +1,106 @@
+/* sharp.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * 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 "sharp.h"
+
+#include "modules/adc/adc.h"
+#include "modules/utils/utils.h"
+
+/** Array of sharp values. */
+uint16_t sharp_values[SHARP_NUMBER];
+
+/** Thresholds */
+uint16_t sharp_threshold_high_[SHARP_NUMBER],
+ sharp_threshold_low_[SHARP_NUMBER];
+uint8_t sharp_old_state[SHARP_NUMBER];
+
+/** Init this module. */
+void
+sharp_init (void)
+{
+ uint8_t compt;
+ /* Init ADC module */
+ adc_init ();
+ /* All pins are on the right direction, nothing to do */
+ for (compt = 0; compt < SHARP_NUMBER; compt++)
+ {
+ sharp_threshold_high_[compt] = 5000;
+ sharp_threshold_low_[compt] = 4000;
+ }
+}
+
+/** Read data from sharp sensors. */
+void
+sharp_update_values (uint8_t sharp_num)
+{
+ /* Check sharp exists (prevent kernel panic) */
+ if (sharp_num < SHARP_NUMBER)
+ {
+ /* Start capture */
+ adc_start (sharp_num + 1);
+ /* Wait ADC to finish the sensor */
+ while (!adc_checkf ())
+ ;
+ /* Wait a little */
+ utils_delay_us (250);
+ /* Get values */
+ sharp_values[sharp_num] = adc_read ();
+ }
+}
+
+/** Analyse a sharp value. */
+int8_t
+sharp_analyse_values (uint8_t sharp_num)
+{
+ /* Check sharp exists (prevent kernel panic) */
+ if (sharp_num < SHARP_NUMBER)
+ {
+ // XXX Check more often first
+ if (sharp_values[sharp_num] < sharp_threshold_low_[sharp_num])
+ {
+ sharp_old_state[sharp_num] = SHARP_CLEAR;
+ return SHARP_CLEAR;
+ }
+ if (sharp_values[sharp_num] > sharp_threshold_high_[sharp_num])
+ {
+ sharp_old_state[sharp_num] = SHARP_OBSTACLE;
+ return SHARP_OBSTACLE;
+ }
+ /* If we are here, we are inside the threshold, look at previous value */
+ return sharp_old_state[sharp_num];
+ }
+ return -1;
+}
+
+/** Configure sharp threshold. */
+void
+sharp_config_threshold (uint8_t sharp_num, uint16_t high, uint16_t low)
+{
+ /* Check sharp exists (prevent kernel panic) */
+ if (sharp_num < SHARP_NUMBER)
+ {
+ sharp_threshold_high_[sharp_num] = high;
+ sharp_threshold_low_[sharp_num] = low;
+ }
+}
diff --git a/n/es-2007/src/sharp.h b/n/es-2007/src/sharp.h
new file mode 100644
index 0000000..e5f1a58
--- /dev/null
+++ b/n/es-2007/src/sharp.h
@@ -0,0 +1,70 @@
+#ifndef sharp_h
+#define sharp_h
+// sharp.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// 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.
+//
+// }}}
+/** Module for reading sharp sensors. */
+
+#include "common.h"
+
+/** Sharps positions
+ * ADC1 -> Rear ball
+ * ADC2 -> Front
+ * ADC3 -> Front
+ */
+
+/** Number of sharps. */
+#define SHARP_NUMBER 3
+
+/** Something in front of the sharp */
+#define SHARP_OBSTACLE 1
+/** Nothing in front of the sharp */
+#define SHARP_CLEAR 0
+
+/** Array of sharp values. */
+extern uint16_t sharp_values[SHARP_NUMBER];
+
+/** Init this module. */
+void sharp_init (void);
+
+/** Read data from sharp sensors.
+ * - sharp_num : the sharp number you want to update.
+ */
+void sharp_update_values (uint8_t sharp_num);
+
+/** Analyse a sharp value.
+ * - sharp_num : the sharp number you want to analyse.
+ * - return : SHARP_CLEAR if nothing in front, SHARP_OBSTACLE otherwise.
+ */
+int8_t sharp_analyse_values (uint8_t sharp_num);
+
+/** Configure sharp threshold.
+ * - sharp_num : the sharp number you want to configure threshold.
+ * - high : high threshold.
+ * - low : low threshold.
+ * Note, high > low !
+ */
+void sharp_config_threshold (uint8_t sharp_num, uint16_t high, uint16_t low);
+
+#endif // sharp_h
diff --git a/n/es-2007/src/sniff_rvb.c b/n/es-2007/src/sniff_rvb.c
new file mode 100644
index 0000000..cc3c126
--- /dev/null
+++ b/n/es-2007/src/sniff_rvb.c
@@ -0,0 +1,190 @@
+/* sniff_rvb.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * 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 "sniff_rvb.h"
+
+#include "io.h"
+#include "common.h"
+
+#include "sensor_rvb.h"
+
+/** Reference color. */
+uint16_t sniff_rvb_reference_color[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
+/** Ratio min max */
+uint16_t sniff_rvb_reference_color_min[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
+uint16_t sniff_rvb_reference_color_max[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
+/** Ratio for the computing the min/max value from the reference color. */
+uint8_t sniff_rvb_ref_ratio_ = 3;
+
+/* test with new robot clothes */
+/* ball black/white detection */
+uint16_t green_limit_ = 3700;
+uint16_t clear_limit_ = 4000;
+
+/** Configure the sensor analysis system. */
+void
+sniff_rvb_config (uint8_t ref_ratio, uint16_t green_limit,
+ uint16_t clear_limit)
+{
+ sniff_rvb_ref_ratio_ = ref_ratio;
+ green_limit_ = green_limit;
+ clear_limit_ = clear_limit;
+}
+
+/** Try to reference the sensor_num sensor into the reference color. */
+inline uint8_t
+sniff_rvb_try_reference (uint8_t sensor_num, uint16_t
+ ref[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX])
+{
+ uint8_t compt;
+ /* If sensor is valid */
+ if (sensor_rvb_values[sensor_num][0] < RVB_INVALID_CAPTURE)
+ {
+ /* For each color add this value by averrage */
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ if (ref[sensor_num][compt] == 0)
+ {
+ ref[sensor_num][compt] =
+ sensor_rvb_values[sensor_num][compt];
+ }
+ else
+ {
+ ref[sensor_num][compt] =
+ (sensor_rvb_values[sensor_num][compt] / 2
+ + ref[sensor_num][compt] / 2);
+ }
+ return !0;
+ }
+ return 0;
+}
+
+/* test "barillet" black/white */
+uint8_t
+sniff_rvb_analysis_ball (uint8_t sensor)
+{
+ /* If sensor is valid */
+ if (sensor_rvb_values[sensor][0] < RVB_INVALID_CAPTURE)
+ {
+ // XXX We can use all four values, and not only two ?
+ if ((sensor_rvb_values[sensor][RVB_INDEX_GREEN] > green_limit_)
+ && (sensor_rvb_values[sensor][RVB_INDEX_CLEAR] > clear_limit_))
+ return RVB_SNIFF_BLACK;
+ else
+ return RVB_SNIFF_WHITE;
+ }
+ return 0;
+}
+
+/* Test blue or red */
+uint8_t
+sniff_rvb_analysis_color_other (uint8_t sensor, uint8_t color)
+{
+ uint8_t what_is_it = RVB_SNIFF_OTHER;
+ if (color == RVB_SNIFF_BLUE)
+ {
+ if (sensor_rvb_values[sensor][RVB_INDEX_CLEAR] < sniff_rvb_reference_color[sensor][RVB_INDEX_CLEAR])
+ what_is_it = RVB_SNIFF_BLUE;
+ }
+ else if (color == RVB_SNIFF_RED)
+ {
+ if ((sensor_rvb_values[sensor][RVB_INDEX_RED] < sniff_rvb_reference_color[sensor][RVB_INDEX_RED])
+ && (sensor_rvb_values[sensor][RVB_INDEX_CLEAR] > sniff_rvb_reference_color[sensor][RVB_INDEX_CLEAR])
+ && (sensor_rvb_values[sensor][RVB_INDEX_GREEN] > sniff_rvb_reference_color[sensor][RVB_INDEX_GREEN]))
+ what_is_it = RVB_SNIFF_RED;
+ }
+ return what_is_it;
+}
+
+/** Analysis a color */
+uint8_t
+sniff_rvb_analysis_color (uint8_t sensor, uint8_t mode)
+{
+ uint8_t compt, what_is_it = RVB_SNIFF_GREEN;
+ /* test for green */
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ {
+ if ((sensor_rvb_values[sensor][compt] < sniff_rvb_reference_color_min[sensor][compt])
+ || (sensor_rvb_values[sensor][compt] > sniff_rvb_reference_color_max[sensor][compt]))
+ {
+ what_is_it = RVB_SNIFF_OTHER;
+ break;
+ }
+ }
+
+ if ((what_is_it == RVB_SNIFF_GREEN) || (mode == RVB_SNIFF_ONLY_GREEN))
+ return what_is_it;
+
+ /* test for red */
+ if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_RED)
+ == RVB_SNIFF_RED)
+ {
+ what_is_it = RVB_SNIFF_RED;
+ return what_is_it;
+ }
+ /* test for blue */
+ if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_BLUE)
+ == RVB_SNIFF_BLUE)
+ {
+ what_is_it = RVB_SNIFF_BLUE;
+ return what_is_it;
+ }
+ /* else other */
+ return RVB_SNIFF_OTHER;
+}
+
+
+/* sub function of sniff_rvb_set_ref_color */
+void
+sniff_rvb_set_ref_color_green (uint8_t sensor)
+{
+ uint8_t compt;
+ if (sniff_rvb_try_reference (sensor, sniff_rvb_reference_color))
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ {
+ sniff_rvb_reference_color_min[sensor][compt] =
+ sniff_rvb_reference_color[sensor][compt] -
+ (sniff_rvb_reference_color[sensor][compt] / sniff_rvb_ref_ratio_);
+ sniff_rvb_reference_color_max[sensor][compt] =
+ sniff_rvb_reference_color[sensor][compt] +
+ (sniff_rvb_reference_color[sensor][compt] / sniff_rvb_ref_ratio_);
+ }
+}
+
+/** Set the current color seen by some sensors as the reference color
+ * and do some cache creation for preventing useless computing. */
+void
+sniff_rvb_set_ref_color (uint8_t sensor, uint8_t color)
+{
+ // Check machine state ?
+ switch (color)
+ {
+ case RVB_SNIFF_GREEN:
+ sniff_rvb_set_ref_color_green (sensor);
+ break;
+ case RVB_SNIFF_RED:
+ case RVB_SNIFF_BLUE:
+ break;
+ }
+}
+
diff --git a/n/es-2007/src/sniff_rvb.h b/n/es-2007/src/sniff_rvb.h
new file mode 100644
index 0000000..bf988b4
--- /dev/null
+++ b/n/es-2007/src/sniff_rvb.h
@@ -0,0 +1,71 @@
+#ifndef sniff_rvb_h
+#define sniff_rvb_h
+// sniff_rvb.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// 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 "io.h"
+#include "common.h"
+
+/** Analysis sensors and determine the colors. */
+
+#define RVB_SNIFF_MAX_INDEX 4
+#define RVB_SNIFF_GREEN 0
+#define RVB_SNIFF_BLUE 1
+#define RVB_SNIFF_RED 2
+#define RVB_SNIFF_OTHER 3
+#define RVB_SNIFF_BLACK 4
+#define RVB_SNIFF_WHITE 5
+
+/** Mode for color detection
+ * ONLY_GREEN is faster but tells only if it's green or not
+ **/
+#define RVB_SNIFF_ONLY_GREEN 0
+#define RVB_SNIFF_ALL_COLORS 1
+
+
+/** Set the current color seen by some sensors as the reference color.
+ * It must be called at the begining of the match for setting the green value.
+ */
+void sniff_rvb_set_ref_color (uint8_t sensor, uint8_t color);
+
+/** Analysis a color :
+ * - sensor : the sensor number to analysis ;
+ * - mode : for futur use.
+ * return the color number.
+ */
+uint8_t sniff_rvb_analysis_color (uint8_t sensor, uint8_t mode);
+
+/* Test "barillet" black/white
+ * - sensor : the sensor number to analysis ;
+*/
+uint8_t sniff_rvb_analysis_ball (uint8_t sensor);
+
+/** Configure the sensor analysis system.
+ * - ref_ratio : ratio for the reference color.
+ */
+void sniff_rvb_config (uint8_t ref_ratio, uint16_t green_limit,
+ uint16_t clear_limit);
+
+#endif // sniff_rvb_h
diff --git a/n/es-2007/src/timer_1.c b/n/es-2007/src/timer_1.c
new file mode 100644
index 0000000..97b29fd
--- /dev/null
+++ b/n/es-2007/src/timer_1.c
@@ -0,0 +1,50 @@
+/* timer_1.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * 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 "timer_1.h"
+
+/** Initialisation of the shared register for the timer/counter 1. */
+inline void
+timer1_init (void)
+{
+ /* Initialisation of timer/counter 1 control register A :
+ * - pwm : TODO Complete it please !
+ */
+ TCCR1A =
+ regv (COM1A1, COM1A0, COM1B1, COM1B0, COM1C1, COM1C0, WGM11, WGM10,
+ 1, 0, 1, 0, 1, 0, 1, 1 );
+ /* Initialisation of timer/counter 1 control register B :
+ * - shared : 1 for prescaling ;
+ * - rvb : noise canceler, IC on falling edge ;
+ * - pwm : Fast PWM 10 bits.
+ */
+ TCCR1B = regv (ICNC1, ICES1, 5, WGM13, WGM12, CS12, CS11, CS10,
+ 1, 0, 0, 0, 1, 0, 0, 1 );
+ /* Initialisation of timer/counter 1 control register C :
+ * - pwm : TODO.
+ */
+// TCCR1C = regv (F0C1A, FOC1B, FOC1C, 4, 3, 2, 1, 0,
+// 0, 0, 0, 0, 0, 0, 0, 0);
+}
+
diff --git a/n/es-2007/src/timer_1.h b/n/es-2007/src/timer_1.h
new file mode 100644
index 0000000..3981c3c
--- /dev/null
+++ b/n/es-2007/src/timer_1.h
@@ -0,0 +1,41 @@
+#ifndef timer_1_h
+#define timer_1_h
+// timer_1.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// 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 "modules/utils/utils.h" /* regv */
+#include "common.h" /* TCCR1*... */
+
+/** Common defines shared between differents modules inside the ES program. */
+
+/** The TOP of the timer/counter 1.
+ * This define has to be update by hand every time you change the
+ * configuration of the timer/counter 1. */
+#define TC1_TOP 0x03FF
+
+/** Initialisation of the shared register for the timer/counter 1. */
+extern void timer1_init (void);
+
+#endif // timer_1_h
diff --git a/n/es-2007/src/timer_main.h b/n/es-2007/src/timer_main.h
new file mode 100644
index 0000000..a130683
--- /dev/null
+++ b/n/es-2007/src/timer_main.h
@@ -0,0 +1,51 @@
+#ifndef timer_main_h
+#define timer_main_h
+// timer_main.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+// From Ni.
+//
+// Robot APB Team/Efrei 2004.
+// 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.
+//
+// }}}
+
+/** Initialise the main timer. */
+inline void
+timer_main_init (void)
+{
+ TCCR0 = regv (FOC0, WGM00, COM01, COM0, WGM01, CS02, CS01, CS00,
+ 0, 0, 0, 0, 0, 1, 0, 1);
+ /* Fov = F_io / (prescaler * (TOP + 1))
+ * TOP = 0xff
+ * prescaler = 256
+ * Tov = 1 / Fov = 4.444 ms */
+}
+
+/** Wait for main timer overflow. */
+inline void
+timer_main_wait (void)
+{
+ while (!(TIFR & _BV (TOV0)))
+ ;
+ /* Write 1 to clear. */
+ TIFR = _BV (TOV0);
+}
+
+#endif // timer_main_h