Nouvelle version de l'asservissement du robot 2 effectuée pour le projet de IESE4

Dependencies:   mbed QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Moteur.cpp Source File

Moteur.cpp

00001 #include "Moteur.h"
00002 
00003 
00004 #define PERIODE_PWM_MOTEUR 0.001
00005 
00006 PwmOut mypwm_a(D11);
00007 PwmOut mypwm_b(D6);
00008 
00009 
00010 DigitalOut in1(D8);
00011 DigitalOut in2(D7);
00012 
00013 DigitalOut in3(D10);
00014 DigitalOut in4(D9);
00015 
00016 DigitalOut in5(PC_10);
00017 DigitalOut in6(PC_12);
00018 DigitalOut in7(PA_13);
00019 
00020 
00021 void moteur_init()
00022 {
00023     mypwm_a.period(PERIODE_PWM_MOTEUR);
00024     mypwm_b.period(PERIODE_PWM_MOTEUR);
00025     //in7=0;
00026     
00027     mypwm_a.pulsewidth(0);
00028     mypwm_b.pulsewidth(0);
00029 
00030 }
00031 
00032 void moteur_a(float percent)
00033 {
00034     if (percent>=0) {
00035         in1 = 1;
00036         in2 = 0;
00037     } else {
00038         in1 = 0;
00039         in2 = 1;
00040         percent = -1 * percent;
00041     }
00042     mypwm_a.pulsewidth((float)percent*(float)PERIODE_PWM_MOTEUR);
00043 }
00044 
00045 void moteur_b(float percent)
00046 {
00047     if (percent>=0) {
00048         in4 = 1;
00049         in3 = 0;
00050     } else {
00051         in4 = 0;
00052         in3 = 1;
00053         percent = -1 * percent;
00054     }
00055 
00056     mypwm_b.pulsewidth((float)percent*(float)PERIODE_PWM_MOTEUR);
00057 }
00058 
00059 void moteur_c(int percent)
00060 {
00061 if (percent==0) in7=0;
00062     else
00063     if (percent==1) {
00064         in5 = 0;
00065         in6 = 1;
00066         in7=1;
00067         wait_ms(900);
00068         in7=0;
00069 
00070     } else if (percent==2){
00071         in5 = 1;
00072         in6 = 0;
00073         in7=1;
00074         wait_ms(900);
00075         in7=0;
00076 
00077     }
00078 
00079    
00080 }