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@20:24ebe046ebe9, 2015-01-17 (annotated)
- Committer:
- AlexandreN7
- Date:
- Sat Jan 17 16:51:33 2015 +0000
- Revision:
- 20:24ebe046ebe9
- Parent:
- 17:31e000d82b21
- Child:
- 21:9430357e777c
apparement les deux cameras fonctionnent ...
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; |
AlexandreN7 | 20:24ebe046ebe9 | 22 | int indexMax=128; |
AlexandreN7 | 20:24ebe046ebe9 | 23 | int compteur_uart=0; |
RobinN7 | 0:3af30bfbc3e5 | 24 | int max_detect=indexMin; |
AlexandreN7 | 9:43c8e6d6724d | 25 | float Kp_servo = 0; |
RobinN7 | 0:3af30bfbc3e5 | 26 | uart.baud(115200); |
RobinN7 | 0:3af30bfbc3e5 | 27 | init_led(); |
RobinN7 | 0:3af30bfbc3e5 | 28 | |
RobinN7 | 0:3af30bfbc3e5 | 29 | // Init UART baudrate |
RobinN7 | 0:3af30bfbc3e5 | 30 | |
RobinN7 | 0:3af30bfbc3e5 | 31 | |
RobinN7 | 0:3af30bfbc3e5 | 32 | // Lancement boucle |
RobinN7 | 0:3af30bfbc3e5 | 33 | while(1){ |
RobinN7 | 0:3af30bfbc3e5 | 34 | |
RobinN7 | 0:3af30bfbc3e5 | 35 | readline(); |
AlexandreN7 | 20:24ebe046ebe9 | 36 | //passebas(12); |
AlexandreN7 | 20:24ebe046ebe9 | 37 | //derivation(); |
RobinN7 | 15:b77dc649e4f3 | 38 | //passebas(4); |
RobinN7 | 15:b77dc649e4f3 | 39 | |
AlexandreN7 | 20:24ebe046ebe9 | 40 | |
AlexandreN7 | 20:24ebe046ebe9 | 41 | if (compteur_uart ==50) // on envoit une trame toute les 50 acquisitions de cameras |
AlexandreN7 | 20:24ebe046ebe9 | 42 | { |
AlexandreN7 | 20:24ebe046ebe9 | 43 | uart.printf("S1");//debug START |
AlexandreN7 | 20:24ebe046ebe9 | 44 | for (int indice_pixel=0; indice_pixel<128; indice_pixel++) |
AlexandreN7 | 20:24ebe046ebe9 | 45 | { |
AlexandreN7 | 20:24ebe046ebe9 | 46 | uart.printf("%d,",pixel1[indice_pixel]); |
AlexandreN7 | 20:24ebe046ebe9 | 47 | } |
AlexandreN7 | 20:24ebe046ebe9 | 48 | uart.printf("E");//debug END |
AlexandreN7 | 20:24ebe046ebe9 | 49 | |
AlexandreN7 | 20:24ebe046ebe9 | 50 | uart.printf("S2");//debug START |
AlexandreN7 | 20:24ebe046ebe9 | 51 | for (int indice_pixel=0; indice_pixel<128; indice_pixel++) |
AlexandreN7 | 20:24ebe046ebe9 | 52 | { |
AlexandreN7 | 20:24ebe046ebe9 | 53 | uart.printf("%d,",pixel2[indice_pixel]); |
AlexandreN7 | 20:24ebe046ebe9 | 54 | } |
AlexandreN7 | 20:24ebe046ebe9 | 55 | uart.printf("E");//debug END |
AlexandreN7 | 20:24ebe046ebe9 | 56 | compteur_uart =0; |
RobinN7 | 0:3af30bfbc3e5 | 57 | } |
AlexandreN7 | 20:24ebe046ebe9 | 58 | else { |
AlexandreN7 | 20:24ebe046ebe9 | 59 | compteur_uart =compteur_uart+1; |
AlexandreN7 | 20:24ebe046ebe9 | 60 | } |
RobinN7 | 0:3af30bfbc3e5 | 61 | |
RobinN7 | 0:3af30bfbc3e5 | 62 | for (int j=indexMin; j<indexMax; j++) |
RobinN7 | 0:3af30bfbc3e5 | 63 | { |
AlexandreN7 | 20:24ebe046ebe9 | 64 | if (pixel1[j]>pixel1[max_detect]) |
RobinN7 | 0:3af30bfbc3e5 | 65 | { |
RobinN7 | 0:3af30bfbc3e5 | 66 | max_detect=j; |
RobinN7 | 0:3af30bfbc3e5 | 67 | } |
RobinN7 | 6:a4e49784b533 | 68 | } |
RobinN7 | 14:000be67805b2 | 69 | // Réduction proportionelle de la vitesse moteur si l'angle du servo augmente |
RobinN7 | 6:a4e49784b533 | 70 | if (max_detect>64) |
RobinN7 | 6:a4e49784b533 | 71 | { |
RobinN7 | 15:b77dc649e4f3 | 72 | consigne_moteur_1=6*(1-(max_detect-64)/150.); |
RobinN7 | 15:b77dc649e4f3 | 73 | consigne_moteur_2=6*(1-(max_detect-64)/100.); |
RobinN7 | 0:3af30bfbc3e5 | 74 | } |
RobinN7 | 6:a4e49784b533 | 75 | else |
RobinN7 | 6:a4e49784b533 | 76 | { |
RobinN7 | 15:b77dc649e4f3 | 77 | consigne_moteur_1=7*(1-(64-max_detect)/100.); |
RobinN7 | 15:b77dc649e4f3 | 78 | consigne_moteur_2=7*(1-(64-max_detect)/150.); |
RobinN7 | 6:a4e49784b533 | 79 | } |
RobinN7 | 13:61c50db20069 | 80 | // Lecture du potentiometre |
RobinN7 | 13:61c50db20069 | 81 | Kp_servo=2.0*pot1.read_u16()/65000.0; |
RobinN7 | 13:61c50db20069 | 82 | |
RobinN7 | 13:61c50db20069 | 83 | servo = Kp_servo*(double(max_detect)/128.-0.5)+0.5; |
RobinN7 | 0:3af30bfbc3e5 | 84 | |
AlexandreN7 | 12:3384196374ca | 85 | |
RobinN7 | 0:3af30bfbc3e5 | 86 | } |
RobinN7 | 0:3af30bfbc3e5 | 87 | } |
RobinN7 | 0:3af30bfbc3e5 | 88 |