Freescale_Cachan
/
Programme_course_2
programme course avec menu amélioré
Fork of Programme_course by
shield.cpp@1:000a03402c6e, 2017-02-01 (annotated)
- Committer:
- leandre
- Date:
- Wed Feb 01 13:41:24 2017 +0000
- Revision:
- 1:000a03402c6e
- Parent:
- 0:3ec7fc598e48
prog course avec menu am?lior?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Freescale_cup | 0:3ec7fc598e48 | 1 | #include "Mlib.h" |
Freescale_cup | 0:3ec7fc598e48 | 2 | |
Freescale_cup | 0:3ec7fc598e48 | 3 | /***************SHIELD*****************/ |
Freescale_cup | 0:3ec7fc598e48 | 4 | |
Freescale_cup | 0:3ec7fc598e48 | 5 | |
Freescale_cup | 0:3ec7fc598e48 | 6 | void moteurs_arriere() |
Freescale_cup | 0:3ec7fc598e48 | 7 | { |
Freescale_cup | 0:3ec7fc598e48 | 8 | vitesse_virage = new_bari/2; |
Freescale_cup | 0:3ec7fc598e48 | 9 | |
Freescale_cup | 0:3ec7fc598e48 | 10 | ajust_vitesse = (ligne_droite*5)/2; |
Freescale_cup | 0:3ec7fc598e48 | 11 | if(VIT == 0) |
Freescale_cup | 0:3ec7fc598e48 | 12 | { |
Freescale_cup | 0:3ec7fc598e48 | 13 | PWM_motor(0,0); |
Freescale_cup | 0:3ec7fc598e48 | 14 | } |
Freescale_cup | 0:3ec7fc598e48 | 15 | else if(ralentire == 1) |
Freescale_cup | 0:3ec7fc598e48 | 16 | { |
Freescale_cup | 0:3ec7fc598e48 | 17 | if(vitesse_virage > 0) |
Freescale_cup | 0:3ec7fc598e48 | 18 | { |
Freescale_cup | 0:3ec7fc598e48 | 19 | PWM_motor((VIT+ajust_vitesse) - vitesse_virage,(VIT)+ 4*vitesse_virage); |
Freescale_cup | 0:3ec7fc598e48 | 20 | } |
Freescale_cup | 0:3ec7fc598e48 | 21 | else |
Freescale_cup | 0:3ec7fc598e48 | 22 | { |
Freescale_cup | 0:3ec7fc598e48 | 23 | PWM_motor((VIT)- 4*vitesse_virage, (VIT+ajust_vitesse) + vitesse_virage); |
Freescale_cup | 0:3ec7fc598e48 | 24 | } |
Freescale_cup | 0:3ec7fc598e48 | 25 | } |
Freescale_cup | 0:3ec7fc598e48 | 26 | else |
Freescale_cup | 0:3ec7fc598e48 | 27 | { |
Freescale_cup | 0:3ec7fc598e48 | 28 | if(vitesse_virage > 0) |
Freescale_cup | 0:3ec7fc598e48 | 29 | { |
Freescale_cup | 0:3ec7fc598e48 | 30 | PWM_motor((VIT) - vitesse_virage, (VIT) + vitesse_virage); |
Freescale_cup | 0:3ec7fc598e48 | 31 | } |
Freescale_cup | 0:3ec7fc598e48 | 32 | else |
Freescale_cup | 0:3ec7fc598e48 | 33 | { |
Freescale_cup | 0:3ec7fc598e48 | 34 | PWM_motor((VIT)- vitesse_virage, (VIT) + vitesse_virage); |
Freescale_cup | 0:3ec7fc598e48 | 35 | } |
Freescale_cup | 0:3ec7fc598e48 | 36 | } |
Freescale_cup | 0:3ec7fc598e48 | 37 | |
Freescale_cup | 0:3ec7fc598e48 | 38 | } |
Freescale_cup | 0:3ec7fc598e48 | 39 | |
Freescale_cup | 0:3ec7fc598e48 | 40 | void test_servo(int time) |
Freescale_cup | 0:3ec7fc598e48 | 41 | { |
Freescale_cup | 0:3ec7fc598e48 | 42 | Timer debut_fct; |
Freescale_cup | 0:3ec7fc598e48 | 43 | debut_fct.start(); |
Freescale_cup | 0:3ec7fc598e48 | 44 | while(debut_fct.read() < time) |
Freescale_cup | 0:3ec7fc598e48 | 45 | { |
Freescale_cup | 0:3ec7fc598e48 | 46 | for(int i = -30; i < 30; i++) |
Freescale_cup | 0:3ec7fc598e48 | 47 | { |
Freescale_cup | 0:3ec7fc598e48 | 48 | angle_servo_moteur(i); |
Freescale_cup | 0:3ec7fc598e48 | 49 | wait(0.01); |
Freescale_cup | 0:3ec7fc598e48 | 50 | } |
Freescale_cup | 0:3ec7fc598e48 | 51 | for(int i = 30; i > -30; i--) |
Freescale_cup | 0:3ec7fc598e48 | 52 | { |
Freescale_cup | 0:3ec7fc598e48 | 53 | angle_servo_moteur(i); |
Freescale_cup | 0:3ec7fc598e48 | 54 | wait(0.01); |
Freescale_cup | 0:3ec7fc598e48 | 55 | } |
Freescale_cup | 0:3ec7fc598e48 | 56 | } |
Freescale_cup | 0:3ec7fc598e48 | 57 | angle_servo_moteur(0); |
Freescale_cup | 0:3ec7fc598e48 | 58 | } |
Freescale_cup | 0:3ec7fc598e48 | 59 | |
Freescale_cup | 0:3ec7fc598e48 | 60 | void Get_pot_value() |
Freescale_cup | 0:3ec7fc598e48 | 61 | { |
Freescale_cup | 0:3ec7fc598e48 | 62 | VIT = 0, KP = 0; |
Freescale_cup | 0:3ec7fc598e48 | 63 | for(int i = 0; i < 10; i++) |
Freescale_cup | 0:3ec7fc598e48 | 64 | { |
Freescale_cup | 0:3ec7fc598e48 | 65 | VIT += ((pot1.read()+1)*(25.0)); |
Freescale_cup | 0:3ec7fc598e48 | 66 | KP += ((pot2.read()+1)*100); |
Freescale_cup | 0:3ec7fc598e48 | 67 | } |
Freescale_cup | 0:3ec7fc598e48 | 68 | VIT /= 10; |
leandre | 1:000a03402c6e | 69 | pc.printf("VIT=%d\nKP=%d\n",VIT,KP); //ici |
Freescale_cup | 0:3ec7fc598e48 | 70 | } |