这次的直流调速采用PID的思路来写控制函数Controller,利用输出的瞬间值与预期值之间的偏差作为控制因子,反馈到PID控制器中,从而进一步控制下一个瞬间的输入值,从而使各项参数准确的到达指定值,并且没有超调和波动
首先直流电机基本的参数模型定义如下
model PWMVoltageSource extends TwoPin; InPort Command(n=1); parameter Time T = 0.003; parameter Voltage Vin = 200; equation T*der(v)+ v = Vin*Command.signal[1]/10; end PWMVoltageSource; model DCMotor "DC Motor" extends TwoPin; extends Rigid; OutPort SensorVelocity(n=1); OutPort SensorCurrent(n=1); parameter MomentOfInertia J"Total Inertia"; parameter Resistance R"Armature Resistance"; parameter Inductance L"Armature Inductance"; parameter Real Kt"Torque Constant"; parameter Real Ke"EMF Constant"; AngularVelocity w "Angular velocity of motor"; AngularAcceleration a "Absolute angular acceleration of motor"; Torque tau_motor; RotFlange_b rotFlange_b; equation w = der(rotFlange_b.phi); a = der(w); v = R*i+Ke*w+L*der(i); tau_motor = Kt*i; J*a = tau_motor + rotFlange_b.tau; SensorVelocity.signal[1] = w; SensorCurrent.signal[1] = i; end DCMotor; block CommandSignalGenerator OutPort outPort(n=1); Real acc; equation if time <= 1 then acc =60; elseif time <3 then acc = 0; elseif time <4 then acc = -60; else acc = 0; end if; der(outPort.signal[1]) = acc; end CommandSignalGenerator; model DCMotorControlSystem Ground ground1; Inertia inertia1(J = 3, w(fixed = true)); DCMotor motor1(J = 1,R = 0.6,L = 0.01,Kt=1.8, Ke= 1.8,rotFlange_b(phi(fixed = true))); CommandSignalGenerator sg1; Controller con1; PWMVoltageSource PowerSource1; equation connect(sg1.outPort, con1.command); connect(con1.feedback, motor1.SensorVelocity); connect(con1.outPort, PowerSource1.Command); connect(PowerSource1.p, motor1.p); connect(motor1.rotFlange_b, inertia1.rotFlange_a); connect(PowerSource1.n, ground1.p); connect(ground1.p, motor1.n); end DCMotorControlSystem;
其次是写PID控制器模型,其代码如下
block Controller InPort command(n=1); InPort feedback(n=1); OutPort outPort(n=1); Real error; Real pout; Real poutIntegral; parameter Real Kp=2.1; parameter Real Ti=1.5; parameter Real Td=0.34; parameter Real Max_Output_Pos = 10; parameter Real Max_Output_Neg = -10; equation error=command.signal[1]-feedback.signal[1]; der(poutIntegral)=error/Ti; algorithm pout := Kp * (error+Td*der(error)+poutIntegral); if pout > Max_Output_Pos then outPort.signal[1] := Max_Output_Pos; elseif pout < Max_Output_Neg then outPort.signal[1] := Max_Output_Neg; else outPort.signal[1] := pout; end if; end Controller;
编译电机模型,时间选为5s
simulate( DCMotorControlSystem, stopTime=5 )
绘制电机的电流和转速参数图
plot({motor1.i,motor1.w})
其图形如下
由图看来,这个PID控制器对直流电机的调速效果良好,速度能准确的变化且没有波动和超调,但电流仍然存在超调,这个可以通过反复尝试不同的微分和积分项比例参数来减小或消除超调,使曲线更平滑。
时间: 2024-12-24 04:11:05