summaryrefslogtreecommitdiff
path: root/n/es-2006/src
diff options
context:
space:
mode:
authorlambert2006-05-10 21:08:04 +0000
committerlambert2006-05-10 21:08:04 +0000
commit4d3ee19aec9942f5ef1ddcc2b0dd843cd50bf49a (patch)
tree2074d048a609a33c480333d98c503635349c1267 /n/es-2006/src
parenta4266f564c72cbf02266eebea6989b6cb2cbe7e7 (diff)
Premiere version du code des fonctions relatives au barillet
Todo : verifier le code, tester et etalonner les vitesses
Diffstat (limited to 'n/es-2006/src')
-rw-r--r--n/es-2006/src/Makefile2
-rw-r--r--n/es-2006/src/barillet.c289
-rw-r--r--n/es-2006/src/barillet.h44
3 files changed, 334 insertions, 1 deletions
diff --git a/n/es-2006/src/Makefile b/n/es-2006/src/Makefile
index 444347b..0c109f3 100644
--- a/n/es-2006/src/Makefile
+++ b/n/es-2006/src/Makefile
@@ -1,6 +1,6 @@
BASE = ../../avr
PROGS = es
-es_SOURCES = main.c sensor_rvb.c es_config.c
+es_SOURCES = main.c sensor_rvb.c es_config.c barillet.c
MODULES = proto uart utils
CONFIGFILE = avrconfig.h
# atmega8, atmega8535, atmega128...
diff --git a/n/es-2006/src/barillet.c b/n/es-2006/src/barillet.c
new file mode 100644
index 0000000..96aad2a
--- /dev/null
+++ b/n/es-2006/src/barillet.c
@@ -0,0 +1,289 @@
+/* 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"
+
+/* utilisation de OCR1A pour le moteur barillet
+ OCR1B pour la turbine avant
+ OCR1C pour la turbine 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 1
+ SIG_INTERRUPT4 pour la fourche barillet 2
+*/
+
+
+
+/* XXX verifier que les turbines sont en vitesse lente si inutilisé */
+/* XXX verifier que le sens de rotation du barillet est 0 si inutilisé */
+
+
+/* etat pour l'interruption fourche optique montee de balle arriere */
+#define MONTEE 0
+#define DESCENTE 1
+
+
+/* vitesse de rotation maximale du barillet */
+#define VITESSE_BAR_MAX_ 0xA0 /* XXX a etalonner */
+
+/* vitesse de rotation minimale du barillet */
+#define VITESSE_BAR_MIN_ 0x10 /* XXX a etalonner */
+
+/* vitesse de rotation maximale des turbines */
+#define VITESSE_TURB_MAX_ 0x70 /* XXX a etalonner */
+
+/* vitesse de rotation minimale des turbines */
+#define VITESSE_TURB_MIN_ 0x10 /* XXX a etalonner */
+
+/* delai d'une µs pour la carte puissance */
+#define DELAY_ 1
+
+/* compteur nombre de pas fourche barillet 1 */
+volatile uint8_t fourche_bar_1_;
+
+/* compteur nombre de pas fourche barillet 2 */
+volatile uint8_t fourche_bar_2_;
+
+/* sens de rotation du barillet */
+uint8_t sens_rotat_;
+
+/* nb de pas que le barillet doit tourner */
+uint8_t nb_pas_bar_;
+
+/* etat d'attente pour l'interruption fourche optique arriere */
+uint8_t etat_inter_ar_;
+
+/* etat de la rotation */
+uint8_t rotation_en_cours_;
+
+
+
+/* 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));
+
+ /* mode PWM = 0 */
+ OCR1A = 0; /* vitesse moteur barillet null */
+ utils_delay_ms ( DELAY_ ); /* attente d'1 µs pour la puiss_barillet */
+ // FIXME
+ // 1µs ok, mais fait pas appel à delay_ms non ?
+ // Passe aussi ton 1 en define, histoire que si tu veuilles le changer,
+ // ca ne soit pas trop galère. Voir meme une fonction inline qui
+ // appelle que le utils_delay_ms, enfin on verra après.
+
+ // FIXME
+ // il y a pas un _ à la fin ? Met en majuscule, ca sera plus
+ // simple donc.
+ OCR1B = VITESSE_TURB_MAX_; /* vitesse turb av max */
+ OCR1C = VITESSE_TURB_MIN_; /* vitesse turb ar min */
+
+ /* initialisation sens rotation */
+ PORTB &= ~_BV(4);
+
+ /* interruption autorisees INT7 INT6 INT5 INT4 sur front montant */
+ // FIXME
+ // Je pense que 0xFF c'est mieux quand même ici.
+ EICRB =
+ regv ( ISC71, ISC70, ISC61, ISC60, ISC51, ISC50, ISC41, ISC40,
+ 1, 1, 1, 1, 1, 1, 1, 1);
+
+ EIFR |= _BV(7) | _BV(6) | _BV(5) | _BV(4);
+ EIMSK |= _BV(7) | _BV(6) | _BV(5) | _BV(4);
+
+}
+
+/* fonction de rotation du barillet */
+inline void
+rotation_barillet( uint8_t nb_pas, uint8_t sens )
+{
+ if ( rotation_en_cours_ == 1 )
+ {
+ /* XXX mettre une methode pour attendre sans bloquer les interruptions */
+ /* Possibilite de le mettre dans le main, mais pb pour l'interrupt montee_balle_av sauf si on met tout dans le main et juste une variable dans l'interrupt */
+ }
+ else
+ {
+ /* initialisation pour la rotation */
+ fourche_bar_1_ = 0;
+ fourche_bar_2_ = 0;
+ nb_pas_bar_ = nb_pas;
+
+ /* affecter le bon sens de rotation */
+ if ( sens )
+ {
+ sens_rotat_ = 1;
+ utils_delay_ms ( DELAY_ ); /* XXX XXX pb si appel de la fonction dans l'une des interrupt XXX XXX */
+ }
+
+ /* tourner le barillet-les interruptions feront le reste */
+ rotation_en_cours_ = 1;
+ OCR1A = VITESSE_BAR_MAX_;
+ }
+}
+
+/* Si balle dans trou => Extraction */
+inline void
+extraction_balle(void)
+{
+ /* Ralentir la turbine avant */
+ OCR1B = VITESSE_TURB_MIN_;
+ /* Vitesse max de la turbine arriere */
+ OCR1C = VITESSE_TURB_MAX_;
+ /* attente de l'interruption */
+ etat_inter_ar_ = MONTEE;
+}
+
+
+/* deposer une balle dans un trou apres rotation */
+inline void
+depose_balle(void)
+{
+ /* vitesse turbine arriere nulle */
+ OCR1C = 0;
+ /* attente de l'interruption */
+ etat_inter_ar_ = DESCENTE;
+}
+
+
+/* interruption fourche optique turbine avant */
+SIGNAL ( SIG_INTERRUPT6 )
+{
+ /* baisser la vitesse de la turbine */
+ OCR1B = VITESSE_TURB_MIN_;
+ /* XXX attendre qu'ilm n'y ia plus d'obstacle devant le capteur */
+ /* check la fourche optique */
+
+ /* faire tourner le barillet pour voir la couleur */
+ rotation_barillet( 2, 0 );
+ /* regarder la couleur */
+// check_color /* XXX nom de la fonction a changer */
+ /* renvoyer l'info a la PC104 */
+}
+
+/* interruption fourche optique turbine arriere */
+SIGNAL ( SIG_INTERRUPT7 )
+{
+ if ( etat_inter_ar_ == MONTEE )
+ {
+ /* Ralentir la vitesse de la turbine arriere pour la rotation */
+ OCR1C = VITESSE_TURB_MIN_;
+ /* rotation du barillet pour la couleur */
+ rotation_barillet( 2, 0 );
+ }
+ else if ( etat_inter_ar_ == DESCENTE )
+ {
+ /* remettre la vitesse turbine a min */
+ OCR1C = VITESSE_TURB_MIN_;
+ /* XXX verifier que la balle ne remonte pas */
+
+ /* XXX mettre une variable pour dire : OK, on peut avancer ??*/
+ }
+}
+
+
+/* interruption fourche optique barillet 1 */
+SIGNAL ( SIG_INTERRUPT5 )
+{
+ /* XXX tester pour voir si on ralenti pas trop tard */
+ if ( ++fourche_bar_1_ == nb_pas_bar_ )
+ {
+ if ( OCR1A == VITESSE_BAR_MAX_ )
+ {
+ OCR1A = VITESSE_BAR_MIN_;
+ }
+ else if ( OCR1A == VITESSE_BAR_MIN_ )
+ {
+ OCR1A = 0;
+ if ( sens_rotat_ )
+ {
+ utils_delay_ms ( DELAY_ ); /* XXX bof bof */
+ sens_rotat_ = 0;
+ }
+ rotation_en_cours_ =0;
+ }
+ }
+}
+
+
+/* interruption fourche optique barillet 1 */
+SIGNAL ( SIG_INTERRUPT4 )
+{
+ if ( ++fourche_bar_2_ == nb_pas_bar_ )
+ {
+ if ( OCR1A == VITESSE_BAR_MAX_ )
+ {
+ OCR1A = VITESSE_BAR_MIN_;
+ }
+ else if ( OCR1A == VITESSE_BAR_MIN_ )
+ {
+ OCR1A = 0;
+ if ( sens_rotat_ == 1 )
+ {
+ utils_delay_ms ( DELAY_ ); /* XXX XXX XXX XXX */
+ sens_rotat_ = 0;
+ }
+ rotation_en_cours_ = 0;
+ }
+ }
+}
+
+
+/*Dans le main :
+ * apres extraction de balle
+ * => check couleur
+ * => remonter l'info a la PC104
+ * => rucup quelle balle on doit mettre
+ * => rotation barillet
+ * => depose_balle
+ * => on ravance
+ */
+
diff --git a/n/es-2006/src/barillet.h b/n/es-2006/src/barillet.h
new file mode 100644
index 0000000..c361397
--- /dev/null
+++ b/n/es-2006/src/barillet.h
@@ -0,0 +1,44 @@
+#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"
+
+/* fonction d'initialisation */
+void barillet_init(void);
+
+/* fonction de rotation du barillet */
+void rotation_barillet( uint8_t nb_pas, uint8_t sens );
+
+/* fonction d'extraction de balle */
+void extraction_balle(void);
+
+/* fonction pour déposer une balle dans un trou */
+void depose_balle(void);
+
+#endif
+