summaryrefslogtreecommitdiff
path: root/n
diff options
context:
space:
mode:
authordalmais2005-04-22 22:06:40 +0000
committerdalmais2005-04-22 22:06:40 +0000
commit02a5739d0cef67ac48b4b7fda5d1c8c5ed0621f0 (patch)
treee0ff6b51d4cad50bb1596b37ffe9871cca2b375b /n
parent2b19311a735adf3310ff3352b8bfdc53b5e91434 (diff)
Debut ascenseur
Diffstat (limited to 'n')
-rw-r--r--n/es/src/Makefile2
-rw-r--r--n/es/src/ascenseur.c78
-rw-r--r--n/es/src/ascenseur.h47
-rw-r--r--n/es/src/main.c90
-rw-r--r--n/es/src/tourelle.c51
5 files changed, 199 insertions, 69 deletions
diff --git a/n/es/src/Makefile b/n/es/src/Makefile
index bde642d..9ffa7b8 100644
--- a/n/es/src/Makefile
+++ b/n/es/src/Makefile
@@ -1,5 +1,5 @@
PROGS = es
-es_OBJECTS = main.o rs232.o tourelle.o adc.o twi_slave.o proto.o
+es_OBJECTS = main.o rs232.o tourelle.o adc.o twi_slave.o proto.o ascenseur.o
DOC =
EXTRACTDOC =
MODULES = n/avr/rs232 n/avr/carte_capteur n/avr/utils n/avr/adc n/avr/proto n/avr/twi-slave
diff --git a/n/es/src/ascenseur.c b/n/es/src/ascenseur.c
new file mode 100644
index 0000000..24538be
--- /dev/null
+++ b/n/es/src/ascenseur.c
@@ -0,0 +1,78 @@
+/* ascenseur.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/~dalmais
+ * Email: <dalmais@efrei.fr>
+ * }}} */
+
+#include "ascenseur.h"
+
+
+/* +AutoDec */
+/* -AutoDec */
+
+extern uint8_t clk ; // clock de la machine d'état.
+uint8_t sens_ascenseur = 0;
+
+void ascenseur_init()
+{
+ sens_ascenseur = 0;
+ TCCR2 = 0x0C ; // mode CTC | pas de OC2 | prescaler = 128
+
+
+}
+
+void asc_haut(uint8_t valeur)
+{
+ TCNT2 = valeur;
+ sens_ascenseur = MONTE;
+
+}
+
+void asc_bas(uint8_t valeur)
+{
+ TCNT2 = valeur;
+ sens_ascenseur = DESCEND;
+
+}
+
+void asc_stable(uint8_t valeur)
+{
+ TCNT2 = valeur;
+ sens_ascenseur = MONTE;
+
+}
+
+
+uint8_t capteur_bas()
+{
+return (PORTA & _BV(CAPTEUR_BAS)) ;
+}
+
+uint8_t capteur_haut()
+{
+return (PORTA & _BV(CAPTEUR_HAUT)) ;
+}
+
+
+uint8_t capteur_milieu()
+{
+return (PORTA & _BV(CAPTEUR_MILIEU)) ;
+}
diff --git a/n/es/src/ascenseur.h b/n/es/src/ascenseur.h
new file mode 100644
index 0000000..36957d7
--- /dev/null
+++ b/n/es/src/ascenseur.h
@@ -0,0 +1,47 @@
+/* ascenseur.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@efrei.fr>
+ * }}} */
+
+#ifndef ascenseur_h
+#define ascenseur_h
+
+#define CAPTEUR_BAS 0x01
+#define CAPTEUR_MILIEU 0x02
+#define CAPTEUR_HAUT 0x03
+
+#define MONTE 0
+#define DESCEND 1
+
+#include <stdint.h>
+#include "avr/io.h"
+//#include ""
+
+void ascenseur_init();
+void asc_haut(uint8_t valeur);
+void asc_bas(uint8_t valeur);
+void asc_stable(uint8_t valeur);
+uint8_t capteur_bas();
+uint8_t capteur_haut();
+uint8_t capteur_milieu();
+
+#endif
diff --git a/n/es/src/main.c b/n/es/src/main.c
index 35feb5f..2c31122 100644
--- a/n/es/src/main.c
+++ b/n/es/src/main.c
@@ -28,6 +28,7 @@
#include "avr/interrupt.h"
#include "avr/io.h"
#include <stdint.h>
+#include "ascenseur.h"
/* +AutoDec */
/* -AutoDec */
@@ -36,11 +37,16 @@ uint8_t etat = 1; // etat de fonctionnement du module
uint8_t sens = 1; // sens du scan
uint8_t continu = 0; // demande fait d'un envoi en continu sur le RS232
uint8_t envoie = 0; // demande fait par I2C d'un envoi
+uint8_t clk = 0; // clock de la machine d'état.
char buffer_serie ; // buffer RS232
const uint16_t prescaler = 8;// prescaler
uint16_t tableau_longueur[25];
-uint16_t SEUIL = 0x01AF;
+uint16_t SEUIL = 0x0100;
uint8_t mesure = 0;
+uint8_t ascenseur = 0;
+uint8_t pont;
+uint8_t vitesse_ascenseur=0;
+uint8_t commande = 0;
int main (void)
{
@@ -55,8 +61,8 @@ int main (void)
twi_init (0x02);
tourelle_init (prescaler);
adc_init ();
-
-
+ ascenseur = 1;
+ pont = 1;
sei (); // on met les interruptions
@@ -66,36 +72,68 @@ int main (void)
while(1) // boucle principale
{
- if(etat == 1)
+ if(clk == 1)
{
- etat = 0;
- TCNT1 = 115; //(65535L - ((20L*14745600L)/(1024L*1000L))); // LE PASSER EN COMPARATEUR.
+ clk = 0;
+ TCNT1 = 350; //(65535L - ((20L*14745600L)/(1024L*1000L))); // LE PASSER EN COMPARATEUR.
if(temp_sens != sens)
{
- temp_sens = sens;
-// if(continu == 1) renvoi_RS232(); // nom de la fonction qui renvoie la valeur
+ temp_sens = sens; // permet de savoir quand on a fini un tour
}
-// if(buffer_serie != 0) callback_RS232();
TIMSK |= 0x04;
+ if(mesure == 1)
+ {
+ tableau_longueur[2]=tableau_longueur[1];
+ tableau_longueur[1]=tableau_longueur[0];
+ tableau_longueur[0]=mesurer();
+ if(tableau_longueur[0] > SEUIL && tableau_longueur[1] > SEUIL && tableau_longueur[2] > SEUIL)
+ {
+ proto_send1w ('S',tableau_longueur[0]);
+ cli ();
+ }
+// else
+// proto_send1w ('P','0');
+ TournerTourelle();
+ }
+ if(pont == 1)
+ {
+ for(compteur=0;compteur<3;compteur++)
+ {
+ adc_start (compteur); // pin selectionnee
+ while(!adc_checkf()){}
+ tableau_sharp[compteur]=adc_read();
+
+ twi_update (tableau_sharp,6); // renoie des valeurs sur le I2C
+ }
+ }
+ if(ascenseur == 1)
+ {
+ if(commande == MONTE)
+ {
+ if(capteur_haut())
+ {
+ asc_haut(vitesse_ascenseur - 10);
+ }
+ else asc_haut(vitesse_ascenseur + 2);
+ }
+ else
+ {
+ if(commande == DESCEND)
+ {
+ if(capteur_bas())
+ {
+ asc_bas(vitesse_ascenseur - 10);
+ }
+
+ else asc_bas(vitesse_ascenseur + 2);
+
+ }
+ else asc_stable(vitesse_ascenseur);
+
+ }
+ }
}
-
- if(mesure == 1)
- {
- tableau_longueur[0]=mesurer();
- if(tableau_longueur[0] > SEUIL)
- proto_send1w ('S',tableau_longueur[0]);
-// else
-// proto_send1w ('P',tableau_longueur[0]);
- }
-
- for(compteur=0;compteur<3;compteur++)
- {
- adc_start (compteur); // pin selectionnee
- while(!adc_checkf()){}
- tableau_sharp[compteur]=adc_read();
- }
-twi_update (tableau_sharp,6);
}
}
diff --git a/n/es/src/tourelle.c b/n/es/src/tourelle.c
index d906853..e2d4ba9 100644
--- a/n/es/src/tourelle.c
+++ b/n/es/src/tourelle.c
@@ -24,8 +24,8 @@
#include "tourelle.h"
#include "avr/signal.h"
-const uint8_t delayMax = 125;
-const uint8_t delayMin = 175;
+const uint8_t delayMax = 100;
+const uint8_t delayMin = 200;
const uint8_t pin_sharp = 3 ;
uint8_t delay = 0;
//extern uint16_t SEUIL = 280; // 10 cm = 2.25Vnet 80 cm = 1.75 V
@@ -42,14 +42,13 @@ const uint8_t MILIEU = 2;
uint16_t tableau_longueur[25];
extern uint8_t continu;
-
extern uint8_t etat;
-
extern uint8_t envoie;
-
extern uint8_t sens;
-
extern uint8_t mesure;
+extern uint8_t pont;
+extern uint8_t clk;
+extern uint8_t ascenseur;
uint8_t valeur_actuelle1 = 0;
uint8_t valeur_actuelle2 = 0;
@@ -89,6 +88,9 @@ void tourelle_init (uint16_t prescaler)
crenaux(delay,PORTC,7);
delay_ms(20L);
+ pont = 1;
+ ascenseur = 1;
+
rs232_putc('F');
switch(prescaler)
@@ -195,43 +197,8 @@ int16_t mesurer(void)
SIGNAL (SIG_OVERFLOW1)
{
- // on fait la mesure
- uint8_t i = 0;
- uint8_t temp = 0;
-
TIMSK &= ~(0x04);
-
-
- 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] && temp > SEUIL )
- {
- if(nombre_actuel == 0)
- {
- valeur_actuelle1 = tableau_longueur[MILIEU+1];
- angle_actuel1 = 45 + (delay - 6)*90/50;
- }
-
- if(nombre_actuel == 1)
- {
- valeur_actuelle2 = tableau_longueur[MILIEU +1];
- angle_actuel2 = 45 + (delay - 6)*90/50;
- }
-
- if(nombre_actuel > 1)
- {
-// ALARME // PROBLEME // ALLUMER LED
- }
-
- }
- */
- TournerTourelle ();
- etat = 1;
- mesure = 1;
+ clk = 1;
}