Merged to branch
Dependencies: USBDevice mbed EquatorStrutController LightWeightSerialTransmit
Fork of EquatorStrutDigitalMonitor by
Diff: main.cpp
- Revision:
- 19:a6369257c00f
- Parent:
- 18:ab282713f4a7
- Child:
- 20:04432d03b46c
- Child:
- 21:b4eb253d3dbb
--- a/main.cpp Thu Aug 14 14:23:56 2014 +0000 +++ b/main.cpp Thu Aug 14 14:46:31 2014 +0000 @@ -145,7 +145,7 @@ } double PosError = 0; //This has been defined here as it's being used in the serial transmit function -double VelError = 0; +//double VelError = 0; void SerialOut(double outputValue) { @@ -225,9 +225,9 @@ double PosKiGain = 0.0; double PosKdGain = 0.0; -double VelKpGain = 0.01; -double VelKiGain = 0.0; -double VelKdGain = 0.0; +//double VelKpGain = 0.01; +//double VelKiGain = 0.0; +//double VelKdGain = 0.0; void SerialTransmit() { @@ -255,7 +255,7 @@ pc.putc('\t'); - SerialOut(VelKpGain); + // SerialOut(VelKpGain); //pc.putc('\t'); @@ -334,13 +334,13 @@ double PosIntError; double PosDifError; -double VelProError; -double VelIntError; -double VelDifError; +//double VelProError; +//double VelIntError; +//double VelDifError; int errorcounter; double PosPreviousError [10]; -double VelPreviousError [10]; +//double VelPreviousError [10]; double PwmChange=0; @@ -349,7 +349,7 @@ double TargetVelocity; double PosiState; -double VeliState; +//double VeliState; int PreviousTime = 0; @@ -369,8 +369,8 @@ int timeStep = RunningTime.read_us() - PreviousTime; PreviousTime = RunningTime.read_us(); - double integral_velmax = vMax/VelKiGain; - double integral_velmin = -vMax/VelKiGain ; + double integral_velmax = vMax/PosKiGain; + double integral_velmin = -vMax/PosKiGain ; PosError = SetPoint - (position * 0.01); @@ -390,12 +390,15 @@ } PosIntError = PosKiGain * PosiState; - TargetVelocity = (PosKpGain * PosError + PosKdGain * PosDifError + PosIntError); + TargetPwm = (PosKpGain * PosError + PosKdGain * PosDifError + PosIntError); + + + // TargetVelocity = (PosKpGain * PosError + PosKdGain * PosDifError + PosIntError); /////////////////////////////////////////////////////////////////////////////////////////////// //Velocity PID /////////////////////////////////////////////////////////////////////////////////////////////// - + /* double integral_pwmmax = 1.0/VelKiGain; double integral_pwmmin = -1.0/VelKiGain; @@ -421,6 +424,8 @@ VelIntError = VelKiGain * VeliState; TargetPwm = (VelKpGain * VelError + VelKdGain * VelDifError + VelIntError); + */ + if (TargetPwm > 1.0) { @@ -447,7 +452,7 @@ } PosPreviousError[errorcounter] = PosError; - VelPreviousError[errorcounter] = VelError; + // VelPreviousError[errorcounter] = VelError; // } } @@ -487,10 +492,10 @@ //pow += 0.05; PosKpGain += 1.0; - VelKpGain = 0.003; - while (VelKpGain < 0.008) - { - VelKpGain += 0.001; + // VelKpGain = 0.003; + // while (VelKpGain < 0.008) + // { + // VelKpGain += 0.001; float iterationStart = RunningTime.read(); @@ -502,7 +507,7 @@ } Home(); - } + // } } Disable();