Tuk tutoriail

Dependencies:   mbed lib_workshop_2019

src/test_motor/ft_run_motor.cpp

Committer:
gvaquette
Date:
2019-10-28
Revision:
9:19255172362f
Parent:
7:c7ff04228b11
Child:
10:2c17068cb551

File content as of revision 9:19255172362f:

#include "mbed.h"
#include "test_motor.h"
#include "console_output.h"


/**********************************************************************/
/**                         ft_run_motor                             **/
/* Args :   - direction (e_direction): direction to turn the motor    */
/*          - duty_cycle (double): duty cycle for the PWM             */
/*          - pwm_mot (PwmOut): pin to set the PWM                    */
/*          - dirA and dirB (DigitalOut): Pins to set the direction   */
/**********************************************************************/
void ft_run_motor(  e_direction direction, double duty_cycle,
                    PwmOut pwm_mot, DigitalOut  dirA, DigitalOut  dirB)
{
    
    /* TO DO : define direction */
    
    if (direction == FORWARD)
    {
       
       
    }
    else // direction == BACKWARD
    {
      
      
    }
    
    /* TO DO : apply duty cycle to pwm_mot */

}


double ft_get_duty_cycle_choice(Serial pc) {
    double duty_cycle = 0;
    
    if (pc.readable() )
        {
            int user_int = ft_get_user_int(pc);
            if (user_int < 10 && user_int >= 0) duty_cycle = user_int/10.0; 
        }
        return duty_cycle;
}

void ft_test_motor(PwmOut pin_pwm_mot, DigitalOut pin_dirA, DigitalOut pin_dirB,
                    Serial &pc)
{
    e_direction direction = FORWARD;
    
    double duty_cycle =0.1;
    
    do{
        duty_cycle = ft_get_duty_cycle_choice(pc);
        ft_run_motor(direction, duty_cycle, pin_pwm_mot, pin_dirA, pin_dirB);
    } while (duty_cycle > 0.0);
    
    return;
}