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@12:3384196374ca, 2015-01-13 (annotated)
- Committer:
- AlexandreN7
- Date:
- Tue Jan 13 17:07:47 2015 +0000
- Revision:
- 12:3384196374ca
- Parent:
- 11:b00b073f05a4
- Parent:
- 6:a4e49784b533
- Child:
- 13:61c50db20069
merge final i hope
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 | |
AlexandreN7 | 9:43c8e6d6724d | 13 | //Serial uart(PTD3, PTD2); //xbee |
AlexandreN7 | 9:43c8e6d6724d | 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 | 0:3af30bfbc3e5 | 22 | int indexMax=128; |
RobinN7 | 0:3af30bfbc3e5 | 23 | int max_detect=indexMin; |
AlexandreN7 | 9:43c8e6d6724d | 24 | float Kp_servo = 0; |
RobinN7 | 0:3af30bfbc3e5 | 25 | uart.baud(115200); |
RobinN7 | 0:3af30bfbc3e5 | 26 | init_led(); |
RobinN7 | 0:3af30bfbc3e5 | 27 | |
RobinN7 | 0:3af30bfbc3e5 | 28 | // Init UART baudrate |
RobinN7 | 0:3af30bfbc3e5 | 29 | |
RobinN7 | 0:3af30bfbc3e5 | 30 | |
RobinN7 | 0:3af30bfbc3e5 | 31 | // Lancement boucle |
RobinN7 | 0:3af30bfbc3e5 | 32 | while(1){ |
RobinN7 | 0:3af30bfbc3e5 | 33 | |
RobinN7 | 0:3af30bfbc3e5 | 34 | readline(); |
RobinN7 | 0:3af30bfbc3e5 | 35 | passebas(); |
AlexandreN7 | 9:43c8e6d6724d | 36 | derivation(); |
RobinN7 | 0:3af30bfbc3e5 | 37 | |
AlexandreN7 | 8:8f886cd6a59f | 38 | uart.printf("S");//debug START |
RobinN7 | 0:3af30bfbc3e5 | 39 | for (int indice_pixel=0; indice_pixel<128; indice_pixel++) |
RobinN7 | 0:3af30bfbc3e5 | 40 | { |
RobinN7 | 0:3af30bfbc3e5 | 41 | uart.printf("%d,",pixel[indice_pixel]); |
RobinN7 | 0:3af30bfbc3e5 | 42 | } |
AlexandreN7 | 8:8f886cd6a59f | 43 | uart.printf("E");//debug END |
RobinN7 | 0:3af30bfbc3e5 | 44 | |
RobinN7 | 0:3af30bfbc3e5 | 45 | for (int j=indexMin; j<indexMax; j++) |
RobinN7 | 0:3af30bfbc3e5 | 46 | { |
RobinN7 | 0:3af30bfbc3e5 | 47 | if (pixel[j]>pixel[max_detect]) |
RobinN7 | 0:3af30bfbc3e5 | 48 | { |
RobinN7 | 0:3af30bfbc3e5 | 49 | max_detect=j; |
RobinN7 | 0:3af30bfbc3e5 | 50 | } |
RobinN7 | 6:a4e49784b533 | 51 | } |
RobinN7 | 6:a4e49784b533 | 52 | // Réduction de la vitesse moteur si l'angle du servo augmente |
RobinN7 | 6:a4e49784b533 | 53 | if (max_detect>64) |
RobinN7 | 6:a4e49784b533 | 54 | { |
RobinN7 | 6:a4e49784b533 | 55 | consigne_moteur_1=6-(max_detect-64)/20.; |
RobinN7 | 6:a4e49784b533 | 56 | consigne_moteur_2=6-(max_detect-64)/15.; |
RobinN7 | 0:3af30bfbc3e5 | 57 | } |
AlexandreN7 | 12:3384196374ca | 58 | |
RobinN7 | 0:3af30bfbc3e5 | 59 | |
RobinN7 | 0:3af30bfbc3e5 | 60 | //servo = float(min_detect-indexMin)/float(indexMax-indexMin); |
AlexandreN7 | 9:43c8e6d6724d | 61 | //lecture du potentiometre |
AlexandreN7 | 12:3384196374ca | 62 | // Kp_servo=2.0*pot1.read_u16()/65000.0; |
AlexandreN7 | 9:43c8e6d6724d | 63 | // |
AlexandreN7 | 12:3384196374ca | 64 | // servo = float(max_detect)/128.; |
AlexandreN7 | 12:3384196374ca | 65 | // servo = 1.2*(float(max_detect)/128.-0.5)+0.5; |
RobinN7 | 0:3af30bfbc3e5 | 66 | |
AlexandreN7 | 11:b00b073f05a4 | 67 | // servo = 1.6*(double(max_detect)/128.-0.5)+0.5; |
AlexandreN7 | 11:b00b073f05a4 | 68 | |
AlexandreN7 | 11:b00b073f05a4 | 69 | |
RobinN7 | 0:3af30bfbc3e5 | 70 | |
RobinN7 | 6:a4e49784b533 | 71 | else |
RobinN7 | 6:a4e49784b533 | 72 | { |
RobinN7 | 6:a4e49784b533 | 73 | consigne_moteur_1=6-(64-max_detect)/15.; |
RobinN7 | 6:a4e49784b533 | 74 | consigne_moteur_2=6-(64-max_detect)/20.; |
RobinN7 | 6:a4e49784b533 | 75 | } |
RobinN7 | 6:a4e49784b533 | 76 | servo = 1.4*(double(max_detect)/128.-0.5)+0.5; |
RobinN7 | 0:3af30bfbc3e5 | 77 | |
AlexandreN7 | 12:3384196374ca | 78 | |
RobinN7 | 0:3af30bfbc3e5 | 79 | } |
RobinN7 | 0:3af30bfbc3e5 | 80 | } |
RobinN7 | 0:3af30bfbc3e5 | 81 |