wassim boumaiza
/
Nucleo_PWM
servo
Fork of Nucleo_PWM by
main.cpp@2:197217bf7bca, 2016-03-23 (annotated)
- Committer:
- wassim94
- Date:
- Wed Mar 23 11:54:22 2016 +0000
- Revision:
- 2:197217bf7bca
- Parent:
- 1:6c59c6871460
servo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mahran | 0:bb0da30d43f4 | 1 | #include "mbed.h" |
wassim94 | 1:6c59c6871460 | 2 | //TIM1_CH1 //Pince Bas gauche |
Mahran | 0:bb0da30d43f4 | 3 | PwmOut PWM1(PA_8); |
wassim94 | 1:6c59c6871460 | 4 | //TIM1_CH4 //Pince bas droite |
wassim94 | 2:197217bf7bca | 5 | PwmOut PWM2(PA_9); |
Mahran | 0:bb0da30d43f4 | 6 | //TIM16_CH1 |
wassim94 | 2:197217bf7bca | 7 | PwmOut PWM3(PB_4);// Pince Glissement Gauche |
Mahran | 0:bb0da30d43f4 | 8 | //TIM3_CH1 |
wassim94 | 2:197217bf7bca | 9 | PwmOut PWM4(PB_10);//Pince Glissement droite |
Mahran | 0:bb0da30d43f4 | 10 | //TIM3_CH4 |
wassim94 | 2:197217bf7bca | 11 | |
Mahran | 0:bb0da30d43f4 | 12 | |
Mahran | 0:bb0da30d43f4 | 13 | float map (int x, int in_min,int in_max, float out_min, float out_max) |
Mahran | 0:bb0da30d43f4 | 14 | { |
Mahran | 0:bb0da30d43f4 | 15 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
Mahran | 0:bb0da30d43f4 | 16 | } |
Mahran | 0:bb0da30d43f4 | 17 | |
Mahran | 0:bb0da30d43f4 | 18 | void Pince_Bas_Gauche(int a) |
wassim94 | 1:6c59c6871460 | 19 | {// 40 ouverture 0 fermeture |
Mahran | 0:bb0da30d43f4 | 20 | PWM1.period_ms(20); |
Mahran | 0:bb0da30d43f4 | 21 | PWM1.write(map (a,0,180,0.028f,0.12f)); |
Mahran | 0:bb0da30d43f4 | 22 | } |
Mahran | 0:bb0da30d43f4 | 23 | |
Mahran | 0:bb0da30d43f4 | 24 | void Pince_Bas_Droite(int a) |
wassim94 | 1:6c59c6871460 | 25 | {// 0 ouverture 40 fermeture |
Mahran | 0:bb0da30d43f4 | 26 | PWM2.period_ms(20); |
Mahran | 0:bb0da30d43f4 | 27 | PWM2.write(map (a,0,180,0.028f,0.12f)); |
Mahran | 0:bb0da30d43f4 | 28 | } |
wassim94 | 1:6c59c6871460 | 29 | void ouverture() |
wassim94 | 1:6c59c6871460 | 30 | { |
wassim94 | 2:197217bf7bca | 31 | Pince_Bas_Gauche(80); |
wassim94 | 2:197217bf7bca | 32 | Pince_Bas_Droite(10); |
wassim94 | 1:6c59c6871460 | 33 | } |
wassim94 | 1:6c59c6871460 | 34 | void fermeture() |
wassim94 | 1:6c59c6871460 | 35 | { |
wassim94 | 2:197217bf7bca | 36 | Pince_Bas_Gauche(30); |
wassim94 | 2:197217bf7bca | 37 | Pince_Bas_Droite(60); |
wassim94 | 2:197217bf7bca | 38 | } |
Mahran | 0:bb0da30d43f4 | 39 | void Pince_Glissement_Gauche(int a) |
wassim94 | 1:6c59c6871460 | 40 | {//50avant 0 arriere |
Mahran | 0:bb0da30d43f4 | 41 | PWM3.period_ms(20); |
Mahran | 0:bb0da30d43f4 | 42 | PWM3.write(map (a,0,180,0.028f,0.12f)); |
Mahran | 0:bb0da30d43f4 | 43 | } |
Mahran | 0:bb0da30d43f4 | 44 | |
Mahran | 0:bb0da30d43f4 | 45 | void Pince_Glissement_Droit(int a) |
wassim94 | 2:197217bf7bca | 46 | {//0avant 50 arriere |
Mahran | 0:bb0da30d43f4 | 47 | PWM4.period_ms(20); |
Mahran | 0:bb0da30d43f4 | 48 | PWM4.write(map (a,0,180,0.028f,0.12f)); |
Mahran | 0:bb0da30d43f4 | 49 | } |
wassim94 | 2:197217bf7bca | 50 | void Pince_arriere() |
wassim94 | 1:6c59c6871460 | 51 | { |
wassim94 | 1:6c59c6871460 | 52 | Pince_Glissement_Droit(0); |
wassim94 | 1:6c59c6871460 | 53 | Pince_Glissement_Gauche(50); |
wassim94 | 1:6c59c6871460 | 54 | } |
wassim94 | 2:197217bf7bca | 55 | void Pince_avant() |
wassim94 | 1:6c59c6871460 | 56 | { |
wassim94 | 1:6c59c6871460 | 57 | Pince_Glissement_Droit(50); |
wassim94 | 1:6c59c6871460 | 58 | Pince_Glissement_Gauche(0); |
wassim94 | 1:6c59c6871460 | 59 | } |
Mahran | 0:bb0da30d43f4 | 60 | int main() |
Mahran | 0:bb0da30d43f4 | 61 | { |
Mahran | 0:bb0da30d43f4 | 62 | |
wassim94 | 1:6c59c6871460 | 63 | |
wassim94 | 2:197217bf7bca | 64 | |
wassim94 | 2:197217bf7bca | 65 | while(1){ |
wassim94 | 2:197217bf7bca | 66 | Pince_Glissement_Gauche(90); |
wassim94 | 2:197217bf7bca | 67 | Pince_Glissement_Droit(90); |
wassim94 | 2:197217bf7bca | 68 | |
wassim94 | 2:197217bf7bca | 69 | wait(1); |
wassim94 | 2:197217bf7bca | 70 | Pince_Glissement_Gauche(0); |
wassim94 | 2:197217bf7bca | 71 | Pince_Glissement_Droit(0); |
wassim94 | 2:197217bf7bca | 72 | wait(1); |
wassim94 | 2:197217bf7bca | 73 | } |
Mahran | 0:bb0da30d43f4 | 74 | } |