Merged to branch
Dependencies: USBDevice mbed EquatorStrutController LightWeightSerialTransmit
Fork of EquatorStrutDigitalMonitor by
Revision 20:04432d03b46c, committed 2014-08-15
- Comitter:
- alpesh
- Date:
- Fri Aug 15 09:11:50 2014 +0000
- Parent:
- 19:a6369257c00f
- Child:
- 22:9f7dae024a81
- Commit message:
- Linearisation of the pwm
Changed in this revision
USBDevice.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/USBDevice.lib Thu Aug 14 14:46:31 2014 +0000 +++ b/USBDevice.lib Fri Aug 15 09:11:50 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/USBDevice/#0c6524151939 +http://mbed.org/users/mbed_official/code/USBDevice/#c09a0c9bf425
--- a/main.cpp Thu Aug 14 14:46:31 2014 +0000 +++ b/main.cpp Fri Aug 15 09:11:50 2014 +0000 @@ -346,6 +346,7 @@ double pwm; double TargetPwm; +double newTargetPwm; double TargetVelocity; double PosiState; @@ -353,7 +354,9 @@ int PreviousTime = 0; -double vMax = 20; +double vMax = 300; +double vStep = 50; +double pStep = 0.5; void Controller () { @@ -392,54 +395,30 @@ TargetPwm = (PosKpGain * PosError + PosKdGain * PosDifError + PosIntError); - - // TargetVelocity = (PosKpGain * PosError + PosKdGain * PosDifError + PosIntError); + if (TargetPwm < pStep) - /////////////////////////////////////////////////////////////////////////////////////////////// - //Velocity PID - /////////////////////////////////////////////////////////////////////////////////////////////// - /* - double integral_pwmmax = 1.0/VelKiGain; - double integral_pwmmin = -1.0/VelKiGain; - - VelError = TargetVelocity - GetSpeed(); - - VelProError = VelError * VelKpGain; - - VelDifError = (VelError - VelPreviousError[errorcounter]) / timeStep; - - //Calculate the integral state with appropriate limiting + { + newTargetPwm = (TargetPwm * 300) / 100; + } - VeliState += VelError; + if (TargetPwm > pStep) + { + newTargetPwm = pStep + (TargetPwm - pStep) * 100 / 500; + } - if (VeliState > integral_pwmmax) - { - VeliState = integral_pwmmax; - } - else if (VeliState < integral_pwmmin) - { - VeliState = integral_pwmmin; - } - - VelIntError = VelKiGain * VeliState; - - TargetPwm = (VelKpGain * VelError + VelKdGain * VelDifError + VelIntError); - */ - - - if (TargetPwm > 1.0) + if (newTargetPwm > 1.0) { pwm = 1.0; } - else if (TargetPwm < -1.0) + else if (newTargetPwm < -1.0) { pwm = -1.0; } else { - pwm = TargetPwm; + pwm = newTargetPwm; } SetPower(pwm);