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 freescal_cup_k22f
source/main.cpp@22:b5a3688e144b, 2015-01-17 (annotated)
- Committer:
- RobinN7
- Date:
- Sat Jan 17 18:06:33 2015 +0000
- Revision:
- 22:b5a3688e144b
- Parent:
- 21:9430357e777c
- Child:
- 23:fa834aa184e0
d?riv?e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobinN7 | 0:3af30bfbc3e5 | 1 | |
RobinN7 | 0:3af30bfbc3e5 | 2 | //Bibliothéque |
RobinN7 | 0:3af30bfbc3e5 | 3 | #include "mbed.h" |
RobinN7 | 0:3af30bfbc3e5 | 4 | #include "QEI.h" |
RobinN7 | 0:3af30bfbc3e5 | 5 | #include "Gestion_Moteur.h" |
RobinN7 | 0:3af30bfbc3e5 | 6 | #include "Camera.h" |
RobinN7 | 0:3af30bfbc3e5 | 7 | #include "Servo.h" |
RobinN7 | 0:3af30bfbc3e5 | 8 | |
RobinN7 | 0:3af30bfbc3e5 | 9 | //Differents objet/variable global |
RobinN7 | 0:3af30bfbc3e5 | 10 | |
AlexandreN7 | 1:49100fa5e278 | 11 | //test de commit |
RobinN7 | 0:3af30bfbc3e5 | 12 | |
RobinN7 | 14:000be67805b2 | 13 | Serial uart(PTD3, PTD2); //xbee |
RobinN7 | 14:000be67805b2 | 14 | //Serial uart(USBTX, USBRX); //port série usb ACM0 |
RobinN7 | 0:3af30bfbc3e5 | 15 | Servo servo(PTD0); |
AlexandreN7 | 9:43c8e6d6724d | 16 | AnalogIn pot1(PTC1); |
RobinN7 | 0:3af30bfbc3e5 | 17 | |
RobinN7 | 0:3af30bfbc3e5 | 18 | int main() { |
RobinN7 | 0:3af30bfbc3e5 | 19 | // Initialisation |
RobinN7 | 0:3af30bfbc3e5 | 20 | |
RobinN7 | 0:3af30bfbc3e5 | 21 | int indexMin=0; |
RobinN7 | 21:9430357e777c | 22 | int indexMax=127; |
AlexandreN7 | 20:24ebe046ebe9 | 23 | int compteur_uart=0; |
RobinN7 | 21:9430357e777c | 24 | int max_detect1=indexMin; |
RobinN7 | 22:b5a3688e144b | 25 | int min_detect2=indexMin; |
RobinN7 | 22:b5a3688e144b | 26 | int max_detect=(max_detect1+min_detect2)/2; |
AlexandreN7 | 9:43c8e6d6724d | 27 | float Kp_servo = 0; |
RobinN7 | 0:3af30bfbc3e5 | 28 | uart.baud(115200); |
RobinN7 | 0:3af30bfbc3e5 | 29 | init_led(); |
RobinN7 | 0:3af30bfbc3e5 | 30 | |
RobinN7 | 0:3af30bfbc3e5 | 31 | // Init UART baudrate |
RobinN7 | 0:3af30bfbc3e5 | 32 | |
RobinN7 | 0:3af30bfbc3e5 | 33 | |
RobinN7 | 0:3af30bfbc3e5 | 34 | // Lancement boucle |
RobinN7 | 0:3af30bfbc3e5 | 35 | while(1){ |
RobinN7 | 0:3af30bfbc3e5 | 36 | |
RobinN7 | 0:3af30bfbc3e5 | 37 | readline(); |
RobinN7 | 22:b5a3688e144b | 38 | passebas(10); |
RobinN7 | 22:b5a3688e144b | 39 | derivation(); |
RobinN7 | 15:b77dc649e4f3 | 40 | //passebas(4); |
RobinN7 | 15:b77dc649e4f3 | 41 | |
AlexandreN7 | 20:24ebe046ebe9 | 42 | |
AlexandreN7 | 20:24ebe046ebe9 | 43 | if (compteur_uart ==50) // on envoit une trame toute les 50 acquisitions de cameras |
AlexandreN7 | 20:24ebe046ebe9 | 44 | { |
AlexandreN7 | 20:24ebe046ebe9 | 45 | uart.printf("S1");//debug START |
AlexandreN7 | 20:24ebe046ebe9 | 46 | for (int indice_pixel=0; indice_pixel<128; indice_pixel++) |
AlexandreN7 | 20:24ebe046ebe9 | 47 | { |
AlexandreN7 | 20:24ebe046ebe9 | 48 | uart.printf("%d,",pixel1[indice_pixel]); |
AlexandreN7 | 20:24ebe046ebe9 | 49 | } |
AlexandreN7 | 20:24ebe046ebe9 | 50 | uart.printf("E");//debug END |
AlexandreN7 | 20:24ebe046ebe9 | 51 | |
AlexandreN7 | 20:24ebe046ebe9 | 52 | uart.printf("S2");//debug START |
AlexandreN7 | 20:24ebe046ebe9 | 53 | for (int indice_pixel=0; indice_pixel<128; indice_pixel++) |
AlexandreN7 | 20:24ebe046ebe9 | 54 | { |
AlexandreN7 | 20:24ebe046ebe9 | 55 | uart.printf("%d,",pixel2[indice_pixel]); |
AlexandreN7 | 20:24ebe046ebe9 | 56 | } |
AlexandreN7 | 20:24ebe046ebe9 | 57 | uart.printf("E");//debug END |
AlexandreN7 | 20:24ebe046ebe9 | 58 | compteur_uart =0; |
RobinN7 | 0:3af30bfbc3e5 | 59 | } |
AlexandreN7 | 20:24ebe046ebe9 | 60 | else { |
AlexandreN7 | 20:24ebe046ebe9 | 61 | compteur_uart =compteur_uart+1; |
AlexandreN7 | 20:24ebe046ebe9 | 62 | } |
RobinN7 | 0:3af30bfbc3e5 | 63 | |
RobinN7 | 22:b5a3688e144b | 64 | max_detect1=indexMin; |
RobinN7 | 22:b5a3688e144b | 65 | min_detect2=indexMin; |
RobinN7 | 22:b5a3688e144b | 66 | |
RobinN7 | 21:9430357e777c | 67 | for (int j=indexMin; j<=indexMax; j++) |
RobinN7 | 0:3af30bfbc3e5 | 68 | { |
RobinN7 | 22:b5a3688e144b | 69 | if (pixel1[j]>pixel1[max_detect1]) |
RobinN7 | 0:3af30bfbc3e5 | 70 | { |
RobinN7 | 21:9430357e777c | 71 | max_detect1=j; |
RobinN7 | 0:3af30bfbc3e5 | 72 | } |
RobinN7 | 22:b5a3688e144b | 73 | } |
RobinN7 | 22:b5a3688e144b | 74 | for (int j=indexMin; j<=indexMax; j++) |
RobinN7 | 22:b5a3688e144b | 75 | { |
RobinN7 | 22:b5a3688e144b | 76 | if (pixel1[j]<pixel2[min_detect2]) |
RobinN7 | 21:9430357e777c | 77 | { |
RobinN7 | 22:b5a3688e144b | 78 | min_detect2=j; |
RobinN7 | 21:9430357e777c | 79 | } |
RobinN7 | 21:9430357e777c | 80 | } |
RobinN7 | 22:b5a3688e144b | 81 | max_detect=(max_detect1+min_detect2)/2; |
RobinN7 | 14:000be67805b2 | 82 | // Réduction proportionelle de la vitesse moteur si l'angle du servo augmente |
RobinN7 | 6:a4e49784b533 | 83 | if (max_detect>64) |
RobinN7 | 6:a4e49784b533 | 84 | { |
RobinN7 | 15:b77dc649e4f3 | 85 | consigne_moteur_1=6*(1-(max_detect-64)/150.); |
RobinN7 | 15:b77dc649e4f3 | 86 | consigne_moteur_2=6*(1-(max_detect-64)/100.); |
RobinN7 | 0:3af30bfbc3e5 | 87 | } |
RobinN7 | 6:a4e49784b533 | 88 | else |
RobinN7 | 6:a4e49784b533 | 89 | { |
RobinN7 | 15:b77dc649e4f3 | 90 | consigne_moteur_1=7*(1-(64-max_detect)/100.); |
RobinN7 | 15:b77dc649e4f3 | 91 | consigne_moteur_2=7*(1-(64-max_detect)/150.); |
RobinN7 | 6:a4e49784b533 | 92 | } |
RobinN7 | 13:61c50db20069 | 93 | // Lecture du potentiometre |
RobinN7 | 13:61c50db20069 | 94 | Kp_servo=2.0*pot1.read_u16()/65000.0; |
RobinN7 | 13:61c50db20069 | 95 | |
RobinN7 | 13:61c50db20069 | 96 | servo = Kp_servo*(double(max_detect)/128.-0.5)+0.5; |
RobinN7 | 0:3af30bfbc3e5 | 97 | |
AlexandreN7 | 12:3384196374ca | 98 | |
RobinN7 | 0:3af30bfbc3e5 | 99 | } |
RobinN7 | 0:3af30bfbc3e5 | 100 | } |
RobinN7 | 0:3af30bfbc3e5 | 101 |