servo

Dependencies:   mbed

Fork of Nucleo_PWM by Khemiri Mahrane

Committer:
wassim94
Date:
Tue Feb 09 15:44:08 2016 +0000
Revision:
1:6c59c6871460
Parent:
0:bb0da30d43f4
Child:
2:197217bf7bca
servo

Who changed what in which revision?

UserRevisionLine numberNew 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
Mahran 0:bb0da30d43f4 5 PwmOut PWM2(PA_11);
Mahran 0:bb0da30d43f4 6 //TIM16_CH1
Mahran 0:bb0da30d43f4 7 PwmOut PWM3(PA_12);
Mahran 0:bb0da30d43f4 8 //TIM3_CH1
Mahran 0:bb0da30d43f4 9 PwmOut PWM4(PB_0);
Mahran 0:bb0da30d43f4 10 //TIM3_CH4
Mahran 0:bb0da30d43f4 11 PwmOut PWM5(PB_7);
Mahran 0:bb0da30d43f4 12 //TIM17_CH1N
Mahran 0:bb0da30d43f4 13 PwmOut PWM6(PB_6);
Mahran 0:bb0da30d43f4 14 //TIM3_CH4,
Mahran 0:bb0da30d43f4 15 PwmOut PWM7(PB_1);
Mahran 0:bb0da30d43f4 16 //TIM3_CH3
Mahran 0:bb0da30d43f4 17 PwmOut PWM8(PB_0);
Mahran 0:bb0da30d43f4 18
Mahran 0:bb0da30d43f4 19 float map (int x, int in_min,int in_max, float out_min, float out_max)
Mahran 0:bb0da30d43f4 20 {
Mahran 0:bb0da30d43f4 21 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
Mahran 0:bb0da30d43f4 22 }
Mahran 0:bb0da30d43f4 23
Mahran 0:bb0da30d43f4 24 void Pince_Bas_Gauche(int a)
wassim94 1:6c59c6871460 25 {// 40 ouverture 0 fermeture
Mahran 0:bb0da30d43f4 26 PWM1.period_ms(20);
Mahran 0:bb0da30d43f4 27 PWM1.write(map (a,0,180,0.028f,0.12f));
Mahran 0:bb0da30d43f4 28 }
Mahran 0:bb0da30d43f4 29
Mahran 0:bb0da30d43f4 30 void Pince_Bas_Droite(int a)
wassim94 1:6c59c6871460 31 {// 0 ouverture 40 fermeture
Mahran 0:bb0da30d43f4 32 PWM2.period_ms(20);
Mahran 0:bb0da30d43f4 33 PWM2.write(map (a,0,180,0.028f,0.12f));
Mahran 0:bb0da30d43f4 34 }
wassim94 1:6c59c6871460 35 void ouverture()
wassim94 1:6c59c6871460 36 {
wassim94 1:6c59c6871460 37 Pince_Bas_Droite(0);
wassim94 1:6c59c6871460 38 Pince_Bas_Gauche(40);
wassim94 1:6c59c6871460 39 }
wassim94 1:6c59c6871460 40 void fermeture()
wassim94 1:6c59c6871460 41 {
wassim94 1:6c59c6871460 42 Pince_Bas_Droite(35);
wassim94 1:6c59c6871460 43 Pince_Bas_Gauche(5);
wassim94 1:6c59c6871460 44 }
Mahran 0:bb0da30d43f4 45 void Pince_Glissement_Gauche(int a)
wassim94 1:6c59c6871460 46 {//50avant 0 arriere
Mahran 0:bb0da30d43f4 47 PWM3.period_ms(20);
Mahran 0:bb0da30d43f4 48 PWM3.write(map (a,0,180,0.028f,0.12f));
Mahran 0:bb0da30d43f4 49 }
Mahran 0:bb0da30d43f4 50
Mahran 0:bb0da30d43f4 51 void Pince_Glissement_Droit(int a)
wassim94 1:6c59c6871460 52 {//0 avant 50 arriere
Mahran 0:bb0da30d43f4 53 PWM4.period_ms(20);
Mahran 0:bb0da30d43f4 54 PWM4.write(map (a,0,180,0.028f,0.12f));
Mahran 0:bb0da30d43f4 55 }
wassim94 1:6c59c6871460 56 void Pince_avant()
wassim94 1:6c59c6871460 57 {
wassim94 1:6c59c6871460 58 Pince_Glissement_Droit(0);
wassim94 1:6c59c6871460 59 Pince_Glissement_Gauche(50);
wassim94 1:6c59c6871460 60 }
wassim94 1:6c59c6871460 61 void Pince_arriere()
wassim94 1:6c59c6871460 62 {
wassim94 1:6c59c6871460 63 Pince_Glissement_Droit(50);
wassim94 1:6c59c6871460 64 Pince_Glissement_Gauche(0);
wassim94 1:6c59c6871460 65 }
Mahran 0:bb0da30d43f4 66 int main()
Mahran 0:bb0da30d43f4 67 {
Mahran 0:bb0da30d43f4 68
wassim94 1:6c59c6871460 69
Mahran 0:bb0da30d43f4 70 while(1) {
wassim94 1:6c59c6871460 71 Pince_arriere();
wassim94 1:6c59c6871460 72 wait(1);
wassim94 1:6c59c6871460 73 ouverture();
wassim94 1:6c59c6871460 74 wait(2);
wassim94 1:6c59c6871460 75 fermeture();
wassim94 1:6c59c6871460 76 wait(2);
wassim94 1:6c59c6871460 77 Pince_avant();
wassim94 1:6c59c6871460 78 wait(3); }
Mahran 0:bb0da30d43f4 79 }