changes to motor library
Fork of motor by
Diff: motor.cpp
- Branch:
- testing
- Revision:
- 8:4df2a47ab4ee
- Parent:
- 7:9aaa4f73bb32
- Child:
- 9:22b119eef1de
--- a/motor.cpp Mon Nov 07 16:00:45 2016 +0000 +++ b/motor.cpp Mon Nov 07 16:12:48 2016 +0000 @@ -15,9 +15,8 @@ //Corner Control -void PWM_cornerCntrl(bool a,float pwmRatio); -void cornerLeft(float speed); -void cornerRight(float speed); + +void corner(float &w1,float &w2,float deltaTheta,int maxspeed) void steering(float center, float theta, int maxspeed); @@ -131,58 +130,14 @@ } return; } - -void PWM_cornerCntrl(bool a,float pwmRatio) - { - //A is the Right motor B is the left motor. - // may need the value of speed to decelerate. - if(a==1)//turn left - { - cornerLeft(pwmRatio); - } - - else//turn right - { - cornerRight(pwmRatio); - } - return; - } - - -void cornerLeft(float speed) - {// when cornering left the left motor slows down more than the right hand side - // may just replace with ACC and DECC - - // it may be worth doing this off the change in theta. so that it is insesnsitive to the calibration. - float diff = speed*cornerPwmControl; - float w1 = speed + diff; - float w2 = speed-diff; - TFC_SetMotorPWM(w2,w1); //temperary values - - - + //---------------------------------------------------------------------------------------------------------------------------- + //------------------------------------------------Cornering Control----------------------------------------------------------- + //---------------------------------------------------------------------------------------------------------------------------- - - - return; - } - -void cornerRight(float speed) - { // may need to put deceleration control within here. - // may just replace with ACC and DECC - float diff = speed*cornerPwmControl; - float w1 = speed + diff; - float w2 = speed-diff; - TFC_SetMotorPWM(w1,w2); //temperary values - - return; - } - - -void deltaCornerLeft(float speed,float deltaTheta) +void corner(float &w1,float &w2,float deltaTheta,int maxspeed) {// when cornering left the left motor slows down more than the right hand side // may just replace with ACC and DECC float r; @@ -191,12 +146,10 @@ // it may be worth doing this off the change in theta. so that it is insesnsitive to the calibration. float diff= ((d*tan(deltaTheta)/(2*l))); - float w1 = (speed/r)*(1+diff); - float w2 = (speed/r)*(1-diff); + float w1 = (maxspeed/r)*(1+diff); + float w2 = (maxspeed/r)*(1-diff); - // when there is a speed sensor tghe conversion will be much more simplistic. this is basically just guessing. - // need to convert w1 to the duty cycle - TFC_SetMotorPWM(w2,w1); //temperary values + return; @@ -212,13 +165,16 @@ return center; } -void steering(float center, float theta, int maxspeed,float w1, float w2) -{ +void steering(float center, float theta, int maxspeed,float & w1, float & w2) +{ // this function is for simply calculating the motor speeds. this reduces the amount of calculations needed + //and can be triggered when the car steers. + + float deltaTheta = center- theta; if(deltaTheta <0) { // going left? - corner(w1,w2,deltaTheta); + corner(w1,w2,deltaTheta,maxspeed); } else()