summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--n/es/src/avrconfig.h66
-rw-r--r--n/es/src/carte_capteurs.c78
-rw-r--r--n/es/src/carte_capteurs.h32
-rw-r--r--n/es/src/main.c64
-rw-r--r--n/es/src/tourelle.c182
-rw-r--r--n/es/src/tourelle.h30
6 files changed, 452 insertions, 0 deletions
diff --git a/n/es/src/avrconfig.h b/n/es/src/avrconfig.h
new file mode 100644
index 0000000..a96d7ef
--- /dev/null
+++ b/n/es/src/avrconfig.h
@@ -0,0 +1,66 @@
+#ifndef avrconfig_h
+#define avrconfig_h
+/* avrconfig.h - config file for avr projects. */
+/* asserv - Position & speed motor control on a ATmega128. {{{
+ *
+ * Copyright (C) 2004 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2005.
+ * 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.
+ *
+ * }}} */
+
+/* global */
+/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
+ * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
+#define AC_FREQ 14745600
+
+/* rs232 - RS232 Module. */
+/** Baudrate : 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800,
+ * 115200, 230400, 250000, 500000, 1000000. */
+#define AC_RS232_BAUDRATE 115200
+/** Send mode :
+ * - POLLING : no interrupts;
+ * - RING : interrupts, ring buffer. */
+#define AC_RS232_SEND_MODE RING
+/** Recv mode, same as send mode. */
+#define AC_RS232_RECV_MODE RING
+/** Character size : 5, 6, 7, 8, 9 (only 8 implemented). */
+#define AC_RS232_CHAR_SIZE 8
+/** Parity : ODD, EVEN, NONE. */
+#define AC_RS232_PARITY EVEN
+/** Stop bits : 1, 2. */
+#define AC_RS232_STOP_BITS 1
+/** Send buffer size, should be power of 2 for RING mode. */
+#define AC_RS232_SEND_BUFFER_SIZE 64
+/** Recv buffer size, should be power of 2 for RING mode. */
+#define AC_RS232_RECV_BUFFER_SIZE 32
+/** Select serial port (0 or 1). */
+#define AC_RS232_PORT 1
+
+/* proto - Protocol module. */
+/** Maximum argument size. */
+#define AC_PROTO_ARGS_MAX_SIZE 8
+/** Callback function name. */
+#define AC_PROTO_CALLBACK proto_callback
+/** Putchar function name. */
+#define AC_PROTO_PUTC rs232_putc
+/** Support for quote parameter. */
+#define AC_PROTO_QUOTE 1
+
+#endif /* avrconfig_h */
diff --git a/n/es/src/carte_capteurs.c b/n/es/src/carte_capteurs.c
new file mode 100644
index 0000000..81d2870
--- /dev/null
+++ b/n/es/src/carte_capteurs.c
@@ -0,0 +1,78 @@
+/* main.c */
+/* n.avr.carte_capteurs - AVR Carte_capteur Principal Module. {{{
+ *
+ * Copyright (C) 2005 Dalmais Romain
+ *
+ * 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.
+ *
+ * Contact :
+ * Web: http://perso.efrei.fr/~dalmais/
+ * Email: <dalmais@gmail.com>
+ * }}} */
+
+//#include "rs232.h"
+//#include "I2C.h"
+#include "carte_capteur.h"
+
+/* +AutoDec */
+/* -AutoDec */
+
+int
+main (void)
+{
+ int clock;
+ int timer;
+ /// intialisation
+ renvoyer(A1,A2,A3,...);
+m:!;<F10>
+ rs232_init ();
+ I2C_init (0x01); // A CHANGER ou vérifier adresse 1
+ Tourelle_init(); // verifier
+ clock=0;
+
+ /// programme principal
+
+ while(1)
+ {
+ tourner_servo();
+ mesurer();
+ switch(buffer[0])
+ {
+ case 'z':{reset();}break;
+ case 'p':{clock=(int)buffer[1];}break;
+
+ };
+
+ if(timer==clock)
+ renvoyer(A1,A2,A3,...);
+
+ }
+
+}
+
+void
+proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
+{
+#define c(cmd, size) (cmd << 8 | size)
+ switch (c (cmd, size))
+ {
+ case c ('z', 0):
+ reset ();
+ break;
+ /* Commands. */
+ case c ('p', 0):
+ /// inclure le rencoi et la gestion du temps.
+ }
+
diff --git a/n/es/src/carte_capteurs.h b/n/es/src/carte_capteurs.h
new file mode 100644
index 0000000..2f9b993
--- /dev/null
+++ b/n/es/src/carte_capteurs.h
@@ -0,0 +1,32 @@
+#ifndef main_h
+#define main_h
+/* main.h */
+/* n.avr.carte_capteurs - AVR Carte Capteur Module. {{{
+ *
+ * Copyright (C) 2005 Dalmais Romain
+ *
+ * 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.
+ *
+ * Contact :
+ * Web: http://perso.efrei.fr/~dalmais/
+ * Email: <dalmais@gmail.com>
+ * }}} */
+
+#include "n/avr/rs232/rs232.h"
+#include "n/avr/twi-slave/twi_slave.h" // A CHANGER
+#include "n/avr/tourelle/tourelle.h"
+#include "n/avr/utils/utils.h"
+
+
diff --git a/n/es/src/main.c b/n/es/src/main.c
new file mode 100644
index 0000000..a9d0299
--- /dev/null
+++ b/n/es/src/main.c
@@ -0,0 +1,64 @@
+/* main.c */
+/* n.avr.carte_capteurs - AVR Carte_capteur Module. {{{
+ *
+ * Copyright (C) 2005 Dalmais Romain
+ *
+ * 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.
+ *
+ * Contact :
+ * Web: http://perso.efrei.fr/~schodet/
+ * Email: <contact@ni.fr.eu.org>
+ * }}} */
+
+//#include "rs232.h"
+//#include "I2C.h"
+#include "carte_capteur.h"
+
+/* +AutoDec */
+/* -AutoDec */
+
+uint8_t valeur[25];
+main (void)
+{
+ /// intialisation
+ rs232_init ();
+ I2C_init (); /// A CHANGER
+ toutelle_init ();
+
+ /// programme principal
+
+ while(1)
+ {
+ if(etat == 1)
+ {
+ etat = 0;
+ TCNT0 = 65535 - ((20*14745600)/(1024*1000));
+ if(temp_sens != sens)
+ {
+ temp_sens = sens;
+ if(continu == 1) renvoi_RS232();
+ }
+ if(buffer_serie != 0) callback_RS232();
+ }
+ if(etat == 1 && envoie == 1)
+ {
+ traitement(); //traiter les valeurs du tableau
+ renvoyer(A1,A2,A3,...); // mettre me renvoie des valeurs
+ }
+
+ }
+}
+
+
diff --git a/n/es/src/tourelle.c b/n/es/src/tourelle.c
new file mode 100644
index 0000000..b186cef
--- /dev/null
+++ b/n/es/src/tourelle.c
@@ -0,0 +1,182 @@
+/*Tourelle.c*/
+/* Detector on a ATmega128. {{{
+ * Copyright (C) 2005 Dalmais Romain
+ *
+ * Robot APB Team/Efrei 2005.
+ * 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 "Tourelle.h"
+
+const int8_t delayMax = 125;
+const int8_t delayMin = 175;
+const int8_t SEUIL = 180; // 10 cm = 2.25V et 80 cm = 1.75 V
+
+//capteur sharp sur PA0
+
+
+/* etat mode:
+ * 0 = inactif
+ * 1 = continu */
+int8_t etat=0;
+int8_t tableau_longueur[25];
+
+tourelle_init(int8_t prescaler)
+{
+ continu = 0;
+ delay = 0;
+
+ SFIOR |= 0x01; // prescaler autorisé
+
+ crenaux(delay); // on met le capteur à 0°
+ wait_1ms(20);
+
+ crenaux(delay);
+ wait_1ms(20);
+
+ crenaux(delay);
+
+ switch(prescaler)
+ {
+
+ case 81: registre_prescal |= 0x03;break;
+
+ case 64 :
+ {
+ registre_prescaler &= 0xFD;
+ registre_prescaler |= 0x01;
+ }break;
+
+ case 256 :
+ {
+ registre_prescaler &= 0xFD;
+ registre_prescaler |= 0x01;
+ }break;
+
+ case 1024: registre_prescal |= 0x03;break;
+
+ }
+}
+
+crenaux(int8_t temps, int8_t port, int8_t pin)
+{
+
+ port |= pin; // en admettant que je sois sur le portb et la troisième pin
+ wait_10us(temp);
+ port &= 0xFF - pin; // on remet l'impulsion à 0
+
+}
+
+proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
+{
+#define c(cmd, size) (cmd << 8 | size)
+ switch (c (cmd, size))
+ {
+ case c ('z', 0): reset (); break;
+
+ /* Commands. */
+
+ case c ('c', 0):{ // continu
+ etat = 1;
+ envoie = 1;
+ if(c(0,1)) sendValeur(); /// mettre la bonne fonction
+ }break;
+
+ case c ('u',0):{ // unique
+ envoie = 0;
+ sendValeur();
+ etat = 0;
+ }break;
+
+ case c ('s',0): { // stop
+ etat = 0;
+ envoie = 0;
+ }break;
+}
+
+
+TournerTourelle()
+{
+ if(delay=delayMax||delay=delayMin)
+ {
+ sens *= -1;
+
+ valeur_ancienne1 = valeur_actuelle1;
+ valeur_actuelle1 = 0;
+ valeur_ancienne2 = valeur_actuelle2;
+ valeur_actuelle2 = 0;
+
+ angle_ancien1 = angle_actuel1;
+ angle_ancien2 = angle_actuel2;
+
+ nombre_ancien = nombre_actuel;
+ }
+
+ delay += 2 * sens;
+ crenaux(delay,portc,0x07);
+}
+
+int8_t mesurer()
+{
+
+adc_init();
+adc_start();
+while(!adc_checkf)
+{wait_1us(1)}
+return adc_read();
+}
+
+
+void Timer_tourelle()
+{
+ // on fait la mesure
+ uint8_t i = 0;
+ uint8_t temp = 0;
+
+ for(i=0;i<(MILIEU*2+1);i++)
+ {
+ if(temp < tableau_longueur [i]) temp = tableau_longueur[i];
+ }
+ tableau_longueur[0] = mesurer();
+
+ if(temp == tableau_longueur[MILIEU+1])
+ {
+ if(nombre_valeur == 0)
+ {
+ valeur_actuelle1 = (PROUT - distance);
+ angle_actuel1 = 45 + (delay - 6)*90/50;
+ }
+
+ if(nombre_valeur == 1)
+ {
+ valeur_actuelle2 = (PROUT - distance);
+ angle_actuel2 = 45 + (delay - 6)*90/50;
+ }
+
+ if(nombre_valeur > 1)
+ {
+// ALARME // PROBLEME
+ }
+
+ }
+
+cycle();
+}
+
+
+
diff --git a/n/es/src/tourelle.h b/n/es/src/tourelle.h
new file mode 100644
index 0000000..95cb3dc
--- /dev/null
+++ b/n/es/src/tourelle.h
@@ -0,0 +1,30 @@
+/* Tourelle.h */
+/* Detector on a ATmega128. {{{
+ *
+ * Copyright (C) 2005 Dalmais Romain
+ *
+ * Robot APB Team/Efrei 2005
+ * 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.
+ *
+ * }}} */
+
+/* inclusion */
+
+#include <n/avr/rs232/rs232.h>
+#include <n/avr/utils/utils.h>
+#include "n/avr/twi-slave/twi_slave.h" // A CHANGER
+
+/* proto */
+
+