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.
Fork of Utilisatio_MX12_V2 by
main.cpp@4:0972025782f3, 2017-05-20 (annotated)
- Committer:
- R66Y
- Date:
- Sat May 20 16:16:00 2017 +0000
- Revision:
- 4:0972025782f3
- Parent:
- 2:9d280856a536
Programme d'utilisation des AX et de l'MX12 V3
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| matthieuvignon | 2:9d280856a536 | 1 | #include "all_includes.h" |
| matthieuvignon | 2:9d280856a536 | 2 | |
| matthieuvignon | 2:9d280856a536 | 3 | Timer t; |
| matthieuvignon | 2:9d280856a536 | 4 | Ticker flipper; |
| matthieuvignon | 2:9d280856a536 | 5 | |
| matthieuvignon | 2:9d280856a536 | 6 | CAN can(p30,p29); // Rx&Tx pour le CAN |
| matthieuvignon | 2:9d280856a536 | 7 | CANMessage msgRxBuffer[SIZE_FIFO]; // buffer en réception pour le CAN |
| matthieuvignon | 2:9d280856a536 | 8 | |
| matthieuvignon | 2:9d280856a536 | 9 | Serial pc(USBTX, USBRX); |
| matthieuvignon | 2:9d280856a536 | 10 | |
| matthieuvignon | 2:9d280856a536 | 11 | extern void gerer_turbine(unsigned char pwm_turbine); |
| matthieuvignon | 2:9d280856a536 | 12 | |
| ClementBreteau | 0:7737d7573e3b | 13 | |
| matthieuvignon | 2:9d280856a536 | 14 | PwmOut PompeDroite(p21); |
| matthieuvignon | 2:9d280856a536 | 15 | //PwmOut PompeGauche(p22); |
| matthieuvignon | 2:9d280856a536 | 16 | PwmOut MotLanceur(p22); |
| matthieuvignon | 2:9d280856a536 | 17 | PwmOut turbine(p23); |
| matthieuvignon | 2:9d280856a536 | 18 | //PwmOut ServoVanne(p21); |
| matthieuvignon | 2:9d280856a536 | 19 | |
| matthieuvignon | 2:9d280856a536 | 20 | AnalogIn telemetre(p15); |
| matthieuvignon | 2:9d280856a536 | 21 | |
| matthieuvignon | 2:9d280856a536 | 22 | DigitalIn Jack(p25); |
| matthieuvignon | 2:9d280856a536 | 23 | |
| matthieuvignon | 2:9d280856a536 | 24 | |
| matthieuvignon | 2:9d280856a536 | 25 | DigitalOut led(LED1); |
| matthieuvignon | 2:9d280856a536 | 26 | DigitalOut led2(LED2); |
| matthieuvignon | 2:9d280856a536 | 27 | |
| matthieuvignon | 2:9d280856a536 | 28 | unsigned char EtatPompeDroite=0, EtatPompeGauche=0, EtatLanceur=0, EtatAx12=0, ChoixBras=0, ActionAx12=0, EtatTurbine=0, EtatServoVanne=0; |
| matthieuvignon | 2:9d280856a536 | 29 | unsigned char action_a_effectuer=0, ActionPompe=0; |
| matthieuvignon | 2:9d280856a536 | 30 | |
| ClementBreteau | 0:7737d7573e3b | 31 | |
| ClementBreteau | 0:7737d7573e3b | 32 | /* |
| ClementBreteau | 0:7737d7573e3b | 33 | DigitalIn IO1(p23); |
| ClementBreteau | 0:7737d7573e3b | 34 | DigitalIn IO2(p24); |
| ClementBreteau | 0:7737d7573e3b | 35 | DigitalIn IO3(p25); |
| ClementBreteau | 0:7737d7573e3b | 36 | DigitalIn IO4(p26); |
| ClementBreteau | 0:7737d7573e3b | 37 | |
| ClementBreteau | 0:7737d7573e3b | 38 | AnalogIn A_in1(p15); |
| ClementBreteau | 0:7737d7573e3b | 39 | AnalogIn A_in2(p16); |
| ClementBreteau | 0:7737d7573e3b | 40 | AnalogIn A_in3(p17); |
| ClementBreteau | 0:7737d7573e3b | 41 | AnalogIn A_in4(p18); |
| ClementBreteau | 0:7737d7573e3b | 42 | AnalogIn A_in5(p19); |
| ClementBreteau | 0:7737d7573e3b | 43 | AnalogIn A_in6(p20); |
| ClementBreteau | 0:7737d7573e3b | 44 | |
| ClementBreteau | 0:7737d7573e3b | 45 | PwmOut IRL_1(p21); |
| ClementBreteau | 0:7737d7573e3b | 46 | PwmOut IRL_2(p22); |
| ClementBreteau | 0:7737d7573e3b | 47 | */ |
| ClementBreteau | 0:7737d7573e3b | 48 | |
| ClementBreteau | 1:f3f702086a30 | 49 | |
| ClementBreteau | 0:7737d7573e3b | 50 | |
| matthieuvignon | 2:9d280856a536 | 51 | |
| matthieuvignon | 2:9d280856a536 | 52 | int main() { |
| matthieuvignon | 2:9d280856a536 | 53 | |
| matthieuvignon | 2:9d280856a536 | 54 | can.frequency(1000000); // fréquence de travail 1Mbit/s |
| matthieuvignon | 2:9d280856a536 | 55 | can.attach(&canRx_ISR); // création de l'interrupt attachée à la réception sur le CAN |
| matthieuvignon | 2:9d280856a536 | 56 | |
| matthieuvignon | 2:9d280856a536 | 57 | |
| matthieuvignon | 2:9d280856a536 | 58 | // message CAN autorise a declencher l'interruption |
| matthieuvignon | 2:9d280856a536 | 59 | |
| matthieuvignon | 2:9d280856a536 | 60 | CAN2_wrFilter(POMPE_DROITE); |
| matthieuvignon | 2:9d280856a536 | 61 | CAN2_wrFilter(POMPE_GAUCHE); |
| matthieuvignon | 2:9d280856a536 | 62 | |
| matthieuvignon | 2:9d280856a536 | 63 | CAN2_wrFilter(LANCEUR); |
| matthieuvignon | 2:9d280856a536 | 64 | CAN2_wrFilter(TURBINE); |
| matthieuvignon | 2:9d280856a536 | 65 | CAN2_wrFilter(SERVOVANNE); |
| matthieuvignon | 2:9d280856a536 | 66 | CAN2_wrFilter(0x123); |
| matthieuvignon | 2:9d280856a536 | 67 | |
| matthieuvignon | 2:9d280856a536 | 68 | CAN2_wrFilter(SERVO_AX12_ACTION); |
| matthieuvignon | 2:9d280856a536 | 69 | CAN2_wrFilter(SERVO_AX12_ACK); |
| matthieuvignon | 2:9d280856a536 | 70 | CAN2_wrFilter(SERVO_AX12_END); |
| matthieuvignon | 2:9d280856a536 | 71 | CAN2_wrFilter(CHECK_AX12); |
| matthieuvignon | 2:9d280856a536 | 72 | |
| matthieuvignon | 2:9d280856a536 | 73 | initialisation_AX12(); |
| matthieuvignon | 2:9d280856a536 | 74 | |
| matthieuvignon | 2:9d280856a536 | 75 | PompeDroite.period(0.001); |
| matthieuvignon | 2:9d280856a536 | 76 | //PompeGauche.period(0.001); |
| matthieuvignon | 2:9d280856a536 | 77 | MotLanceur.period(0.001); |
| matthieuvignon | 2:9d280856a536 | 78 | // ServoVanne.period(0.001); |
| matthieuvignon | 2:9d280856a536 | 79 | |
| matthieuvignon | 2:9d280856a536 | 80 | |
| matthieuvignon | 2:9d280856a536 | 81 | while(1) { |
| matthieuvignon | 2:9d280856a536 | 82 | led = !led; |
| matthieuvignon | 2:9d280856a536 | 83 | canProcessRx();//Traitement des trames CAN en attente |
| matthieuvignon | 2:9d280856a536 | 84 | |
| matthieuvignon | 2:9d280856a536 | 85 | |
| matthieuvignon | 2:9d280856a536 | 86 | if (action_a_effectuer==1) { |
| matthieuvignon | 2:9d280856a536 | 87 | |
| matthieuvignon | 2:9d280856a536 | 88 | action_a_effectuer=0; |
| matthieuvignon | 2:9d280856a536 | 89 | |
| matthieuvignon | 2:9d280856a536 | 90 | if (ActionAx12==1){ |
| matthieuvignon | 2:9d280856a536 | 91 | AX12_automate(EtatAx12, ChoixBras); |
| matthieuvignon | 2:9d280856a536 | 92 | ActionAx12=0; |
| matthieuvignon | 2:9d280856a536 | 93 | } |
| matthieuvignon | 2:9d280856a536 | 94 | |
| matthieuvignon | 2:9d280856a536 | 95 | if ((EtatPompeDroite==1)&&(ActionPompe==1)) |
| matthieuvignon | 2:9d280856a536 | 96 | ActionPompe=0, PompeDroite.write(1); |
| matthieuvignon | 2:9d280856a536 | 97 | else if ((EtatPompeDroite==0)&&(ActionPompe==1)) |
| matthieuvignon | 2:9d280856a536 | 98 | PompeDroite.write(0), ActionPompe=0; |
| matthieuvignon | 2:9d280856a536 | 99 | |
| matthieuvignon | 2:9d280856a536 | 100 | /* |
| matthieuvignon | 2:9d280856a536 | 101 | if (EtatPompeGauche==1) |
| matthieuvignon | 2:9d280856a536 | 102 | PompeGauche.write(1); |
| matthieuvignon | 2:9d280856a536 | 103 | else if (EtatPompeGauche==0) |
| matthieuvignon | 2:9d280856a536 | 104 | PompeGauche.write(0); |
| matthieuvignon | 2:9d280856a536 | 105 | */ |
| matthieuvignon | 2:9d280856a536 | 106 | |
| matthieuvignon | 2:9d280856a536 | 107 | if (EtatTurbine==1) |
| matthieuvignon | 2:9d280856a536 | 108 | gerer_turbine(20); |
| matthieuvignon | 2:9d280856a536 | 109 | else if (EtatTurbine==0) |
| matthieuvignon | 2:9d280856a536 | 110 | gerer_turbine(0); |
| matthieuvignon | 2:9d280856a536 | 111 | |
| matthieuvignon | 2:9d280856a536 | 112 | if (EtatLanceur==1) |
| matthieuvignon | 2:9d280856a536 | 113 | MotLanceur.write(1); |
| matthieuvignon | 2:9d280856a536 | 114 | else if (EtatLanceur==0) |
| matthieuvignon | 2:9d280856a536 | 115 | MotLanceur.write(0); |
| matthieuvignon | 2:9d280856a536 | 116 | /* |
| matthieuvignon | 2:9d280856a536 | 117 | if (EtatServoVanne==1) |
| matthieuvignon | 2:9d280856a536 | 118 | ServoVanne.write(0.4); |
| matthieuvignon | 2:9d280856a536 | 119 | if (EtatServoVanne==0) |
| matthieuvignon | 2:9d280856a536 | 120 | ServoVanne.write(0); |
| matthieuvignon | 2:9d280856a536 | 121 | */ |
| matthieuvignon | 2:9d280856a536 | 122 | } |
| matthieuvignon | 2:9d280856a536 | 123 | |
| ClementBreteau | 0:7737d7573e3b | 124 | } |
| ClementBreteau | 0:7737d7573e3b | 125 | } |
| ClementBreteau | 0:7737d7573e3b | 126 |
