Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Synchronisation.cpp@0:a53b6ec3fbb3, 2016-05-30 (annotated)
- Committer:
- CS
- Date:
- Mon May 30 07:04:49 2016 +0000
- Revision:
- 0:a53b6ec3fbb3
RAZ integrale de la synchronisation
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| CS | 0:a53b6ec3fbb3 | 1 | /*******************************************************************/ |
| CS | 0:a53b6ec3fbb3 | 2 | /* */ |
| CS | 0:a53b6ec3fbb3 | 3 | /* Synchronisation */ |
| CS | 0:a53b6ec3fbb3 | 4 | /* */ |
| CS | 0:a53b6ec3fbb3 | 5 | /* Procédures de synchronisation des piles du pont Bacalan */ |
| CS | 0:a53b6ec3fbb3 | 6 | /* */ |
| CS | 0:a53b6ec3fbb3 | 7 | /* Creation : 3R MONTAUBAN */ |
| CS | 0:a53b6ec3fbb3 | 8 | /*******************************************************************/ |
| CS | 0:a53b6ec3fbb3 | 9 | |
| CS | 0:a53b6ec3fbb3 | 10 | #include "Synchronisation.h" |
| CS | 0:a53b6ec3fbb3 | 11 | |
| CS | 0:a53b6ec3fbb3 | 12 | S16 Ecart_Synchro_Avant ; |
| CS | 0:a53b6ec3fbb3 | 13 | F32 Cumul_Ecarts_Synchro_F32 ; |
| CS | 0:a53b6ec3fbb3 | 14 | F32 Correction_Synchro_F32 ; |
| CS | 0:a53b6ec3fbb3 | 15 | |
| CS | 0:a53b6ec3fbb3 | 16 | /** void vSynchro_Initialise ( void ) |
| CS | 0:a53b6ec3fbb3 | 17 | * Procédure appelée à chaque mise en route en mode automatique (synchronisé) |
| CS | 0:a53b6ec3fbb3 | 18 | */ |
| CS | 0:a53b6ec3fbb3 | 19 | void vSynchro_Initialise ( void ) |
| CS | 0:a53b6ec3fbb3 | 20 | {// Initialisation des variables de synchronisation |
| CS | 0:a53b6ec3fbb3 | 21 | Ecart_Synchro_Avant = 0 ; |
| CS | 0:a53b6ec3fbb3 | 22 | Cumul_Ecarts_Synchro_F32 = 0.0 ; |
| CS | 0:a53b6ec3fbb3 | 23 | Correction_Synchro_F32 = (F32) Correction_Synchro ; |
| CS | 0:a53b6ec3fbb3 | 24 | } |
| CS | 0:a53b6ec3fbb3 | 25 | |
| CS | 0:a53b6ec3fbb3 | 26 | void vSynchronise ( U8 Mode_Synchronisation, U8 Sens ) |
| CS | 0:a53b6ec3fbb3 | 27 | { |
| CS | 0:a53b6ec3fbb3 | 28 | F32 Correction_F32 ; |
| CS | 0:a53b6ec3fbb3 | 29 | |
| CS | 0:a53b6ec3fbb3 | 30 | switch ( Mode_Synchronisation ) |
| CS | 0:a53b6ec3fbb3 | 31 | { |
| CS | 0:a53b6ec3fbb3 | 32 | case CUSTOM : |
| CS | 0:a53b6ec3fbb3 | 33 | { |
| CS | 0:a53b6ec3fbb3 | 34 | // Ecrivez ici votre code personnalisé pour la synchronisation des piles du pont |
| CS | 0:a53b6ec3fbb3 | 35 | Consigne_Vitesse_RD = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 36 | Consigne_Vitesse_RG = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 37 | break ; |
| CS | 0:a53b6ec3fbb3 | 38 | } |
| CS | 0:a53b6ec3fbb3 | 39 | case DEUX_VITESSES : |
| CS | 0:a53b6ec3fbb3 | 40 | { |
| CS | 0:a53b6ec3fbb3 | 41 | // Calcul de l'écart de synchronisation |
| CS | 0:a53b6ec3fbb3 | 42 | Ecart_Synchronisation = ( Hauteur_RD - Hauteur_RG + Ecart_Synchro_Avant ) / 2 ; |
| CS | 0:a53b6ec3fbb3 | 43 | Ecart_Synchro_Avant = Ecart_Synchronisation ; |
| CS | 0:a53b6ec3fbb3 | 44 | |
| CS | 0:a53b6ec3fbb3 | 45 | if ( abs( Ecart_Synchronisation ) < Defaut_Mineur_Synchro ) |
| CS | 0:a53b6ec3fbb3 | 46 | {// Pas d'écart de synchronisation significatif: meme vitesse pour les 2 rives |
| CS | 0:a53b6ec3fbb3 | 47 | Consigne_Vitesse_RD = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 48 | Consigne_Vitesse_RG = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 49 | } |
| CS | 0:a53b6ec3fbb3 | 50 | |
| CS | 0:a53b6ec3fbb3 | 51 | else if ( Sens == MONTE ) |
| CS | 0:a53b6ec3fbb3 | 52 | {// Le pont monte, et l'ecart de synchronisation nécessite une correction de vitesse |
| CS | 0:a53b6ec3fbb3 | 53 | if ( Ecart_Synchronisation > Defaut_Majeur_Synchro ) |
| CS | 0:a53b6ec3fbb3 | 54 | {// Montée et Hauteur_RD > Hauteur_RG |
| CS | 0:a53b6ec3fbb3 | 55 | Consigne_Vitesse_RD = (S16)( (F32)Consigne_Vitesse_Auto * Correction_Synchro_F32 / 100.0 ) ; |
| CS | 0:a53b6ec3fbb3 | 56 | Consigne_Vitesse_RG = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 57 | } |
| CS | 0:a53b6ec3fbb3 | 58 | else if ( Ecart_Synchronisation < -Defaut_Majeur_Synchro ) |
| CS | 0:a53b6ec3fbb3 | 59 | {// Montée et Hauteur_RD < Hauteur_RG |
| CS | 0:a53b6ec3fbb3 | 60 | Consigne_Vitesse_RD = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 61 | Consigne_Vitesse_RG = (S16)( (F32)Consigne_Vitesse_Auto * Correction_Synchro_F32 / 100.0 ) ; |
| CS | 0:a53b6ec3fbb3 | 62 | } |
| CS | 0:a53b6ec3fbb3 | 63 | |
| CS | 0:a53b6ec3fbb3 | 64 | } |
| CS | 0:a53b6ec3fbb3 | 65 | else if ( Sens == DESCEND ) |
| CS | 0:a53b6ec3fbb3 | 66 | {// Le pont descend, et l'ecart de synchronisation nécessite une correction de vitesse |
| CS | 0:a53b6ec3fbb3 | 67 | if ( Ecart_Synchronisation > Defaut_Majeur_Synchro ) |
| CS | 0:a53b6ec3fbb3 | 68 | {// Descente et Hauteur_RD > Hauteur_RG |
| CS | 0:a53b6ec3fbb3 | 69 | Consigne_Vitesse_RD = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 70 | Consigne_Vitesse_RG = (S16)( (F32)Consigne_Vitesse_Auto * Correction_Synchro_F32 / 100.0 ) ; |
| CS | 0:a53b6ec3fbb3 | 71 | } |
| CS | 0:a53b6ec3fbb3 | 72 | else if ( Ecart_Synchronisation < (-Defaut_Majeur_Synchro) ) |
| CS | 0:a53b6ec3fbb3 | 73 | {// Descente et Hauteur_RD < Hauteur_RG |
| CS | 0:a53b6ec3fbb3 | 74 | Consigne_Vitesse_RD = (S16)( (F32)Consigne_Vitesse_Auto * Correction_Synchro_F32 / 100.0 ) ; |
| CS | 0:a53b6ec3fbb3 | 75 | Consigne_Vitesse_RG = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 76 | } |
| CS | 0:a53b6ec3fbb3 | 77 | } |
| CS | 0:a53b6ec3fbb3 | 78 | break ; |
| CS | 0:a53b6ec3fbb3 | 79 | } |
| CS | 0:a53b6ec3fbb3 | 80 | |
| CS | 0:a53b6ec3fbb3 | 81 | case RD_SUIT_RG : |
| CS | 0:a53b6ec3fbb3 | 82 | { |
| CS | 0:a53b6ec3fbb3 | 83 | // Calcul de l'écart de synchronisation |
| CS | 0:a53b6ec3fbb3 | 84 | if ( Sens == MONTE ) |
| CS | 0:a53b6ec3fbb3 | 85 | { |
| CS | 0:a53b6ec3fbb3 | 86 | Ecart_Synchronisation = ( Hauteur_RG - Hauteur_RD + Ecart_Synchro_Avant ) / 2 ; |
| CS | 0:a53b6ec3fbb3 | 87 | } |
| CS | 0:a53b6ec3fbb3 | 88 | else |
| CS | 0:a53b6ec3fbb3 | 89 | { |
| CS | 0:a53b6ec3fbb3 | 90 | Ecart_Synchronisation = ( Hauteur_RD - Hauteur_RG + Ecart_Synchro_Avant ) / 2 ; |
| CS | 0:a53b6ec3fbb3 | 91 | } |
| CS | 0:a53b6ec3fbb3 | 92 | Cumul_Ecarts_Synchro_F32 = Cumul_Ecarts_Synchro_F32 + (F32) Ecart_Synchronisation ; |
| CS | 0:a53b6ec3fbb3 | 93 | |
| CS | 0:a53b6ec3fbb3 | 94 | Consigne_Vitesse_RG = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 95 | |
| CS | 0:a53b6ec3fbb3 | 96 | // Anticipation |
| CS | 0:a53b6ec3fbb3 | 97 | Correction_F32 = (F32) Consigne_Vitesse_Auto * (F32) Anticipation_Synchro / 100.0 ; |
| CS | 0:a53b6ec3fbb3 | 98 | |
| CS | 0:a53b6ec3fbb3 | 99 | // Proportionnel |
| CS | 0:a53b6ec3fbb3 | 100 | Correction_F32 = Correction_F32 + (F32) KP_Synchro * (F32) Ecart_Synchronisation / 100.0 ; |
| CS | 0:a53b6ec3fbb3 | 101 | |
| CS | 0:a53b6ec3fbb3 | 102 | // Intégral |
| CS | 0:a53b6ec3fbb3 | 103 | Correction_F32 = Correction_F32 + (F32) KI_Synchro * (F32) Cumul_Ecarts_Synchro_F32 / 100.0 ; |
| CS | 0:a53b6ec3fbb3 | 104 | |
| CS | 0:a53b6ec3fbb3 | 105 | // Dérivé |
| CS | 0:a53b6ec3fbb3 | 106 | Correction_F32 = Correction_F32 + (F32) KD_Synchro * ( (F32) Ecart_Synchronisation - (F32) Ecart_Synchro_Avant ) / 100.0 ; |
| CS | 0:a53b6ec3fbb3 | 107 | |
| CS | 0:a53b6ec3fbb3 | 108 | Consigne_Vitesse_RD = (S16) Correction_F32 ; |
| CS | 0:a53b6ec3fbb3 | 109 | |
| CS | 0:a53b6ec3fbb3 | 110 | Ecart_Synchro_Avant = Ecart_Synchronisation ; |
| CS | 0:a53b6ec3fbb3 | 111 | break ; |
| CS | 0:a53b6ec3fbb3 | 112 | } |
| CS | 0:a53b6ec3fbb3 | 113 | |
| CS | 0:a53b6ec3fbb3 | 114 | case RG_SUIT_RD : |
| CS | 0:a53b6ec3fbb3 | 115 | { |
| CS | 0:a53b6ec3fbb3 | 116 | // Calcul de l'écart de synchronisation |
| CS | 0:a53b6ec3fbb3 | 117 | if ( Sens == MONTE ) |
| CS | 0:a53b6ec3fbb3 | 118 | { |
| CS | 0:a53b6ec3fbb3 | 119 | Ecart_Synchronisation = ( Hauteur_RD - Hauteur_RG + Ecart_Synchro_Avant ) / 2 ; |
| CS | 0:a53b6ec3fbb3 | 120 | } |
| CS | 0:a53b6ec3fbb3 | 121 | else |
| CS | 0:a53b6ec3fbb3 | 122 | { |
| CS | 0:a53b6ec3fbb3 | 123 | Ecart_Synchronisation = ( Hauteur_RG - Hauteur_RD + Ecart_Synchro_Avant ) / 2 ; |
| CS | 0:a53b6ec3fbb3 | 124 | } |
| CS | 0:a53b6ec3fbb3 | 125 | |
| CS | 0:a53b6ec3fbb3 | 126 | Cumul_Ecarts_Synchro_F32 = Cumul_Ecarts_Synchro_F32 + (F32) Ecart_Synchronisation ; |
| CS | 0:a53b6ec3fbb3 | 127 | |
| CS | 0:a53b6ec3fbb3 | 128 | Consigne_Vitesse_RD = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 129 | |
| CS | 0:a53b6ec3fbb3 | 130 | // Anticipation |
| CS | 0:a53b6ec3fbb3 | 131 | Correction_F32 = (F32) Consigne_Vitesse_Auto * (F32) Anticipation_Synchro / 100.0 ; |
| CS | 0:a53b6ec3fbb3 | 132 | |
| CS | 0:a53b6ec3fbb3 | 133 | // Proportionnel |
| CS | 0:a53b6ec3fbb3 | 134 | Correction_F32 = Correction_F32 + (F32) KP_Synchro * (F32) Ecart_Synchronisation / 100.0 ; |
| CS | 0:a53b6ec3fbb3 | 135 | |
| CS | 0:a53b6ec3fbb3 | 136 | // Intégral |
| CS | 0:a53b6ec3fbb3 | 137 | Correction_F32 = Correction_F32 + (F32) KI_Synchro * (F32) Cumul_Ecarts_Synchro_F32 / 100.0 ; |
| CS | 0:a53b6ec3fbb3 | 138 | |
| CS | 0:a53b6ec3fbb3 | 139 | // Dérivé |
| CS | 0:a53b6ec3fbb3 | 140 | Correction_F32 = Correction_F32 + (F32) KD_Synchro * ( (F32) Ecart_Synchronisation - (F32) Ecart_Synchro_Avant ) / 100.0 ; |
| CS | 0:a53b6ec3fbb3 | 141 | |
| CS | 0:a53b6ec3fbb3 | 142 | Consigne_Vitesse_RG = (S16) Correction_F32 ; |
| CS | 0:a53b6ec3fbb3 | 143 | |
| CS | 0:a53b6ec3fbb3 | 144 | Ecart_Synchro_Avant = Ecart_Synchronisation ; |
| CS | 0:a53b6ec3fbb3 | 145 | break ; |
| CS | 0:a53b6ec3fbb3 | 146 | } |
| CS | 0:a53b6ec3fbb3 | 147 | case AUCUN : |
| CS | 0:a53b6ec3fbb3 | 148 | default : |
| CS | 0:a53b6ec3fbb3 | 149 | { |
| CS | 0:a53b6ec3fbb3 | 150 | // Pas de correction de vitesse pour la synchronisation |
| CS | 0:a53b6ec3fbb3 | 151 | Consigne_Vitesse_RD = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 152 | Consigne_Vitesse_RG = Consigne_Vitesse_Auto ; |
| CS | 0:a53b6ec3fbb3 | 153 | } |
| CS | 0:a53b6ec3fbb3 | 154 | } |
| CS | 0:a53b6ec3fbb3 | 155 | } |