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
robot_general.cpp@0:b62e5418d010, 2019-05-13 (annotated)
- Committer:
- futureCrac
- Date:
- Mon May 13 15:41:22 2019 +0000
- Revision:
- 0:b62e5418d010
- Child:
- 1:23a830355dc5
cadeau
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| futureCrac | 0:b62e5418d010 | 1 | #include "robot_general.h" |
| futureCrac | 0:b62e5418d010 | 2 | |
| futureCrac | 0:b62e5418d010 | 3 | DigitalIn Daniels_in(PA_15); |
| futureCrac | 0:b62e5418d010 | 4 | |
| futureCrac | 0:b62e5418d010 | 5 | //DigitalIn UBp(USER_BUTTON); |
| futureCrac | 0:b62e5418d010 | 6 | InterruptIn UBp_it(USER_BUTTON); |
| futureCrac | 0:b62e5418d010 | 7 | Timeout ubp_to; |
| futureCrac | 0:b62e5418d010 | 8 | |
| futureCrac | 0:b62e5418d010 | 9 | //Serial dbug(USBTX, USBRX, 115200); |
| futureCrac | 0:b62e5418d010 | 10 | Serial dbug(PA_0, PA_1, 38400); |
| futureCrac | 0:b62e5418d010 | 11 | |
| futureCrac | 0:b62e5418d010 | 12 | Timer timer_generale; |
| futureCrac | 0:b62e5418d010 | 13 | |
| futureCrac | 0:b62e5418d010 | 14 | int flagUBp = 0, flagDaniels = 0, match_en_cours = 0; |
| futureCrac | 0:b62e5418d010 | 15 | int flagEv = 0, flagAv = 1, flagDpl = 0, flag_auto_suiv = 0; |
| futureCrac | 0:b62e5418d010 | 16 | int sensrotation=-1; |
| futureCrac | 0:b62e5418d010 | 17 | |
| futureCrac | 0:b62e5418d010 | 18 | short pos_balle[10][4];int nb_balle = 0, balle_retrouve = 0; |
| futureCrac | 0:b62e5418d010 | 19 | |
| futureCrac | 0:b62e5418d010 | 20 | |
| futureCrac | 0:b62e5418d010 | 21 | |
| futureCrac | 0:b62e5418d010 | 22 | unsigned int temps_ecoule = 0; |
| futureCrac | 0:b62e5418d010 | 23 | |
| futureCrac | 0:b62e5418d010 | 24 | void isr_UBp();void user_bp_ar(); |
| futureCrac | 0:b62e5418d010 | 25 | |
| futureCrac | 0:b62e5418d010 | 26 | enum etat_visee_balle_T {init_visee_balle, fin_vir_rapide, debut_vir_lent, fin_vir_lent, avancer_20,debut_vir_lent2, fin_vir_lent2,avancer,rotation, lancer, fin_visee_balle, error_visee_balle, D, ED, Perdu, debut_vir_retour, fin_vir_rapide_odo,M, balle_disparue, recalage, recalage3, recalage2, retour}; |
| futureCrac | 0:b62e5418d010 | 27 | enum etat_visee_balle_T etat_visee_balle = init_visee_balle , etat_visee_balle_prec = Perdu; |
| futureCrac | 0:b62e5418d010 | 28 | int timer_visee_balle=0; |
| futureCrac | 0:b62e5418d010 | 29 | void automate_visee_balle(); |
| futureCrac | 0:b62e5418d010 | 30 | |
| futureCrac | 0:b62e5418d010 | 31 | enum etat_pied_ballon_T {init_pied_ballon_dierct, avance_x_DT_pb, rotation_ballon_x_pb, reculer_ballon_x_pb, recalage_pied_pb,fin_pied_ballon, error_pied_ballon}; |
| futureCrac | 0:b62e5418d010 | 32 | enum etat_pied_ballon_T etat_pied_ballon = init_pied_ballon_dierct , etat_pied_ballon_prec = fin_pied_ballon; |
| futureCrac | 0:b62e5418d010 | 33 | int timer_pied_ballon = 0; |
| futureCrac | 0:b62e5418d010 | 34 | void automate_pied_ballon(); |
| futureCrac | 0:b62e5418d010 | 35 | |
| futureCrac | 0:b62e5418d010 | 36 | enum etat_macro_auto_T {init_macro_auto}; |
| futureCrac | 0:b62e5418d010 | 37 | enum etat_macro_auto_T etat_macro_auto = init_macro_auto , etat_macro_auto_prec = init_macro_auto; |
| futureCrac | 0:b62e5418d010 | 38 | int timer_macro_auto = 0; |
| futureCrac | 0:b62e5418d010 | 39 | void automate_macro_auto(); |
| futureCrac | 0:b62e5418d010 | 40 | |
| futureCrac | 0:b62e5418d010 | 41 | enum etat_tirer_balle_complet_T {init_tirer_balle_complet, pied_ballon_tbc, visee_balle_tbc, fin_tirer_balle_complet, error_tirer_balle_complet}; |
| futureCrac | 0:b62e5418d010 | 42 | enum etat_tirer_balle_complet_T etat_tirer_balle_complet = init_tirer_balle_complet , etat_tirer_balle_complet_prec = init_tirer_balle_complet; |
| futureCrac | 0:b62e5418d010 | 43 | int timer_tirer_balle_complet = 0; |
| futureCrac | 0:b62e5418d010 | 44 | void automate_tirer_balle_complet(); |
| futureCrac | 0:b62e5418d010 | 45 | |
| futureCrac | 0:b62e5418d010 | 46 | enum etat_3balles_odo_T {init_tirer_balle_complet, pied_ballon_tbc, visee_balle_tbc, fin_tirer_balle_complet, error_tirer_balle_complet}; |
| futureCrac | 0:b62e5418d010 | 47 | enum etat_3balles_odo_T etat_3balles_odo = init_tirer_balle_complet , etat_3balles_odo = init_tirer_balle_complet; |
| futureCrac | 0:b62e5418d010 | 48 | int timer_3balles_odo = 0; |
| futureCrac | 0:b62e5418d010 | 49 | void automate_3balles_odo(); |
| futureCrac | 0:b62e5418d010 | 50 | |
| futureCrac | 0:b62e5418d010 | 51 | |
| futureCrac | 0:b62e5418d010 | 52 | void automate_base(); |
| futureCrac | 0:b62e5418d010 | 53 | int etat_auto = 0, etat_auto_prec = 0; |
| futureCrac | 0:b62e5418d010 | 54 | int etat_auto_base = 0, etat_auto_base_prec = 0; |
| futureCrac | 0:b62e5418d010 | 55 | |
| futureCrac | 0:b62e5418d010 | 56 | void if_UBp(); |
| futureCrac | 0:b62e5418d010 | 57 | void wait_debut_de_partie(); |
| futureCrac | 0:b62e5418d010 | 58 | |
| futureCrac | 0:b62e5418d010 | 59 | |
| futureCrac | 0:b62e5418d010 | 60 | |
| futureCrac | 0:b62e5418d010 | 61 | int main() |
| futureCrac | 0:b62e5418d010 | 62 | { |
| futureCrac | 0:b62e5418d010 | 63 | dbug.printf("\nSETUP "); |
| futureCrac | 0:b62e5418d010 | 64 | can_init(); |
| futureCrac | 0:b62e5418d010 | 65 | UBp_it.rise(&isr_UBp); |
| futureCrac | 0:b62e5418d010 | 66 | //SetOdometrie(26,500,55,0); |
| futureCrac | 0:b62e5418d010 | 67 | bonus_findepartie(0); |
| futureCrac | 0:b62e5418d010 | 68 | |
| futureCrac | 0:b62e5418d010 | 69 | cmd_servo = 0; |
| futureCrac | 0:b62e5418d010 | 70 | ejection_continue = 1; |
| futureCrac | 0:b62e5418d010 | 71 | ejection_active = 1; |
| futureCrac | 0:b62e5418d010 | 72 | temps_ecoule = 0; |
| futureCrac | 0:b62e5418d010 | 73 | match_en_cours = 0; |
| futureCrac | 0:b62e5418d010 | 74 | |
| futureCrac | 0:b62e5418d010 | 75 | //BendRadius(139, 900, -1,0); |
| futureCrac | 0:b62e5418d010 | 76 | //GoStraight(3800,0,0,0); |
| futureCrac | 0:b62e5418d010 | 77 | dbug.printf("END SETUP\n"); |
| futureCrac | 0:b62e5418d010 | 78 | while(!match_en_cours){ |
| futureCrac | 0:b62e5418d010 | 79 | trait_can(); |
| futureCrac | 0:b62e5418d010 | 80 | wait_debut_de_partie();} |
| futureCrac | 0:b62e5418d010 | 81 | |
| futureCrac | 0:b62e5418d010 | 82 | timer_generale.start(); |
| futureCrac | 0:b62e5418d010 | 83 | //Rotate(3600); |
| futureCrac | 0:b62e5418d010 | 84 | //BendRadius(139, -900, -1,0); |
| futureCrac | 0:b62e5418d010 | 85 | //while(1); |
| futureCrac | 0:b62e5418d010 | 86 | //dbug.printf("%d\n", flagDaniels); |
| futureCrac | 0:b62e5418d010 | 87 | |
| futureCrac | 0:b62e5418d010 | 88 | while(1) |
| futureCrac | 0:b62e5418d010 | 89 | { |
| futureCrac | 0:b62e5418d010 | 90 | if(temps_ecoule > DUREE_MATCH_TIC) |
| futureCrac | 0:b62e5418d010 | 91 | { |
| futureCrac | 0:b62e5418d010 | 92 | match_en_cours = 0; |
| futureCrac | 0:b62e5418d010 | 93 | SendRawId(ASSERVISSEMENT_STOP); |
| futureCrac | 0:b62e5418d010 | 94 | ejection_active = 0; |
| futureCrac | 0:b62e5418d010 | 95 | automate_ejecteur(); |
| futureCrac | 0:b62e5418d010 | 96 | wait(6); |
| futureCrac | 0:b62e5418d010 | 97 | bonus_findepartie(1); |
| futureCrac | 0:b62e5418d010 | 98 | while(1); |
| futureCrac | 0:b62e5418d010 | 99 | } |
| futureCrac | 0:b62e5418d010 | 100 | else if(timer_generale.read_us() > TIKER_GENERALE_US) |
| futureCrac | 0:b62e5418d010 | 101 | {timer_generale.reset();temps_ecoule++; |
| futureCrac | 0:b62e5418d010 | 102 | trait_can(); |
| futureCrac | 0:b62e5418d010 | 103 | f_mesure(); |
| futureCrac | 0:b62e5418d010 | 104 | pos_disquette(); |
| futureCrac | 0:b62e5418d010 | 105 | |
| futureCrac | 0:b62e5418d010 | 106 | //if_UBp(); |
| futureCrac | 0:b62e5418d010 | 107 | //automate_base(); |
| futureCrac | 0:b62e5418d010 | 108 | automate_pied_ballon(); |
| futureCrac | 0:b62e5418d010 | 109 | automate_visee_balle(); |
| futureCrac | 0:b62e5418d010 | 110 | |
| futureCrac | 0:b62e5418d010 | 111 | automate_ejecteur(); |
| futureCrac | 0:b62e5418d010 | 112 | if(((temps_ecoule%500) == 0))// execute chaques secondes |
| futureCrac | 0:b62e5418d010 | 113 | { |
| futureCrac | 0:b62e5418d010 | 114 | dbug.printf("Pos x:%d, y:%d, te:%d, Tecoule:%d\n", pos[0], pos[1], pos[2],temps_ecoule*TIKER_GENERALE_US/1000000); |
| futureCrac | 0:b62e5418d010 | 115 | //dbug.printf("Dis D:%f, G:%f, min:%f\n", DTD_avg_Ex, DTG_avg_Ex, DT_avg_min_Ex); |
| futureCrac | 0:b62e5418d010 | 116 | } |
| futureCrac | 0:b62e5418d010 | 117 | } |
| futureCrac | 0:b62e5418d010 | 118 | |
| futureCrac | 0:b62e5418d010 | 119 | } |
| futureCrac | 0:b62e5418d010 | 120 | } |
| futureCrac | 0:b62e5418d010 | 121 | |
| futureCrac | 0:b62e5418d010 | 122 | void automate_macro_auto() |
| futureCrac | 0:b62e5418d010 | 123 | { |
| futureCrac | 0:b62e5418d010 | 124 | timer_macro_auto++; |
| futureCrac | 0:b62e5418d010 | 125 | switch(etat_macro_auto) |
| futureCrac | 0:b62e5418d010 | 126 | { |
| futureCrac | 0:b62e5418d010 | 127 | case init_macro_auto: |
| futureCrac | 0:b62e5418d010 | 128 | etat_macro_auto = init_macro_auto; timer_macro_auto = 0; |
| futureCrac | 0:b62e5418d010 | 129 | break; |
| futureCrac | 0:b62e5418d010 | 130 | } |
| futureCrac | 0:b62e5418d010 | 131 | } |
| futureCrac | 0:b62e5418d010 | 132 | |
| futureCrac | 0:b62e5418d010 | 133 | void automate_3balles_odo() |
| futureCrac | 0:b62e5418d010 | 134 | { |
| futureCrac | 0:b62e5418d010 | 135 | timer_3balles_odot++; |
| futureCrac | 0:b62e5418d010 | 136 | switch(etat_3balles_odo) |
| futureCrac | 0:b62e5418d010 | 137 | { |
| futureCrac | 0:b62e5418d010 | 138 | case 1: |
| futureCrac | 0:b62e5418d010 | 139 | ejection_active = 1; |
| futureCrac | 0:b62e5418d010 | 140 | ejection_continue = 1; |
| futureCrac | 0:b62e5418d010 | 141 | GoStraight(1805,0,0,0); |
| futureCrac | 0:b62e5418d010 | 142 | etat_3balles_odo = 2; timer_3balles_odot = 0; |
| futureCrac | 0:b62e5418d010 | 143 | break; |
| futureCrac | 0:b62e5418d010 | 144 | |
| futureCrac | 0:b62e5418d010 | 145 | case 2 : |
| futureCrac | 0:b62e5418d010 | 146 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 147 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 148 | flagDaniels = 1; |
| futureCrac | 0:b62e5418d010 | 149 | Rotate(-930);//rotation acoté de la balle |
| futureCrac | 0:b62e5418d010 | 150 | etat_3balles_odo = pied_ballon_tbc; timer_3balles_odot = 0; |
| futureCrac | 0:b62e5418d010 | 151 | }else if(timer_3balles_odot>TIMEOUT_ERROR_TIC) etat_3balles_odo = 10; |
| futureCrac | 0:b62e5418d010 | 152 | break; |
| futureCrac | 0:b62e5418d010 | 153 | |
| futureCrac | 0:b62e5418d010 | 154 | case 3 : |
| futureCrac | 0:b62e5418d010 | 155 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 156 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 157 | ejection_continue = 0; |
| futureCrac | 0:b62e5418d010 | 158 | GoStraight(1500,0,0,0);//on va vers la deuxieme balle |
| futureCrac | 0:b62e5418d010 | 159 | etat_3balles_odo = 4; timer_3balles_odot = 0; |
| futureCrac | 0:b62e5418d010 | 160 | }else if(timer_3balles_odot>TIMEOUT_ERROR_TIC) etat_3balles_odo = 10; |
| futureCrac | 0:b62e5418d010 | 161 | break; |
| futureCrac | 0:b62e5418d010 | 162 | |
| futureCrac | 0:b62e5418d010 | 163 | case 4 : |
| futureCrac | 0:b62e5418d010 | 164 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 165 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 166 | Rotate(940);//deuxieme balle gobé ,on tourne |
| futureCrac | 0:b62e5418d010 | 167 | etat_3balles_odo = 5; timer_3balles_odot = 0; |
| futureCrac | 0:b62e5418d010 | 168 | }else if(timer_3balles_odot>TIMEOUT_ERROR_TIC) etat_3balles_odo = 10; |
| futureCrac | 0:b62e5418d010 | 169 | break; |
| futureCrac | 0:b62e5418d010 | 170 | |
| futureCrac | 0:b62e5418d010 | 171 | case 5 : |
| futureCrac | 0:b62e5418d010 | 172 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 173 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 174 | envoyer_balle = 1;ejection_continue = 1;//tir la deuxieme balle |
| futureCrac | 0:b62e5418d010 | 175 | flagDaniels = 1; |
| futureCrac | 0:b62e5418d010 | 176 | Rotate(-940);//ici implementer le deuxieme ciblage laser |
| futureCrac | 0:b62e5418d010 | 177 | etat_3balles_odo = 6; timer_3balles_odot = 0; |
| futureCrac | 0:b62e5418d010 | 178 | }else if(timer_3balles_odot>TIMEOUT_ERROR_TIC) etat_3balles_odo = 10; |
| futureCrac | 0:b62e5418d010 | 179 | break; |
| futureCrac | 0:b62e5418d010 | 180 | |
| futureCrac | 0:b62e5418d010 | 181 | case 6: |
| futureCrac | 0:b62e5418d010 | 182 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 183 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 184 | ejection_continue = 0; |
| futureCrac | 0:b62e5418d010 | 185 | GoStraight(1500,0,0,0); |
| futureCrac | 0:b62e5418d010 | 186 | etat_3balles_odo = 7; timer_3balles_odot = 0; |
| futureCrac | 0:b62e5418d010 | 187 | }else if(timer_3balles_odot>TIMEOUT_ERROR_TIC) etat_3balles_odo = 10; |
| futureCrac | 0:b62e5418d010 | 188 | break; |
| futureCrac | 0:b62e5418d010 | 189 | |
| futureCrac | 0:b62e5418d010 | 190 | case 7: |
| futureCrac | 0:b62e5418d010 | 191 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 192 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 193 | Rotate(930); |
| futureCrac | 0:b62e5418d010 | 194 | etat_3balles_odo = 8; timer_3balles_odot = 0; |
| futureCrac | 0:b62e5418d010 | 195 | }else if(timer_3balles_odot>TIMEOUT_ERROR_TIC) etat_3balles_odo = 10; |
| futureCrac | 0:b62e5418d010 | 196 | break; |
| futureCrac | 0:b62e5418d010 | 197 | |
| futureCrac | 0:b62e5418d010 | 198 | case 8: |
| futureCrac | 0:b62e5418d010 | 199 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 200 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 201 | envoyer_balle = 1;ejection_continue = 1;//envoie de la troisième balle |
| futureCrac | 0:b62e5418d010 | 202 | etat_3balles_odo = 9; timer_3balles_odot = 0; |
| futureCrac | 0:b62e5418d010 | 203 | sensrotation=1;//on est a gauche sur le terrain ,donc on cible vers la droite |
| futureCrac | 0:b62e5418d010 | 204 | }else if(timer_3balles_odot>TIMEOUT_ERROR_TIC) etat_3balles_odo = 10; |
| futureCrac | 0:b62e5418d010 | 205 | break; |
| futureCrac | 0:b62e5418d010 | 206 | |
| futureCrac | 0:b62e5418d010 | 207 | case 9: |
| futureCrac | 0:b62e5418d010 | 208 | break; |
| futureCrac | 0:b62e5418d010 | 209 | |
| futureCrac | 0:b62e5418d010 | 210 | case 10: |
| futureCrac | 0:b62e5418d010 | 211 | break; |
| futureCrac | 0:b62e5418d010 | 212 | } |
| futureCrac | 0:b62e5418d010 | 213 | } |
| futureCrac | 0:b62e5418d010 | 214 | |
| futureCrac | 0:b62e5418d010 | 215 | |
| futureCrac | 0:b62e5418d010 | 216 | |
| futureCrac | 0:b62e5418d010 | 217 | void automate_tirer_balle_complet() |
| futureCrac | 0:b62e5418d010 | 218 | { |
| futureCrac | 0:b62e5418d010 | 219 | timer_tirer_balle_complet++; |
| futureCrac | 0:b62e5418d010 | 220 | switch(etat_tirer_balle_complet) |
| futureCrac | 0:b62e5418d010 | 221 | { |
| futureCrac | 0:b62e5418d010 | 222 | case init_tirer_balle_complet: |
| futureCrac | 0:b62e5418d010 | 223 | sensrotation = -sensrotation; |
| futureCrac | 0:b62e5418d010 | 224 | etat_pied_ballon = init_pied_ballon_dierct; |
| futureCrac | 0:b62e5418d010 | 225 | etat_tirer_balle_complet = pied_ballon_tbc; timer_tirer_balle_complet = 0; |
| futureCrac | 0:b62e5418d010 | 226 | break; |
| futureCrac | 0:b62e5418d010 | 227 | |
| futureCrac | 0:b62e5418d010 | 228 | case pied_ballon_tbc: |
| futureCrac | 0:b62e5418d010 | 229 | automate_pied_ballon(); |
| futureCrac | 0:b62e5418d010 | 230 | if(etat_pied_ballon == fin_pied_ballon) |
| futureCrac | 0:b62e5418d010 | 231 | { |
| futureCrac | 0:b62e5418d010 | 232 | etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 233 | etat_tirer_balle_complet = visee_balle_tbc; timer_tirer_balle_complet = 0; |
| futureCrac | 0:b62e5418d010 | 234 | } |
| futureCrac | 0:b62e5418d010 | 235 | break; |
| futureCrac | 0:b62e5418d010 | 236 | |
| futureCrac | 0:b62e5418d010 | 237 | case visee_balle_tbc: |
| futureCrac | 0:b62e5418d010 | 238 | automate_visee_balle(); |
| futureCrac | 0:b62e5418d010 | 239 | if(etat_visee_balle == fin_visee_balle) |
| futureCrac | 0:b62e5418d010 | 240 | { |
| futureCrac | 0:b62e5418d010 | 241 | //etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 242 | etat_tirer_balle_complet = fin_tirer_balle_complet; timer_tirer_balle_complet = 0; |
| futureCrac | 0:b62e5418d010 | 243 | } |
| futureCrac | 0:b62e5418d010 | 244 | else if(etat_visee_balle == error_visee_balle) |
| futureCrac | 0:b62e5418d010 | 245 | { |
| futureCrac | 0:b62e5418d010 | 246 | //etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 247 | etat_tirer_balle_complet = error_tirer_balle_complet; timer_tirer_balle_complet = 0; |
| futureCrac | 0:b62e5418d010 | 248 | } |
| futureCrac | 0:b62e5418d010 | 249 | break; |
| futureCrac | 0:b62e5418d010 | 250 | |
| futureCrac | 0:b62e5418d010 | 251 | case fin_tirer_balle_complet: |
| futureCrac | 0:b62e5418d010 | 252 | break; |
| futureCrac | 0:b62e5418d010 | 253 | |
| futureCrac | 0:b62e5418d010 | 254 | case error_tirer_balle_complet: |
| futureCrac | 0:b62e5418d010 | 255 | break; |
| futureCrac | 0:b62e5418d010 | 256 | |
| futureCrac | 0:b62e5418d010 | 257 | |
| futureCrac | 0:b62e5418d010 | 258 | } |
| futureCrac | 0:b62e5418d010 | 259 | } |
| futureCrac | 0:b62e5418d010 | 260 | |
| futureCrac | 0:b62e5418d010 | 261 | void automate_pied_ballon() |
| futureCrac | 0:b62e5418d010 | 262 | { |
| futureCrac | 0:b62e5418d010 | 263 | timer_pied_ballon++; |
| futureCrac | 0:b62e5418d010 | 264 | switch(etat_pied_ballon) |
| futureCrac | 0:b62e5418d010 | 265 | { |
| futureCrac | 0:b62e5418d010 | 266 | case init_pied_ballon_dierct: |
| futureCrac | 0:b62e5418d010 | 267 | short y_temp; |
| futureCrac | 0:b62e5418d010 | 268 | if(sensrotation==1)y_temp = 300; |
| futureCrac | 0:b62e5418d010 | 269 | else y_temp = 3700; |
| futureCrac | 0:b62e5418d010 | 270 | GoToPosition(3500, y_temp, 0, 0); |
| futureCrac | 0:b62e5418d010 | 271 | etat_pied_ballon = avance_x_DT_pb; timer_pied_ballon = 0; |
| futureCrac | 0:b62e5418d010 | 272 | break; |
| futureCrac | 0:b62e5418d010 | 273 | |
| futureCrac | 0:b62e5418d010 | 274 | case avance_x_DT_pb: |
| futureCrac | 0:b62e5418d010 | 275 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 276 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 277 | GoStraight(3050-DTA_avg_Ex,0,0,0); |
| futureCrac | 0:b62e5418d010 | 278 | //SetOdometrie(26,pos[0],y_temp,sensrotation*900); |
| futureCrac | 0:b62e5418d010 | 279 | etat_pied_ballon = rotation_ballon_x_pb; timer_pied_ballon = 0; |
| futureCrac | 0:b62e5418d010 | 280 | }else if(timer_pied_ballon>TIMEOUT_ERROR_TIC) etat_pied_ballon = error_pied_ballon; |
| futureCrac | 0:b62e5418d010 | 281 | break; |
| futureCrac | 0:b62e5418d010 | 282 | |
| futureCrac | 0:b62e5418d010 | 283 | case rotation_ballon_x_pb: |
| futureCrac | 0:b62e5418d010 | 284 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 285 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 286 | if(DTA_avg_Ex<3070 && DTA_avg_Ex>3020){ |
| futureCrac | 0:b62e5418d010 | 287 | Rotate(sensrotation*900); |
| futureCrac | 0:b62e5418d010 | 288 | etat_pied_ballon = reculer_ballon_x_pb; timer_pied_ballon = 0; |
| futureCrac | 0:b62e5418d010 | 289 | } |
| futureCrac | 0:b62e5418d010 | 290 | }else if(timer_pied_ballon>TIMEOUT_ERROR_TIC) etat_pied_ballon = error_pied_ballon; |
| futureCrac | 0:b62e5418d010 | 291 | break; |
| futureCrac | 0:b62e5418d010 | 292 | |
| futureCrac | 0:b62e5418d010 | 293 | case reculer_ballon_x_pb: |
| futureCrac | 0:b62e5418d010 | 294 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 295 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 296 | GoStraight(-250,0,0,0); |
| futureCrac | 0:b62e5418d010 | 297 | etat_pied_ballon = recalage_pied_pb; timer_pied_ballon = 0; |
| futureCrac | 0:b62e5418d010 | 298 | }else if(timer_pied_ballon>TIMEOUT_ERROR_TIC) etat_pied_ballon = error_pied_ballon; |
| futureCrac | 0:b62e5418d010 | 299 | break; |
| futureCrac | 0:b62e5418d010 | 300 | |
| futureCrac | 0:b62e5418d010 | 301 | case recalage_pied_pb: |
| futureCrac | 0:b62e5418d010 | 302 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 303 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 304 | short y_temp; |
| futureCrac | 0:b62e5418d010 | 305 | if(sensrotation==1)y_temp = 55; |
| futureCrac | 0:b62e5418d010 | 306 | else y_temp = 3945; |
| futureCrac | 0:b62e5418d010 | 307 | SetOdometrie(26,3050,y_temp,sensrotation*900); |
| futureCrac | 0:b62e5418d010 | 308 | etat_pied_ballon = fin_pied_ballon; timer_pied_ballon = 0; |
| futureCrac | 0:b62e5418d010 | 309 | }else if(timer_pied_ballon>TIMEOUT_ERROR_TIC) etat_pied_ballon = error_pied_ballon; |
| futureCrac | 0:b62e5418d010 | 310 | break; |
| futureCrac | 0:b62e5418d010 | 311 | |
| futureCrac | 0:b62e5418d010 | 312 | case fin_pied_ballon: |
| futureCrac | 0:b62e5418d010 | 313 | break; |
| futureCrac | 0:b62e5418d010 | 314 | |
| futureCrac | 0:b62e5418d010 | 315 | case error_pied_ballon: |
| futureCrac | 0:b62e5418d010 | 316 | break; |
| futureCrac | 0:b62e5418d010 | 317 | } |
| futureCrac | 0:b62e5418d010 | 318 | if(etat_pied_ballon != etat_pied_ballon_prec)dbug.printf("Etat visee_balle : %d\n",etat_pied_ballon); |
| futureCrac | 0:b62e5418d010 | 319 | etat_pied_ballon_prec = etat_pied_ballon; |
| futureCrac | 0:b62e5418d010 | 320 | } |
| futureCrac | 0:b62e5418d010 | 321 | |
| futureCrac | 0:b62e5418d010 | 322 | |
| futureCrac | 0:b62e5418d010 | 323 | |
| futureCrac | 0:b62e5418d010 | 324 | void automate_visee_balle() |
| futureCrac | 0:b62e5418d010 | 325 | { |
| futureCrac | 0:b62e5418d010 | 326 | timer_visee_balle++; |
| futureCrac | 0:b62e5418d010 | 327 | |
| futureCrac | 0:b62e5418d010 | 328 | switch(etat_visee_balle) |
| futureCrac | 0:b62e5418d010 | 329 | { |
| futureCrac | 0:b62e5418d010 | 330 | case init_visee_balle ://--------------------------------------0 |
| futureCrac | 0:b62e5418d010 | 331 | SendSpeed(80, 600); |
| futureCrac | 0:b62e5418d010 | 332 | Rotate(sensrotation*900); |
| futureCrac | 0:b62e5418d010 | 333 | etat_visee_balle = fin_vir_rapide; |
| futureCrac | 0:b62e5418d010 | 334 | timer_visee_balle=0; |
| futureCrac | 0:b62e5418d010 | 335 | break; |
| futureCrac | 0:b62e5418d010 | 336 | |
| futureCrac | 0:b62e5418d010 | 337 | case fin_vir_rapide : //--------------------------------------1 |
| futureCrac | 0:b62e5418d010 | 338 | if(balleg || balled ) |
| futureCrac | 0:b62e5418d010 | 339 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 340 | dbug.printf("balle 1-----1\n"); |
| futureCrac | 0:b62e5418d010 | 341 | pos_balle[0][2] = pos[2]; |
| futureCrac | 0:b62e5418d010 | 342 | SendRawId(ASSERVISSEMENT_STOP); |
| futureCrac | 0:b62e5418d010 | 343 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 344 | etat_visee_balle = debut_vir_lent; |
| futureCrac | 0:b62e5418d010 | 345 | } else if(flagFinDpl || timer_visee_balle>TIMEOUT_ERROR_TIC) etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 346 | break; |
| futureCrac | 0:b62e5418d010 | 347 | |
| futureCrac | 0:b62e5418d010 | 348 | case debut_vir_lent://--------------------------------------2 |
| futureCrac | 0:b62e5418d010 | 349 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 350 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 351 | dbug.printf("balle 2-----2\n"); |
| futureCrac | 0:b62e5418d010 | 352 | SendSpeed(18, 300); |
| futureCrac | 0:b62e5418d010 | 353 | Rotate((pos_balle[0][2]-pos[2])*2); |
| futureCrac | 0:b62e5418d010 | 354 | etat_visee_balle = fin_vir_lent; |
| futureCrac | 0:b62e5418d010 | 355 | }else if(timer_visee_balle>TIMEOUT_ERROR_TIC) etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 356 | break; |
| futureCrac | 0:b62e5418d010 | 357 | |
| futureCrac | 0:b62e5418d010 | 358 | case balle_disparue: |
| futureCrac | 0:b62e5418d010 | 359 | break; |
| futureCrac | 0:b62e5418d010 | 360 | |
| futureCrac | 0:b62e5418d010 | 361 | case fin_vir_lent://--------------------------------------3 |
| futureCrac | 0:b62e5418d010 | 362 | if(balleg && balled) |
| futureCrac | 0:b62e5418d010 | 363 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 364 | pos_balle[0][2] = pos[2]; |
| futureCrac | 0:b62e5418d010 | 365 | SendRawId(ASSERVISSEMENT_STOP); |
| futureCrac | 0:b62e5418d010 | 366 | SendSpeed(100, 600); |
| futureCrac | 0:b62e5418d010 | 367 | if(DT_avg_min_Ex<2000)etat_visee_balle = avancer; |
| futureCrac | 0:b62e5418d010 | 368 | else etat_visee_balle = avancer_20; |
| futureCrac | 0:b62e5418d010 | 369 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 370 | }else{ |
| futureCrac | 0:b62e5418d010 | 371 | etat_visee_balle = debut_vir_lent; |
| futureCrac | 0:b62e5418d010 | 372 | flagFinDpl = 1; |
| futureCrac | 0:b62e5418d010 | 373 | } |
| futureCrac | 0:b62e5418d010 | 374 | break; |
| futureCrac | 0:b62e5418d010 | 375 | |
| futureCrac | 0:b62e5418d010 | 376 | |
| futureCrac | 0:b62e5418d010 | 377 | case avancer_20://--------------------------------------4 |
| futureCrac | 0:b62e5418d010 | 378 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 379 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 380 | GoStraight(DT_avg_min_Ex-D_ROULEAU_AXE-500,0,0,0); |
| futureCrac | 0:b62e5418d010 | 381 | etat_visee_balle = debut_vir_lent2; |
| futureCrac | 0:b62e5418d010 | 382 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 383 | }else if(timer_visee_balle>TIMEOUT_ERROR_TIC) etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 384 | break; |
| futureCrac | 0:b62e5418d010 | 385 | |
| futureCrac | 0:b62e5418d010 | 386 | case debut_vir_lent2://--------------------------------------5 |
| futureCrac | 0:b62e5418d010 | 387 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 388 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 389 | |
| futureCrac | 0:b62e5418d010 | 390 | SendSpeed(18, 300); |
| futureCrac | 0:b62e5418d010 | 391 | |
| futureCrac | 0:b62e5418d010 | 392 | if(!balleg && !balled) |
| futureCrac | 0:b62e5418d010 | 393 | { |
| futureCrac | 0:b62e5418d010 | 394 | etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 395 | } |
| futureCrac | 0:b62e5418d010 | 396 | else{ |
| futureCrac | 0:b62e5418d010 | 397 | if(!balleg && balled) |
| futureCrac | 0:b62e5418d010 | 398 | { |
| futureCrac | 0:b62e5418d010 | 399 | BendRadius(139, sensrotation*30, sensrotation,0); |
| futureCrac | 0:b62e5418d010 | 400 | etat_visee_balle = fin_vir_lent2; |
| futureCrac | 0:b62e5418d010 | 401 | } |
| futureCrac | 0:b62e5418d010 | 402 | else if(balleg && !balled) |
| futureCrac | 0:b62e5418d010 | 403 | { |
| futureCrac | 0:b62e5418d010 | 404 | BendRadius(139, 30, sensrotation,0); |
| futureCrac | 0:b62e5418d010 | 405 | etat_visee_balle = fin_vir_lent2; |
| futureCrac | 0:b62e5418d010 | 406 | } |
| futureCrac | 0:b62e5418d010 | 407 | else if(balleg && balled) |
| futureCrac | 0:b62e5418d010 | 408 | { |
| futureCrac | 0:b62e5418d010 | 409 | flagFinDpl = 1; |
| futureCrac | 0:b62e5418d010 | 410 | SendSpeed(100, 600); |
| futureCrac | 0:b62e5418d010 | 411 | etat_visee_balle = avancer; |
| futureCrac | 0:b62e5418d010 | 412 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 413 | } |
| futureCrac | 0:b62e5418d010 | 414 | } |
| futureCrac | 0:b62e5418d010 | 415 | }else if(timer_visee_balle>TIMEOUT_ERROR_TIC) etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 416 | break; |
| futureCrac | 0:b62e5418d010 | 417 | |
| futureCrac | 0:b62e5418d010 | 418 | case fin_vir_lent2://--------------------------------------6 |
| futureCrac | 0:b62e5418d010 | 419 | if(balleg && balled) |
| futureCrac | 0:b62e5418d010 | 420 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 421 | SendRawId(ASSERVISSEMENT_STOP); |
| futureCrac | 0:b62e5418d010 | 422 | SendSpeed(100, 600); |
| futureCrac | 0:b62e5418d010 | 423 | etat_visee_balle = avancer; |
| futureCrac | 0:b62e5418d010 | 424 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 425 | }else{flagFinDpl = 1; |
| futureCrac | 0:b62e5418d010 | 426 | etat_visee_balle = debut_vir_lent2; |
| futureCrac | 0:b62e5418d010 | 427 | } |
| futureCrac | 0:b62e5418d010 | 428 | break; |
| futureCrac | 0:b62e5418d010 | 429 | |
| futureCrac | 0:b62e5418d010 | 430 | |
| futureCrac | 0:b62e5418d010 | 431 | case avancer://--------------------------------------7 |
| futureCrac | 0:b62e5418d010 | 432 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 433 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 434 | ejection_continue = 0; |
| futureCrac | 0:b62e5418d010 | 435 | GoStraight(DT_avg_min_Ex-(D_ROULEAU_AXE),0,0,0); |
| futureCrac | 0:b62e5418d010 | 436 | etat_visee_balle = rotation; |
| futureCrac | 0:b62e5418d010 | 437 | } |
| futureCrac | 0:b62e5418d010 | 438 | if(timer_visee_balle>TIMEOUT_ERROR_TIC) etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 439 | break; |
| futureCrac | 0:b62e5418d010 | 440 | |
| futureCrac | 0:b62e5418d010 | 441 | case rotation://--------------------------------------8 |
| futureCrac | 0:b62e5418d010 | 442 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 443 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 444 | if(balle_gobbee) |
| futureCrac | 0:b62e5418d010 | 445 | { |
| futureCrac | 0:b62e5418d010 | 446 | short dTeta = -pos[2]; |
| futureCrac | 0:b62e5418d010 | 447 | Rotate(dTeta); |
| futureCrac | 0:b62e5418d010 | 448 | etat_visee_balle = lancer; |
| futureCrac | 0:b62e5418d010 | 449 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 450 | }else etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 451 | } |
| futureCrac | 0:b62e5418d010 | 452 | break; |
| futureCrac | 0:b62e5418d010 | 453 | |
| futureCrac | 0:b62e5418d010 | 454 | case lancer: |
| futureCrac | 0:b62e5418d010 | 455 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 456 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 457 | envoyer_balle = 1; |
| futureCrac | 0:b62e5418d010 | 458 | ejection_continue = 1; |
| futureCrac | 0:b62e5418d010 | 459 | etat_visee_balle = fin_visee_balle; |
| futureCrac | 0:b62e5418d010 | 460 | |
| futureCrac | 0:b62e5418d010 | 461 | } if(timer_visee_balle>TIMEOUT_ERROR_TIC) etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 462 | break; |
| futureCrac | 0:b62e5418d010 | 463 | |
| futureCrac | 0:b62e5418d010 | 464 | case fin_visee_balle: |
| futureCrac | 0:b62e5418d010 | 465 | ejection_continue = 1; |
| futureCrac | 0:b62e5418d010 | 466 | break; |
| futureCrac | 0:b62e5418d010 | 467 | case error_visee_balle: |
| futureCrac | 0:b62e5418d010 | 468 | ejection_continue = 1; |
| futureCrac | 0:b62e5418d010 | 469 | break; |
| futureCrac | 0:b62e5418d010 | 470 | |
| futureCrac | 0:b62e5418d010 | 471 | case retour : |
| futureCrac | 0:b62e5418d010 | 472 | GoToPosition(300, 0, 0, 0); |
| futureCrac | 0:b62e5418d010 | 473 | etat_visee_balle = recalage; |
| futureCrac | 0:b62e5418d010 | 474 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 475 | break; |
| futureCrac | 0:b62e5418d010 | 476 | |
| futureCrac | 0:b62e5418d010 | 477 | case recalage : |
| futureCrac | 0:b62e5418d010 | 478 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 479 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 480 | GoStraight(-295,0,0,0); |
| futureCrac | 0:b62e5418d010 | 481 | etat_visee_balle = recalage2; |
| futureCrac | 0:b62e5418d010 | 482 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 483 | }if(timer_visee_balle>TIMEOUT_ERROR_TIC) etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 484 | break; |
| futureCrac | 0:b62e5418d010 | 485 | case recalage2 : |
| futureCrac | 0:b62e5418d010 | 486 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 487 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 488 | GoStraight(30,2,50,0); |
| futureCrac | 0:b62e5418d010 | 489 | etat_visee_balle = recalage2; |
| futureCrac | 0:b62e5418d010 | 490 | timer_visee_balle = 0; |
| futureCrac | 0:b62e5418d010 | 491 | }if(timer_visee_balle>TIMEOUT_ERROR_TIC) etat_visee_balle = error_visee_balle; |
| futureCrac | 0:b62e5418d010 | 492 | break; |
| futureCrac | 0:b62e5418d010 | 493 | case recalage3 : |
| futureCrac | 0:b62e5418d010 | 494 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 495 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 496 | etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 497 | } |
| futureCrac | 0:b62e5418d010 | 498 | break; |
| futureCrac | 0:b62e5418d010 | 499 | } |
| futureCrac | 0:b62e5418d010 | 500 | if(etat_visee_balle != etat_visee_balle_prec)dbug.printf("Etat visee_balle : %d\n",etat_visee_balle); |
| futureCrac | 0:b62e5418d010 | 501 | etat_visee_balle_prec = etat_visee_balle; |
| futureCrac | 0:b62e5418d010 | 502 | } |
| futureCrac | 0:b62e5418d010 | 503 | |
| futureCrac | 0:b62e5418d010 | 504 | void automate_base() |
| futureCrac | 0:b62e5418d010 | 505 | { |
| futureCrac | 0:b62e5418d010 | 506 | switch(etat_auto_base) |
| futureCrac | 0:b62e5418d010 | 507 | { |
| futureCrac | 0:b62e5418d010 | 508 | case 0 : |
| futureCrac | 0:b62e5418d010 | 509 | temps_ecoule = 0; |
| futureCrac | 0:b62e5418d010 | 510 | etat_auto_base = 1; |
| futureCrac | 0:b62e5418d010 | 511 | break; |
| futureCrac | 0:b62e5418d010 | 512 | |
| futureCrac | 0:b62e5418d010 | 513 | case 1 : |
| futureCrac | 0:b62e5418d010 | 514 | ejection_active = 1; |
| futureCrac | 0:b62e5418d010 | 515 | ejection_continue = 1; |
| futureCrac | 0:b62e5418d010 | 516 | GoStraight(1805,0,0,0); |
| futureCrac | 0:b62e5418d010 | 517 | etat_auto_base=2; |
| futureCrac | 0:b62e5418d010 | 518 | break; |
| futureCrac | 0:b62e5418d010 | 519 | |
| futureCrac | 0:b62e5418d010 | 520 | case 2 : |
| futureCrac | 0:b62e5418d010 | 521 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 522 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 523 | flagDaniels = 1; |
| futureCrac | 0:b62e5418d010 | 524 | Rotate(-850);//rotation acoté de la balle |
| futureCrac | 0:b62e5418d010 | 525 | etat_auto_base=201; |
| futureCrac | 0:b62e5418d010 | 526 | |
| futureCrac | 0:b62e5418d010 | 527 | } |
| futureCrac | 0:b62e5418d010 | 528 | break; |
| futureCrac | 0:b62e5418d010 | 529 | |
| futureCrac | 0:b62e5418d010 | 530 | case 201 : |
| futureCrac | 0:b62e5418d010 | 531 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 532 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 533 | sensrotation=-1; |
| futureCrac | 0:b62e5418d010 | 534 | etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 535 | etat_auto_base=202; |
| futureCrac | 0:b62e5418d010 | 536 | } |
| futureCrac | 0:b62e5418d010 | 537 | break; |
| futureCrac | 0:b62e5418d010 | 538 | |
| futureCrac | 0:b62e5418d010 | 539 | case 202 : |
| futureCrac | 0:b62e5418d010 | 540 | automate_visee_balle(); //ciblage vers la gauche |
| futureCrac | 0:b62e5418d010 | 541 | if(etat_visee_balle == init_visee_balle)//on attend d'etre sur la balle |
| futureCrac | 0:b62e5418d010 | 542 | { |
| futureCrac | 0:b62e5418d010 | 543 | etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 544 | etat_auto_base = 3; |
| futureCrac | 0:b62e5418d010 | 545 | } |
| futureCrac | 0:b62e5418d010 | 546 | break; |
| futureCrac | 0:b62e5418d010 | 547 | //---------------------FIN--------------------------- |
| futureCrac | 0:b62e5418d010 | 548 | |
| futureCrac | 0:b62e5418d010 | 549 | case 3 : |
| futureCrac | 0:b62e5418d010 | 550 | ejection_continue = 0; |
| futureCrac | 0:b62e5418d010 | 551 | GoStraight(1500,0,0,0);//on va vers la deuxieme balle |
| futureCrac | 0:b62e5418d010 | 552 | etat_auto_base=4; |
| futureCrac | 0:b62e5418d010 | 553 | break; |
| futureCrac | 0:b62e5418d010 | 554 | |
| futureCrac | 0:b62e5418d010 | 555 | case 4 : |
| futureCrac | 0:b62e5418d010 | 556 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 557 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 558 | Rotate(900);//deuxieme balle gobé ,on tourne |
| futureCrac | 0:b62e5418d010 | 559 | etat_auto_base=5; |
| futureCrac | 0:b62e5418d010 | 560 | } |
| futureCrac | 0:b62e5418d010 | 561 | break; |
| futureCrac | 0:b62e5418d010 | 562 | |
| futureCrac | 0:b62e5418d010 | 563 | case 5 : |
| futureCrac | 0:b62e5418d010 | 564 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 565 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 566 | envoyer_balle = 1;//tir la deuxieme balle |
| futureCrac | 0:b62e5418d010 | 567 | flagDaniels = 1; |
| futureCrac | 0:b62e5418d010 | 568 | Rotate(-850);//ici implementer le deuxieme ciblage laser |
| futureCrac | 0:b62e5418d010 | 569 | etat_auto_base=601; |
| futureCrac | 0:b62e5418d010 | 570 | } |
| futureCrac | 0:b62e5418d010 | 571 | break; |
| futureCrac | 0:b62e5418d010 | 572 | |
| futureCrac | 0:b62e5418d010 | 573 | case 601 : |
| futureCrac | 0:b62e5418d010 | 574 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 575 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 576 | sensrotation=-1; |
| futureCrac | 0:b62e5418d010 | 577 | etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 578 | etat_auto_base=602; |
| futureCrac | 0:b62e5418d010 | 579 | } |
| futureCrac | 0:b62e5418d010 | 580 | break; |
| futureCrac | 0:b62e5418d010 | 581 | |
| futureCrac | 0:b62e5418d010 | 582 | case 602 : |
| futureCrac | 0:b62e5418d010 | 583 | automate_visee_balle(); //ciblage vers la gauche |
| futureCrac | 0:b62e5418d010 | 584 | if(etat_visee_balle == 4)//on attend d'etre sur la balle |
| futureCrac | 0:b62e5418d010 | 585 | { |
| futureCrac | 0:b62e5418d010 | 586 | etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 587 | etat_auto_base = 7; |
| futureCrac | 0:b62e5418d010 | 588 | } |
| futureCrac | 0:b62e5418d010 | 589 | break; |
| futureCrac | 0:b62e5418d010 | 590 | |
| futureCrac | 0:b62e5418d010 | 591 | case 7: |
| futureCrac | 0:b62e5418d010 | 592 | ejection_continue = 0; |
| futureCrac | 0:b62e5418d010 | 593 | GoStraight(1500,0,0,0); |
| futureCrac | 0:b62e5418d010 | 594 | etat_auto_base=8; |
| futureCrac | 0:b62e5418d010 | 595 | break; |
| futureCrac | 0:b62e5418d010 | 596 | |
| futureCrac | 0:b62e5418d010 | 597 | case 8 : |
| futureCrac | 0:b62e5418d010 | 598 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 599 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 600 | Rotate(900); |
| futureCrac | 0:b62e5418d010 | 601 | etat_auto_base=9; |
| futureCrac | 0:b62e5418d010 | 602 | } |
| futureCrac | 0:b62e5418d010 | 603 | break; |
| futureCrac | 0:b62e5418d010 | 604 | |
| futureCrac | 0:b62e5418d010 | 605 | case 9 : |
| futureCrac | 0:b62e5418d010 | 606 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 607 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 608 | envoyer_balle = 1;//envoie de la troisième balle |
| futureCrac | 0:b62e5418d010 | 609 | etat_auto_base=10; |
| futureCrac | 0:b62e5418d010 | 610 | sensrotation=1;//on est a gauche sur le terrain ,donc on cible vers la droite |
| futureCrac | 0:b62e5418d010 | 611 | } |
| futureCrac | 0:b62e5418d010 | 612 | break; |
| futureCrac | 0:b62e5418d010 | 613 | |
| futureCrac | 0:b62e5418d010 | 614 | case 10: |
| futureCrac | 0:b62e5418d010 | 615 | GoStraight(1500,0,0,0); |
| futureCrac | 0:b62e5418d010 | 616 | etat_auto_base=11; |
| futureCrac | 0:b62e5418d010 | 617 | break; |
| futureCrac | 0:b62e5418d010 | 618 | |
| futureCrac | 0:b62e5418d010 | 619 | case 11 : |
| futureCrac | 0:b62e5418d010 | 620 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 621 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 622 | Rotate(900); |
| futureCrac | 0:b62e5418d010 | 623 | //cmd_servo = 2; |
| futureCrac | 0:b62e5418d010 | 624 | etat_auto_base=12; |
| futureCrac | 0:b62e5418d010 | 625 | } |
| futureCrac | 0:b62e5418d010 | 626 | break; |
| futureCrac | 0:b62e5418d010 | 627 | |
| futureCrac | 0:b62e5418d010 | 628 | case 12 : |
| futureCrac | 0:b62e5418d010 | 629 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 630 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 631 | GoStraight(100,2,0,0); |
| futureCrac | 0:b62e5418d010 | 632 | cmd_servo = 2; |
| futureCrac | 0:b62e5418d010 | 633 | etat_auto_base=13; |
| futureCrac | 0:b62e5418d010 | 634 | } |
| futureCrac | 0:b62e5418d010 | 635 | break; |
| futureCrac | 0:b62e5418d010 | 636 | case 13 : |
| futureCrac | 0:b62e5418d010 | 637 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 638 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 639 | GoStraight(3800,0,0,0); |
| futureCrac | 0:b62e5418d010 | 640 | cmd_servo = 1; |
| futureCrac | 0:b62e5418d010 | 641 | etat_auto_base=14; |
| futureCrac | 0:b62e5418d010 | 642 | } |
| futureCrac | 0:b62e5418d010 | 643 | break; |
| futureCrac | 0:b62e5418d010 | 644 | |
| futureCrac | 0:b62e5418d010 | 645 | case 14 : |
| futureCrac | 0:b62e5418d010 | 646 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 647 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 648 | GoStraight(-500,0,0,0); |
| futureCrac | 0:b62e5418d010 | 649 | etat_auto_base=15; |
| futureCrac | 0:b62e5418d010 | 650 | } |
| futureCrac | 0:b62e5418d010 | 651 | break; |
| futureCrac | 0:b62e5418d010 | 652 | |
| futureCrac | 0:b62e5418d010 | 653 | case 15 : |
| futureCrac | 0:b62e5418d010 | 654 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 655 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 656 | Rotate(1800); |
| futureCrac | 0:b62e5418d010 | 657 | cmd_servo = 0; |
| futureCrac | 0:b62e5418d010 | 658 | etat_auto_base=16; |
| futureCrac | 0:b62e5418d010 | 659 | sensrotation=1; |
| futureCrac | 0:b62e5418d010 | 660 | } |
| futureCrac | 0:b62e5418d010 | 661 | break; |
| futureCrac | 0:b62e5418d010 | 662 | case 16 : |
| futureCrac | 0:b62e5418d010 | 663 | |
| futureCrac | 0:b62e5418d010 | 664 | break; |
| futureCrac | 0:b62e5418d010 | 665 | |
| futureCrac | 0:b62e5418d010 | 666 | |
| futureCrac | 0:b62e5418d010 | 667 | |
| futureCrac | 0:b62e5418d010 | 668 | case 100 : |
| futureCrac | 0:b62e5418d010 | 669 | etat_visee_balle = init_visee_balle;//On passe dans l'automate de ciblage |
| futureCrac | 0:b62e5418d010 | 670 | etat_auto_base=101; |
| futureCrac | 0:b62e5418d010 | 671 | break; |
| futureCrac | 0:b62e5418d010 | 672 | |
| futureCrac | 0:b62e5418d010 | 673 | case 101 : |
| futureCrac | 0:b62e5418d010 | 674 | automate_visee_balle(); //ciblage vers la gauche |
| futureCrac | 0:b62e5418d010 | 675 | if(etat_visee_balle == init_visee_balle)//on attend d'etre sur la balle |
| futureCrac | 0:b62e5418d010 | 676 | { |
| futureCrac | 0:b62e5418d010 | 677 | etat_visee_balle = init_visee_balle; |
| futureCrac | 0:b62e5418d010 | 678 | etat_auto_base = 102; |
| futureCrac | 0:b62e5418d010 | 679 | } |
| futureCrac | 0:b62e5418d010 | 680 | break; |
| futureCrac | 0:b62e5418d010 | 681 | |
| futureCrac | 0:b62e5418d010 | 682 | case 102 : |
| futureCrac | 0:b62e5418d010 | 683 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 684 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 685 | ejection_continue = 0; |
| futureCrac | 0:b62e5418d010 | 686 | GoStraight(DTD_avg_Ex,0,0,0); |
| futureCrac | 0:b62e5418d010 | 687 | etat_auto_base=103; |
| futureCrac | 0:b62e5418d010 | 688 | } |
| futureCrac | 0:b62e5418d010 | 689 | break; |
| futureCrac | 0:b62e5418d010 | 690 | |
| futureCrac | 0:b62e5418d010 | 691 | case 103 : |
| futureCrac | 0:b62e5418d010 | 692 | if(flagFinDpl) |
| futureCrac | 0:b62e5418d010 | 693 | {flagFinDpl = 0; |
| futureCrac | 0:b62e5418d010 | 694 | Rotate(-pos[2]); |
| futureCrac | 0:b62e5418d010 | 695 | etat_auto_base=100; |
| futureCrac | 0:b62e5418d010 | 696 | } |
| futureCrac | 0:b62e5418d010 | 697 | break; |
| futureCrac | 0:b62e5418d010 | 698 | default : |
| futureCrac | 0:b62e5418d010 | 699 | |
| futureCrac | 0:b62e5418d010 | 700 | break; |
| futureCrac | 0:b62e5418d010 | 701 | |
| futureCrac | 0:b62e5418d010 | 702 | } |
| futureCrac | 0:b62e5418d010 | 703 | if(etat_auto_base != etat_auto_base_prec)dbug.printf("Etat auto_base: %d\n",etat_auto_base); |
| futureCrac | 0:b62e5418d010 | 704 | etat_auto_base_prec = etat_auto_base; |
| futureCrac | 0:b62e5418d010 | 705 | } |
| futureCrac | 0:b62e5418d010 | 706 | |
| futureCrac | 0:b62e5418d010 | 707 | void wait_debut_de_partie() |
| futureCrac | 0:b62e5418d010 | 708 | { |
| futureCrac | 0:b62e5418d010 | 709 | if(!Daniels_in) |
| futureCrac | 0:b62e5418d010 | 710 | { |
| futureCrac | 0:b62e5418d010 | 711 | dbug.printf("-----DEBUT DE PARTIE------\n"); |
| futureCrac | 0:b62e5418d010 | 712 | match_en_cours = 1; |
| futureCrac | 0:b62e5418d010 | 713 | } |
| futureCrac | 0:b62e5418d010 | 714 | } |
| futureCrac | 0:b62e5418d010 | 715 | |
| futureCrac | 0:b62e5418d010 | 716 | void user_bp_ar(){UBp_it.enable_irq();} |
| futureCrac | 0:b62e5418d010 | 717 | void isr_UBp() |
| futureCrac | 0:b62e5418d010 | 718 | { |
| futureCrac | 0:b62e5418d010 | 719 | UBp_it.disable_irq();dbug.printf("ubp\n"); |
| futureCrac | 0:b62e5418d010 | 720 | ubp_to.attach(&user_bp_ar, 0.3); |
| futureCrac | 0:b62e5418d010 | 721 | flagUBp = 1; |
| futureCrac | 0:b62e5418d010 | 722 | } |