From 1b5ceef61990ef11a7015ab7a10e6a9326e478f4 Mon Sep 17 00:00:00 2001 From: lambert Date: Thu, 18 May 2006 22:19:20 +0000 Subject: * bilan : - rotation seulement d'1 sens - Le barillet s'arrete au bon endroit en vitesse medium * todo demain : - essayer d'augmenter la vitesse moteur barillet - revoir le pb de sens - revoir les vitesses de ventillo - gerer l'extraction / depot / montee avant balle --- n/es-2006/src/barillet.c | 212 +++++++++++++++++++++++++++++------------------ n/es-2006/src/main.c | 2 +- 2 files changed, 132 insertions(+), 82 deletions(-) (limited to 'n') diff --git a/n/es-2006/src/barillet.c b/n/es-2006/src/barillet.c index fd3eb20..6f0813e 100644 --- a/n/es-2006/src/barillet.c +++ b/n/es-2006/src/barillet.c @@ -55,7 +55,7 @@ /* XXX XXX passer en 16 bits */ /* vitesse de rotation maximale du barillet */ -#define VITESSE_BAR_MAX_ 0x03FF +#define VITESSE_BAR_MAX_ 0x015F /* vitesse de rotation minimale du barillet */ #define VITESSE_BAR_MIN_ 0xA0 /* XXX a etalonner */ @@ -75,24 +75,28 @@ #define BARRIERE_AVANT_ACTIVEE_ 2 #define EXTRACTION_DEPOT_ 3 #define ROTATION_BARILLET_ 4 +#define ROTATION_EN_COURS_ 5 /* varaible d'état_barillet */ -uint8_t etat_en_cours_; +volatile uint8_t etat_en_cours_; + +/*XXX XXX variable de debug pour la rotation barillet */ +volatile uint8_t pos_temp_; /* position relative au barillet */ volatile uint8_t pos_actuel_; -uint8_t pos_prec_; -uint8_t pos_final_; +volatile uint8_t pos_prec_; +volatile uint8_t pos_final_; /* etat d'attente pour l'interruption fourche optique */ -uint8_t etat_inter_ar_; /* fourche arriere */ +volatile uint8_t etat_inter_ar_; /* fourche arriere */ volatile uint8_t etat_inter_av_; /* fourche avant */ /* variable pour le delay aspiration */ volatile uint8_t compteur_timer_; /* etat de la rotation */ -uint8_t rotation_en_cours_; +volatile uint8_t rotation_en_cours_; uint8_t rotation_local_; /* position a aller pour une rotation local */ @@ -101,8 +105,9 @@ uint8_t pos_a_aller_; /* variable indiquant que la balle est en cours d'extraction */ volatile uint8_t extraire; -/* temp a la con pour initialiser la turbine avant a full pattate XXX sera mis dans le main des q ue le jack sera retirer */ -uint8_t gogogo; +/* variable gerant le pb de rebond dans les interruptions */ +volatile uint8_t rebond_inter_ar; +volatile uint8_t rebond_inter_av; /*** variable globale avec le main ***/ /* variable indiquant qu'il faut faire une extraction de balle */ @@ -179,7 +184,20 @@ barillet_init (void) /* initialisation de la position du barillet */ pos_prec_ = 0; // XXX penser a mettre le barillet avec un trou vers l'avant du robot XXX + pos_temp_ = 0; + pos_a_aller = 0; + pos_actuel_ = 0; + pos_final_ = 0; etat_en_cours_ = SLEEP_; + rotation = 0; + rotation_en_cours_ = 0; + rotation_local_ = 0; + compteur_timer_ = 0; + extraction = 0; + depot = 0; + rebond_inter_av = 0; + rebond_inter_ar = 0; + } @@ -205,20 +223,27 @@ void init_2_barillet(void) /* fonction main barillet */ void sequenceur_barillet() { - ++compteur_timer_; - if ( ( rotation_en_cours_ == 0 ) && ( rotation == 1 ) ) - { - etat_en_cours_ = ROTATION_BARILLET_; - } - else if ( ( etat_inter_av_ == MONTEE ) && ( compteur_timer_ > 5 ) ) // XXX verifier le 5, est ce suffisant ? XXX la balle est elle montee depuis longtemps ? + if ( etat_en_cours_ != SLEEP_ ) { - etat_en_cours_ = BARRIERE_AVANT_ACTIVEE_; - } - else if ( ( etat_inter_ar_ == MONTEE ) || ( etat_inter_ar_ == DESCENTE ) || ( extraction == 1) || ( depot == 1 ) ) - { - etat_en_cours_ = EXTRACTION_DEPOT_; + ++compteur_timer_; + if ( etat_en_cours_ == ROTATION_EN_COURS_ ) + { + //ne rien faire + proto_send1b ('f', pos_temp_); // affichage de pos_temp_ et pos_actuel_ + } + else if ( ( rotation_en_cours_ == 0 ) && ( rotation == 1 ) ) + { + etat_en_cours_ = ROTATION_BARILLET_; + } + else if ( ( etat_inter_av_ == MONTEE ) && ( compteur_timer_ > 5 ) ) // XXX verifier le 5, est ce suffisant ? XXX la balle est elle montee depuis longtemps ? + { + etat_en_cours_ = BARRIERE_AVANT_ACTIVEE_; + } + else if ( ( etat_inter_ar_ == MONTEE ) || ( etat_inter_ar_ == DESCENTE ) || ( extraction == 1) || ( depot == 1 ) ) + { + etat_en_cours_ = EXTRACTION_DEPOT_; + } } - switch(etat_en_cours_) { case SLEEP_ : @@ -234,6 +259,8 @@ void sequenceur_barillet() case ROTATION_BARILLET_ : rotation_barillet(pos_a_aller); break; + case ROTATION_EN_COURS_ : + break; default : break; } } @@ -251,8 +278,8 @@ void rotation_barillet( uint8_t pos_a_aller ) pos_final_ = ( pos_a_aller * 4 ); /* affecter le bon sens de rotation */ - if ( ( ( ( (40 + pos_actuel_ - pos_final_) % 40 ) >= 20 && ( pos_final_ < 20 ) ) ) || - ( ( ( (40 + pos_actuel_ - pos_final_) % 40 ) < 20 && ( pos_final_ > 20 ) ) ) ) +/* if ( ( ( ( (40 + pos_actuel_ - pos_final_) % 40 ) >= 10 && ( pos_final_ < 10 ) ) ) || + ( ( ( (40 + pos_actuel_ - pos_final_) % 40 ) < 10 && ( pos_final_ > 10 ) ) ) ) { PORTB &= ~_BV(4); utils_delay_us ( DELAY_ ); @@ -262,71 +289,75 @@ void rotation_barillet( uint8_t pos_a_aller ) PORTB |= _BV(4); utils_delay_us ( DELAY_ ); } - +*/ vitesse_turbine ( 1,VITESSE_TURB_MIN_); /* tourner le barillet */ - rotation_en_cours_ = EN_COURS; - if ( ( ( ( 40 + pos_actuel_ - pos_final_) % 40 ) < 5 ) || - ( ( ( 40 + pos_actuel_ - pos_final_) % 40 ) > 35 ) ) - { - OCR1A = VITESSE_BAR_MIN_; - } - else - { +// if ( ( ( ( 40 + pos_actuel_ - pos_final_) % 40 ) < 5 ) || +// ( ( ( 40 + pos_actuel_ - pos_final_) % 40 ) > 35 ) ) +// { +// OCR1A = VITESSE_BAR_MIN_; +// } +// else +// { OCR1A = VITESSE_BAR_MAX_; - } - etat_en_cours_ = STAND_BY_; +// } + etat_en_cours_ = ROTATION_EN_COURS_; } /* gestion de la position du barillet */ void pos_bar(void) { uint8_t pos_conc_; - uint8_t pos_temp_; +// uint8_t pos_temp_; - pos_temp_ = ( PINE >> 4) & 3; +// proto_send0('Z'); //debug interrupt + + pos_temp_ = ( PINE >> 4) & 3; // 00 00 00 XX pos_conc_ = ( pos_temp_ << 2 ) | pos_prec_; + etat_en_cours_ = ROTATION_EN_COURS_; switch ( pos_conc_ ) - { + { // actu pres case 1 : // 00 01 - --pos_actuel_; - break; - case 2 : // 00 10 - ++pos_actuel_; - break; - case 4 : // 01 00 - ++pos_actuel_; - break; case 7 : // 01 11 - --pos_actuel_; - break; case 8 : // 10 00 + case 14 : // 11 10 --pos_actuel_; + if ( pos_actuel_ < 0 ) + { + pos_actuel_ = 40 + pos_actuel_; + } break; + case 2 : // 00 10 + case 4 : // 01 00 case 11 : // 10 11 - ++pos_actuel_; - break; case 13 : // 11 01 ++pos_actuel_; + if ( pos_actuel_ == 40 ) + { + pos_actuel_ = 0; + } break; - case 14 : // 11 10 - --pos_actuel_; + default : break; } - if ( ( ( 40 + pos_actuel_ - pos_final_ ) % 40 ) == 1 ) + +// if ( ( pos_temp_ == 3 ) && ( pos_actuel_ == pos_final_ ) ) + if ( pos_actuel_ == ( pos_final_ - 2 )) // +/- { - OCR1A = VITESSE_BAR_MIN_; + OCR1A = 0; } - else if ( ( ( 40 + pos_actuel_ - pos_final_ ) % 40 ) == 0 ) + +/* if ( ( pos_actuel_ == pos_final_ ) && ( pos_actuel_ == 3 ) ) { OCR1A = 0; rotation_en_cours_ = TERMINE; rotation_local_ = TERMINE; vitesse_turbine ( 1, VITESSE_BAR_MAX_); rotation = TERMINE; + etat_en_cours_ = STAND_BY_; } - +*/ pos_prec_ = pos_temp_; } @@ -370,6 +401,8 @@ void sens(uint8_t sens_rotat) void extraction_depot(void) { + rebond_inter_av = 0; + rebond_inter_ar = 0; if ( extraction == 1 ) { if ( extraire == TERMINE ) // debut de l'extraction @@ -391,9 +424,9 @@ void extraction_depot(void) void extraction_balle(void) { /* Ralentir la turbine avant */ - vitesse_turbine( 1, VITESSE_TURB_MIN_); + vitesse_turbine( 2, VITESSE_TURB_MIN_); /* Vitesse max de la turbine arriere */ - vitesse_turbine( 2, VITESSE_TURB_MAX_); + vitesse_turbine( 1, VITESSE_TURB_MAX_); extraire = EN_COURS; } @@ -401,7 +434,7 @@ void extraction_balle(void) void extraction_fin(void) { /* Ralentir la vitesse de la turbine arriere pour la rotation */ - vitesse_turbine( 2, VITESSE_TURB_MIN_); + vitesse_turbine( 1, VITESSE_TURB_MIN_); /* fin d'extraction */ extraction = TERMINE; extraire = TERMINE; @@ -417,7 +450,7 @@ void depose_balle(void) /* attente de l'interruption */ etat_inter_ar_ = DESCENTE; /* vitesse turbine arriere nulle */ - vitesse_turbine( 1, 0); + vitesse_turbine( 2, 0); } @@ -454,50 +487,67 @@ void new_balle(void) /* interruption fourche optique turbine avant */ SIGNAL ( SIG_INTERRUPT6 ) { -/* - if(etat_en_cours_ == STAND_BY_) + if ( etat_en_cours_ != SLEEP_ ) { - etat_inter_av_ = MONTEE; - compteur_timer_ = 0; + if ( rebond_inter_av == 0 ) + { + if(etat_en_cours_ == STAND_BY_) + { + etat_inter_av_ = MONTEE; + compteur_timer_ = 0; + } + } + //proto_send0('A'); } -*/ - proto_send0('A'); } /* interruption fourche optique turbine arriere */ SIGNAL ( SIG_INTERRUPT7 ) { -#if 0 - if ( extraire == EN_COURS ) - { - etat_inter_ar_ = MONTEE; - compteur_timer_ = 0; - } - else if ( etat_inter_ar_ == DESCENTE ) + if ( etat_en_cours_ != SLEEP_ ) { - /* remettre la vitesse turbine a min */ - vitesse_turbine( 1, VITESSE_TURB_MIN_); - /* XXX verifier que la balle ne remonte pas */ - - /* XXX mettre une variable pour dire : OK, on peut avancer ??*/ + if ( rebond_inter_ar == 0 ) + { + rebond_inter_ar = 1; + if ( extraire == EN_COURS ) + { + etat_inter_ar_ = MONTEE; + compteur_timer_ = 0; + } + else if ( etat_inter_ar_ == DESCENTE ) + { + /* remettre la vitesse turbine a min */ + vitesse_turbine( 1, VITESSE_TURB_MIN_); + /* XXX verifier que la balle ne remonte pas */ + + /* XXX mettre une variable pour dire : OK, on peut avancer ??*/ + } + // sinon c'est que la barriere s'est déclanché dans un cas non voulu + //proto_send0('B'); + } } - // sinon c'est que la barriere s'est déclanché dans un cas non voulu -#endif - proto_send0('B'); } /* interruption fourche optique barillet 1 */ SIGNAL ( SIG_INTERRUPT5 ) { - pos_bar(); + //proto_send0('A'); + if ( etat_en_cours_ != SLEEP_ ) + { + pos_bar(); + } } /* interruption fourche optique barillet 1 */ SIGNAL ( SIG_INTERRUPT4 ) { - pos_bar(); + //proto_send0('B'); + if ( etat_en_cours_ != SLEEP_ ) + { + pos_bar(); + } } /* XXX XXX XXX XXX gerer pb des rebond dans les iterruptions pour les barrieres optiques */ diff --git a/n/es-2006/src/main.c b/n/es-2006/src/main.c index 22e7d3d..ceb07d9 100644 --- a/n/es-2006/src/main.c +++ b/n/es-2006/src/main.c @@ -119,7 +119,7 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) vitesse_turbine( args[0], temp_16b); break; - case c('m',1): + case c('w',1): sens(args[0]); break; -- cgit v1.2.3