Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of CURRENT_CONTROL by
Revision 6:bae35ca64f10, committed 2016-12-15
- Comitter:
- benson516
- Date:
- Thu Dec 15 23:16:09 2016 +0000
- Parent:
- 5:7ccd2fb7ce7e
- Child:
- 7:6794cfba3564
- Commit message:
- Another modification
Changed in this revision
| CURRENT_CONTROL.cpp | Show annotated file Show diff for this revision Revisions of this file |
| CURRENT_CONTROL.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/CURRENT_CONTROL.cpp Thu Dec 15 22:54:54 2016 +0000
+++ b/CURRENT_CONTROL.cpp Thu Dec 15 23:16:09 2016 +0000
@@ -22,7 +22,7 @@
PinName PwmChannel1,
PinName PwmChannel2,
PWMIndex pwmIndex,
- float Kp, float Ki, float Kd,
+ float Kp, float Ki, float Kd, float Ka,
float samplingTime) :
currentAnalogIn(curChannel),
MotorPlus(PwmChannel1),
@@ -41,9 +41,17 @@
if(pwmIndex_ == PWM1)TIM1->CCER |= 4;
else if(pwmIndex_ == PWM2)TIM1->CCER |= 64; //enable complimentary output
+
//
currentOffset = 0.0;
delta_output = 0.0;
+
+ // Set PID's parameters
+ /////////////////////
+ pid.Kp = Kp;
+ pid.Ki = Ki;
+ pid.Kd = Kd;
+ pid.Ka = Ka; // Gain for anti-windup // Ka = 0.0017
}
//
void CURRENT_CONTROL::SetParams(float Analog2Cur, float angSpeed2BackEmf, float voltage2DutyRatio)
@@ -77,6 +85,7 @@
// PID
pid.Compute_noWindUP(curRef, curFeedBack);
+ // Output saturation and unit changing
MotorPlus = 0.5 + saturation((-pid.output + func_back_emf(angularSpeed) )*voltage2Duty, delta_output, 0.5, -0.5) ;
// Anti-windup
--- a/CURRENT_CONTROL.h Thu Dec 15 22:54:54 2016 +0000
+++ b/CURRENT_CONTROL.h Thu Dec 15 23:16:09 2016 +0000
@@ -35,7 +35,7 @@
PWM2
} PWMIndex;
- CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float Kp, float Ki, float Kd, float samplingTime);
+ CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float Kp, float Ki, float Kd, float Ka, float samplingTime);
void SetParams(float Analog2Cur, float angSpeed2BackEmf, float voltage2DutyRatio);
float saturation(float input_value, float &delta, const float &limit_H, const float &limit_L);
void Control(float curRef, float speed);
