
Pour les potos en galère tmtc
main.h@7:1cced6852c01, 2021-03-31 (annotated)
- Committer:
- lauric
- Date:
- Wed Mar 31 13:29:12 2021 +0000
- Revision:
- 7:1cced6852c01
ZZZZZZ; Z; Z; ZZ; Z; ; Z; Z; Z; Z; Z; Z;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lauric | 7:1cced6852c01 | 1 | // |
lauric | 7:1cced6852c01 | 2 | //////////////////////////////////////////////////////////////////////////////// |
lauric | 7:1cced6852c01 | 3 | // |
lauric | 7:1cced6852c01 | 4 | // |
lauric | 7:1cced6852c01 | 5 | // Inclusion de fichiers externes |
lauric | 7:1cced6852c01 | 6 | // |
lauric | 7:1cced6852c01 | 7 | // |
lauric | 7:1cced6852c01 | 8 | //////////////////////////////////////////////////////////////////////////////// |
lauric | 7:1cced6852c01 | 9 | // |
lauric | 7:1cced6852c01 | 10 | #include "mbed.h" //Définition Mbde |
lauric | 7:1cced6852c01 | 11 | #include "C12832.h" //Librairie du LCD |
lauric | 7:1cced6852c01 | 12 | // |
lauric | 7:1cced6852c01 | 13 | //////////////////////////////////////////////////////////////////////////////// |
lauric | 7:1cced6852c01 | 14 | // |
lauric | 7:1cced6852c01 | 15 | // |
lauric | 7:1cced6852c01 | 16 | // Déclaration de constantes |
lauric | 7:1cced6852c01 | 17 | // |
lauric | 7:1cced6852c01 | 18 | // |
lauric | 7:1cced6852c01 | 19 | //////////////////////////////////////////////////////////////////////////////// |
lauric | 7:1cced6852c01 | 20 | // |
lauric | 7:1cced6852c01 | 21 | /*pour le pilotage des LEDs RVB*/ |
lauric | 7:1cced6852c01 | 22 | #define LED_ON 0 //Définition du label led_ON |
lauric | 7:1cced6852c01 | 23 | #define LED_OFF 1 //Définition du Label led_OFF |
lauric | 7:1cced6852c01 | 24 | #define SPEED 40 // Puissance des moteurs |
lauric | 7:1cced6852c01 | 25 | // |
lauric | 7:1cced6852c01 | 26 | //////////////////////////////////////////////////////////////////////////////// |
lauric | 7:1cced6852c01 | 27 | // |
lauric | 7:1cced6852c01 | 28 | // |
lauric | 7:1cced6852c01 | 29 | // Déclaration des entrées/sorties |
lauric | 7:1cced6852c01 | 30 | // |
lauric | 7:1cced6852c01 | 31 | // |
lauric | 7:1cced6852c01 | 32 | //////////////////////////////////////////////////////////////////////////////// |
lauric | 7:1cced6852c01 | 33 | // |
lauric | 7:1cced6852c01 | 34 | Serial pc(USBTX, USBRX); //liaison série pc ou wifi |
lauric | 7:1cced6852c01 | 35 | DigitalOut LED_rouge(D5); //Led rouge |
lauric | 7:1cced6852c01 | 36 | DigitalOut LED_bleue(D8); //Led Bleue |
lauric | 7:1cced6852c01 | 37 | DigitalOut LED_verte(D9); //Led Verte |
lauric | 7:1cced6852c01 | 38 | // |
lauric | 7:1cced6852c01 | 39 | DigitalIn up(A2); //Joystick up |
lauric | 7:1cced6852c01 | 40 | DigitalIn down(A3); //Joystick down |
lauric | 7:1cced6852c01 | 41 | DigitalIn left(A4); //Joystick left |
lauric | 7:1cced6852c01 | 42 | DigitalIn right(A5); //Joystick Right |
lauric | 7:1cced6852c01 | 43 | DigitalIn fire(D4); //Joystick fire |
lauric | 7:1cced6852c01 | 44 | DigitalOut enbMot(PB_12); //Broche enable carte commande moteurs |
lauric | 7:1cced6852c01 | 45 | // |
lauric | 7:1cced6852c01 | 46 | //Moteur droit |
lauric | 7:1cced6852c01 | 47 | PwmOut sens1M1(PA_11); //PWM sens 1 moteur 1 |
lauric | 7:1cced6852c01 | 48 | PwmOut sens2M1(PB_15); //PWM sens 2 moteur 1 |
lauric | 7:1cced6852c01 | 49 | // |
lauric | 7:1cced6852c01 | 50 | //moteur gauche |
lauric | 7:1cced6852c01 | 51 | PwmOut sens1M2(PB_14); //PWM sens 1 moteur 2 |
lauric | 7:1cced6852c01 | 52 | PwmOut sens2M2(PB_13); //PWM sens 2 moteur 2 |
lauric | 7:1cced6852c01 | 53 | // |
lauric | 7:1cced6852c01 | 54 | BusIn capteursLigne(PC_9,PC_10,PC_11,PC_12,PA_12,PA_14); //6 Lignes d'entrées de liaison carte capteur |
lauric | 7:1cced6852c01 | 55 | // |
lauric | 7:1cced6852c01 | 56 | DigitalIn jack(PD_2); //Jack |
lauric | 7:1cced6852c01 | 57 | // |
lauric | 7:1cced6852c01 | 58 | DigitalIn bumpers(PB_7); //Bumpers |
lauric | 7:1cced6852c01 | 59 | // |
lauric | 7:1cced6852c01 | 60 | DigitalOut LED(PA_13); //LED rouge carte mère D1 |
lauric | 7:1cced6852c01 | 61 | // |
lauric | 7:1cced6852c01 | 62 | /*****Réservée pour ER2 **** |
lauric | 7:1cced6852c01 | 63 | ** NE PAS SUPPRIMER */ |
lauric | 7:1cced6852c01 | 64 | // |
lauric | 7:1cced6852c01 | 65 | // |
lauric | 7:1cced6852c01 | 66 | AnalogIn IR_G(PB_1); //Capteur analogique gauche |
lauric | 7:1cced6852c01 | 67 | AnalogIn IR_D(PC_2); //Capteur analogique droite |
lauric | 7:1cced6852c01 | 68 | // |
lauric | 7:1cced6852c01 | 69 | DigitalOut ir1(PC_3); //Led infra rouge 1 |
lauric | 7:1cced6852c01 | 70 | DigitalOut ir2(PC_4); //Led infra rouge 2 |
lauric | 7:1cced6852c01 | 71 | DigitalOut ir3(PC_5); //Led infra rouge 3 |
lauric | 7:1cced6852c01 | 72 | DigitalOut ir4(PC_6); //Led infra rouge 4 |
lauric | 7:1cced6852c01 | 73 | DigitalOut ir5(PC_8); //Led infra rouge 5 |
lauric | 7:1cced6852c01 | 74 | // |
lauric | 7:1cced6852c01 | 75 | C12832 lcd(D11, D13, D12, D7, D10); //Broches pour LCD définies par la librairie C12832 |
lauric | 7:1cced6852c01 | 76 | // |
lauric | 7:1cced6852c01 | 77 | AnalogIn pot1 (A0); //Potentiomètre 1 |
lauric | 7:1cced6852c01 | 78 | AnalogIn pot2 (A1); //Potentiomètre 2 |
lauric | 7:1cced6852c01 | 79 | // |
lauric | 7:1cced6852c01 | 80 | //////////////////////////////////////////////////////////////////////////////// |
lauric | 7:1cced6852c01 | 81 | // |
lauric | 7:1cced6852c01 | 82 | // Définition des prototypes des fonctions |
lauric | 7:1cced6852c01 | 83 | // |
lauric | 7:1cced6852c01 | 84 | //////////////////////////////////////////////////////////////////////////////// |
lauric | 7:1cced6852c01 | 85 | // |
lauric | 7:1cced6852c01 | 86 | Ticker sampling; //interruption pour échantillonnage |
lauric | 7:1cced6852c01 | 87 | // |
lauric | 7:1cced6852c01 | 88 | void gestionMAE(void); //gestion Machine à états primaire |
lauric | 7:1cced6852c01 | 89 | void echantillonnage(void); //fonction appelée par le ticker sampling |
lauric | 7:1cced6852c01 | 90 | void initVariateurs(void); //initialisation du variateur choisi dans main.h |
lauric | 7:1cced6852c01 | 91 | void commandeMoteurs(int moteurG, int moteurD); //les commandes sont passées en % -100 à +100 |
lauric | 7:1cced6852c01 | 92 | void lecture_cpld(void); //Lecture des signaux de la carte CPLD |
lauric | 7:1cced6852c01 | 93 | ////////////////////// |
lauric | 7:1cced6852c01 | 94 | void capter_ligne(void); |
lauric | 7:1cced6852c01 | 95 | void impulsion_moteur(void); // Appelé par le ticker |
lauric | 7:1cced6852c01 | 96 | void afficherEcran(void); // Affiche le menu |
lauric | 7:1cced6852c01 | 97 | void selection_timer(void); // Incremente la selection de la tempo quand fire est sur rising edge |
lauric | 7:1cced6852c01 | 98 | void changer_etat(void); |
lauric | 7:1cced6852c01 | 99 | |
lauric | 7:1cced6852c01 | 100 | typedef enum |
lauric | 7:1cced6852c01 | 101 | { |
lauric | 7:1cced6852c01 | 102 | RIEN = 0, |
lauric | 7:1cced6852c01 | 103 | TOUT = 8, |
lauric | 7:1cced6852c01 | 104 | PARTIEL = 4, |
lauric | 7:1cced6852c01 | 105 | }etat_capteur; |
lauric | 7:1cced6852c01 | 106 | |
lauric | 7:1cced6852c01 | 107 | // ==== VARIABLES ==== |
lauric | 7:1cced6852c01 | 108 | int moteurG = 0; // Puissance moteur gauche |
lauric | 7:1cced6852c01 | 109 | int moteurD = 0; // Puissance moteur droit |
lauric | 7:1cced6852c01 | 110 | int etat = 0; // Etat de la machine |
lauric | 7:1cced6852c01 | 111 | int selection = 0; // Selection de la tempo pour la modifier sur l'affichage |
lauric | 7:1cced6852c01 | 112 | |
lauric | 7:1cced6852c01 | 113 | bool run = true; // Sors de la boucle principale quand à false. |
lauric | 7:1cced6852c01 | 114 | |
lauric | 7:1cced6852c01 | 115 | //Temporisation, index : 0 -> Apres ligne blanche, 1 -> Rotation, 2 -> ligne droite entre 2 plots |
lauric | 7:1cced6852c01 | 116 | float timer[3] = { 1, 1, 1}; |
lauric | 7:1cced6852c01 | 117 | |
lauric | 7:1cced6852c01 | 118 | // ==== INTERRUPTIONS ==== |
lauric | 7:1cced6852c01 | 119 | InterruptIn fire_intpt(D4); // Detection interruptif sur bouton centre shield lcd |
lauric | 7:1cced6852c01 | 120 | InterruptIn jack_intpt(PD_2); // Detection du retirage du jack |
lauric | 7:1cced6852c01 | 121 | |
lauric | 7:1cced6852c01 | 122 | Timeout timeout; // Execute une fonction après un temps données |
lauric | 7:1cced6852c01 | 123 | Ticker motor_tk; // Envoi une pulsation au moteur de manière interruptif |
lauric | 7:1cced6852c01 | 124 | Ticker lcd_tk; // Met à jour l'affichage en dehors de la boucle principale car trop rapide pour l'affichage. |