Programme utilisé pour la coupe

Dependencies:   TCA9548A_vcdf mbed QEI RemoteIR VL53L0X_Vcdf

Fork of asservissement_robot2_Homologued_real by Timothée Frouté

Moteur.cpp

Committer:
Onclehube
Date:
2019-10-10
Revision:
2:b94303d66b9d
Parent:
1:11cbd2bf65d7

File content as of revision 2:b94303d66b9d:

#include "Moteur.h"


#define PERIODE_PWM_MOTEUR 0.001

PwmOut mypwm_a(D6);
PwmOut mypwm_b(D11);


DigitalOut in1(D7);
DigitalOut in2(D8);
DigitalOut in3(D9);
DigitalOut in4(D10);
DigitalOut in5(PC_10);
DigitalOut in6(PC_12);
DigitalOut in7(PA_13);


void moteur_init()
{
    mypwm_a.period(PERIODE_PWM_MOTEUR);
    mypwm_b.period(PERIODE_PWM_MOTEUR);
    //in7=0;
    
    mypwm_a.pulsewidth(0);
    mypwm_b.pulsewidth(0);

}

void moteur_a(float percent)
{

    if (percent>=0) {
        in1 = 1;
        in2 = 0;
    } else {
        in1 = 0;
        in2 = 1;
        percent = -1 * percent;
    }
    mypwm_a.pulsewidth((float)percent*(float)PERIODE_PWM_MOTEUR);
}

void moteur_b(float percent)
{

    if (percent>=0) {
        in4 = 1;
        in3 = 0;
    } else {
        in4 = 0;
        in3 = 1;
        percent = -1 * percent;
    }

    mypwm_b.pulsewidth((float)percent*(float)PERIODE_PWM_MOTEUR);
}

void moteur_c(int percent)
{
if (percent==0) in7=0;
    else
    if (percent==1) {
        in5 = 0;
        in6 = 1;
        in7=1;
        wait_ms(900);
        in7=0;

    } else if (percent==2){
        in5 = 1;
        in6 = 0;
        in7=1;
        wait_ms(900);
        in7=0;

    }

   
}