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

Committer:
ahmed_lv
Date:
Tue Mar 20 05:56:22 2018 +0000
Revision:
30:44676e1b38f8
Parent:
11:49344285c82a
Editted Input Variables to PID

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akashvibhute 11:49344285c82a 1 #include "motorDriver.h"
akashvibhute 11:49344285c82a 2 /*
akashvibhute 11:49344285c82a 3 motorDriver::motorDriver(PinName mPlus, PinName mMinus, int freq_khz): motor_P(mPlus), motor_M(mMinus)
akashvibhute 11:49344285c82a 4 {
akashvibhute 11:49344285c82a 5 motor_P.period_us(1000/freq_khz);
akashvibhute 11:49344285c82a 6 motor_M.period_us(1000/freq_khz);
akashvibhute 11:49344285c82a 7 }
akashvibhute 11:49344285c82a 8 */
akashvibhute 11:49344285c82a 9
akashvibhute 11:49344285c82a 10 /*
akashvibhute 11:49344285c82a 11 void motorDriver::setPWM(float val)
akashvibhute 11:49344285c82a 12 {
akashvibhute 11:49344285c82a 13 val = generalFunctions::constrain_f(val, minPWM, maxPWM); //check if input pwm value is between -100% to 100%
akashvibhute 11:49344285c82a 14
akashvibhute 11:49344285c82a 15 if(val >= 0) {
akashvibhute 11:49344285c82a 16 motor_P = generalFunctions::abs_f(val);
akashvibhute 11:49344285c82a 17 motor_M = 0;
akashvibhute 11:49344285c82a 18 } else {
akashvibhute 11:49344285c82a 19 motor_P = 0;
akashvibhute 11:49344285c82a 20 motor_M = generalFunctions::abs_f(val);
akashvibhute 11:49344285c82a 21 }
akashvibhute 11:49344285c82a 22 }
akashvibhute 11:49344285c82a 23 */
akashvibhute 11:49344285c82a 24
akashvibhute 11:49344285c82a 25 motorDriver::motorDriver(): motorL_P(mot_LM), motorL_M(mot_LP), motorR_P(mot_RP), motorR_M(mot_RM)
akashvibhute 11:49344285c82a 26 {
akashvibhute 11:49344285c82a 27 motorL_P.period_us(1000/PWMfreq_khz);
akashvibhute 11:49344285c82a 28 motorL_M.period_us(1000/PWMfreq_khz);
akashvibhute 11:49344285c82a 29
akashvibhute 11:49344285c82a 30 motorR_P.period_us(1000/PWMfreq_khz);
akashvibhute 11:49344285c82a 31 motorR_M.period_us(1000/PWMfreq_khz);
akashvibhute 11:49344285c82a 32 }
akashvibhute 11:49344285c82a 33
akashvibhute 11:49344285c82a 34 void motorDriver::setPWM_L(float val)
akashvibhute 11:49344285c82a 35 {
akashvibhute 11:49344285c82a 36 val = generalFunctions::constrain_f(val, minPWM, maxPWM); //check if input pwm value is between -100% to 100%
akashvibhute 11:49344285c82a 37
akashvibhute 11:49344285c82a 38 if(val >= 0) {
akashvibhute 11:49344285c82a 39 motorL_P = generalFunctions::abs_f(val);
akashvibhute 11:49344285c82a 40 motorL_M = 0;
akashvibhute 11:49344285c82a 41 } else {
akashvibhute 11:49344285c82a 42 motorL_P = 0;
akashvibhute 11:49344285c82a 43 motorL_M = generalFunctions::abs_f(val);
akashvibhute 11:49344285c82a 44 }
akashvibhute 11:49344285c82a 45 }
akashvibhute 11:49344285c82a 46
akashvibhute 11:49344285c82a 47 void motorDriver::setPWM_R(float val)
akashvibhute 11:49344285c82a 48 {
akashvibhute 11:49344285c82a 49 val = generalFunctions::constrain_f(val, minPWM, maxPWM); //check if input pwm value is between -100% to 100%
akashvibhute 11:49344285c82a 50
akashvibhute 11:49344285c82a 51 if(val >= 0) {
akashvibhute 11:49344285c82a 52 motorR_P = generalFunctions::abs_f(val);
akashvibhute 11:49344285c82a 53 motorR_M = 0;
akashvibhute 11:49344285c82a 54 } else {
akashvibhute 11:49344285c82a 55 motorR_P = 0;
akashvibhute 11:49344285c82a 56 motorR_M = generalFunctions::abs_f(val);
akashvibhute 11:49344285c82a 57 }
akashvibhute 11:49344285c82a 58 }