Implement new controller

Dependencies:   mbed-rtos mbed QEI BNO055 MPU6050_DMP_Nucleo-I2Cdev virgo3_imuHandler_Orion_PCB MAX17048 Servo

Fork of Orion_newPCB_test by Team Virgo v3

01_DriveTrain/motorDriver.cpp

Committer:
akashvibhute
Date:
2016-04-24
Revision:
11:49344285c82a

File content as of revision 11:49344285c82a:

#include "motorDriver.h"
/*
motorDriver::motorDriver(PinName mPlus, PinName mMinus, int freq_khz): motor_P(mPlus), motor_M(mMinus)
{
    motor_P.period_us(1000/freq_khz);
    motor_M.period_us(1000/freq_khz);
}
*/

/*
void motorDriver::setPWM(float val)
{
    val = generalFunctions::constrain_f(val, minPWM, maxPWM); //check if input pwm value is between -100% to 100%

    if(val >= 0) {
        motor_P = generalFunctions::abs_f(val);
        motor_M = 0;
    } else {
        motor_P = 0;
        motor_M = generalFunctions::abs_f(val);
    }
}
*/

motorDriver::motorDriver(): motorL_P(mot_LM), motorL_M(mot_LP), motorR_P(mot_RP), motorR_M(mot_RM)
{
    motorL_P.period_us(1000/PWMfreq_khz);
    motorL_M.period_us(1000/PWMfreq_khz);
    
    motorR_P.period_us(1000/PWMfreq_khz);
    motorR_M.period_us(1000/PWMfreq_khz);
}

void motorDriver::setPWM_L(float val)
{
    val = generalFunctions::constrain_f(val, minPWM, maxPWM); //check if input pwm value is between -100% to 100%

    if(val >= 0) {
        motorL_P = generalFunctions::abs_f(val);
        motorL_M = 0;
    } else {
        motorL_P = 0;
        motorL_M = generalFunctions::abs_f(val);
    }
}

void motorDriver::setPWM_R(float val)
{
    val = generalFunctions::constrain_f(val, minPWM, maxPWM); //check if input pwm value is between -100% to 100%

    if(val >= 0) {
        motorR_P = generalFunctions::abs_f(val);
        motorR_M = 0;
    } else {
        motorR_P = 0;
        motorR_M = generalFunctions::abs_f(val);
    }
}