Home > other >  Motor PID control problem
Motor PID control problem

Time:04-08

code on the first
 
100//# define MAX_DUTY output biggest duty ratio

PID sPID;
The static pPID SPTR;

Void IncPIDInit (void)
{
SPTR=& amp; SPID;
SPTR - & gt; SetSpeed=1000;//value

SPTR - & gt; The LastError=0 u;//2 times before error values
SPTR - & gt; PrevError=0 u;//1 time before error values

SPTR - & gt; Proportion f=0.41;//ratio
SPTR - & gt; Integral=0.25 f;//integral
SPTR - & gt; Derivative f=0.12;//differential

SPTR - & gt; IError=0;//the current error
SPTR - & gt; IIncpid=0;//increment error

SPTR - & gt; Uk=0;//output return value
}

Int IncPIDCalc (int tag_speed)
{
Int duty_pwm;

//the current velocity error
SPTR - & gt; IError=SPTR - & gt; SetSpeed - currentSpeed;

//increment error
SPTR - & gt; IIncpid=SPTR - & gt; Proportion * SPTR - & gt; IError SPTR - & gt; Integral * SPTR - & gt; LastError
+ SPTR - & gt; Derivative * SPTR - & gt; PrevError;

//store the error for the next calculation
SPTR - & gt; PrevError=SPTR - & gt; IError;
SPTR - & gt; LastError=SPTR - & gt; LastError;

SPTR - & gt; Uk +=SPTR - & gt; IIncpid;

Duty_pwm=SPTR - & gt; The Uk * 0.2 f;

//output value limiter
If (duty_pwm & gt;=MAX_DUTY)
{
Duty_pwm=MAX_DUTY;
}
Else if (duty_pwm & lt;=0 u)
{
Duty_pwm=0;
}

Return duty_pwm;
}


Tuning PID for the first time, have a few questions to ask

1. Using the incremental PID, increment is obtained by the current and target speed conversion error, SPTR - & gt; IIncpid how to get PWM duty ratio conversion, I get a light 100% duty cycle speed to 500 RPM, is that can conversion by system 0.2

2. SPTR - & gt; IIncpid incremental error is it need to adjust the speed deviation and the speed of the next need rectification

3. The coefficient KP ki kd how to adjust, through simulation or themselves one by one the speed curve blind adjustable



CodePudding user response:

if the motor no-load and load cases, whether the coefficient is also need to separate into two groups

CodePudding user response:

SPTR - & gt; IIncpid=SPTR - & gt; Proportion * SPTR - & gt; IError - SPTR - & gt; Integral * SPTR - & gt; LastError + SPTR - & gt; Derivative * SPTR - & gt; PrevError ;

The red part is not correct,

Ei=target - current value;
Kp + Ki * * ei PID=Sum (ei) + Kd (ei - ei1);//ei current error values, ei1 last error values
  • Related