直流电机调速仿真作业

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了直流电机调速仿真作业相关的知识,希望对你有一定的参考价值。

直流电机调速仿真作业

左学敏 机卓1301 U201310892

一、 重写调速控制器模型Controller

使用速度环和电流环双环控制,原理图如下:

技术分享

现有模型中,仅使用速度环,且控制器内仅使用P控制。

首先,引入电流环,因为电流传感器测得电压值已经定义为SensorCurrent直接使用该变量。将控制器内反馈变量feedback改为两个反馈变量feedbackv和feedbacki,分别用于表示转速和电流的反馈值。

电流环和速度环均使用PI控制,分别定义常数Kp和Ki的值,列出相关方程,修改后控制器模型如下:

 

block Controller

InPort command(n=1);

InPort feedbackv(n=1);

InPort feedbacki(n=1);

OutPort outPort(n=1);

 

Real errorv;

Real errorvi;

Real errori;

Real errorii;

Real vout;

Real pout;

 

parameter Real Kp1=80;

parameter Real Ki1=15;

parameter Real Kp2=20;

parameter Real Ki2=5;

 

parameter Real Max_Output_Pos = 10;

parameter Real Max_Output_Neg = -10;

 

equation

 

errorv = command.signal[1] - feedbackv.signal[1];

errorv = der(errorvi);

vout = Kp1 * errorv + Ki1 * errorvi;

errori = vout - feedbacki.signal[1];

errori = der(errorii);

pout = Kp2 * errori + Ki2 * errorii;

 

 

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;

 

重写控制器后,由于控制器内额外增加了电流环的内容,所以在最后的调速系统DCMotorControlSystem中添加接口定义,修改后的代码为:

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.feedbackv, motor1.SensorVelocity);

connect(con1.feedbacki, motor1.SensorCurrent);

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;

 

进行参数整定,直到获得较理想的转速图和电流图,运行后图像为:

技术分享

此时,稳态速度误差较小,电流平稳变化,满足要求。

 

二、 提高要求——引入阻尼弹簧系统

电机和惯量负载通过阻尼弹簧系统相连,阻尼系数d=0.2,弹簧系数c=10。首先在单位定义模块新增两个新数据类型:

 

type DampingFactor = Real(quantity = "DampingFactor", unit = "N.m/(rad/s)");

type SpringConstant = Real(quantity = "SpringConstant", unit = "N.m/rad");

 

原模型中,电机和惯量负载通过法兰刚性连接,连接部分定义为Rigid,引入阻尼弹簧系统后,重新定义连接部分,新写了一个连接,定义为Dampingspring,其内容如下:

 

partial model Dampingspring

parameter DampingFactor d = 0.2;

parameter SpringConstant c = 10;

Angle phi;

Angle phic;

Angle phid;

equation

phi = phic + phid;

end Dampingspring;

 

本次控制中使用的是较为常见的弹簧 – 质量 – 阻尼模型,电机轴接弹簧,弹簧接惯量负载,惯量负载再接阻尼器。

模型中,phi对应电机轴转过角度,phic对应弹簧两端转过角度之差,phid对应阻尼器两端转过角度之差。

分别将惯量负载模型Inertia和电机模型DCmotor中引入的刚性连接Rigid模型改为阻尼弹簧模型Dampingspring,重写转矩平衡方程。

对于惯量负载模型Inertia

 

model Inertia "1D rotational component with inertia"

extends Dampingspring;

parameter MomentOfInertia J = 1 "Moment of inertia";

AngularVelocity w "Absolute angular velocity of component";

AngularAcceleration a "Absolute angular acceleration of component";

equation

w = der(phid);

a = der(w);

J*a = c*phic - d*w;

end Inertia;

 

对于电机模型DCmotor

 

model DCMotor "DC Motor"

extends TwoPin;

extends Dampingspring;

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;

equation

w = der(phi);

a = der(w);

v = R*i+Ke*w+L*der(i);

tau_motor = Kt*i;

J*a = tau_motor - c*phic;

SensorVelocity.signal[1] = w;

SensorCurrent.signal[1] = i;

end DCMotor;

 

控制器结构不变,调速系统接口定义稍作调整,如下:

 

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, phi(fixed = true));

CommandSignalGenerator sg1;

Controller con1;

PWMVoltageSource PowerSource1;

equation

connect(sg1.outPort, con1.command);

connect(con1.feedbackv, motor1.SensorVelocity);

connect(con1.feedbacki, motor1.SensorCurrent);

connect(con1.outPort, PowerSource1.Command);

connect(PowerSource1.p, motor1.p);

connect(motor1.phi, inertia1.phi);

connect(motor1.phic, inertia1.phic);

connect(PowerSource1.n, ground1.p);

connect(ground1.p, motor1.n);

end DCMotorControlSystem;

 

运行成功后,进行控制器参数整定,最终在Kp1=75Ki1=5Kp2=50Ki2=15时得到较理想图像,如下图:

技术分享

由图像可看出,增加了阻尼弹簧系统之后,电流变得不稳定,出现较大波动,转速则出现上漂现象,调大增益值Kp之后上漂现象有所缓解,但是电流值图像出现较多毛刺。

 

三、附完整代码

1. 仅重写控制器,未引入阻尼弹簧:

 

type ElectricPotential = Real;

type ElectricCurrent = Real(quantity = "ElectricCurrent", unit = "A");

type Resistance = Real(quantity = "Resistance", unit = "Ohm", min = 0);

type Inductance = Real(quantity = "Inductance", unit = "H", min = 0);

type Voltage = ElectricPotential;

type Current = ElectricCurrent;

 

type Force = Real(quantity = "Force", unit = "N");

type Angle = Real(quantity = "Angle", unit = "rad", displayUnit = "deg");

type Torque = Real(quantity = "Torque", unit = "N.m");

type AngularVelocity = Real(quantity = "AngularVelocity", unit = "rad/s", displayUnit = "rev/min");

type AngularAcceleration = Real(quantity = "AngularAcceleration", unit = "rad/s2");

type MomentOfInertia = Real(quantity = "MomentOfInertia", unit = "kg.m2");

 

type Time = Real (final quantity="Time", final unit="s");

 

connector RotFlange_a "1D rotational flange (filled square)"

Angle phi "Absolute rotational angle of flange";

flow Torque tau "Torque in the flange";

end RotFlange_a; //From Modelica.Mechanical.Rotational.Interfaces

 

connector RotFlange_b "1D rotational flange (filled square)"

Angle phi "Absolute rotational angle of flange";

flow Torque tau "Torque in the flange";

end RotFlange_b; //From Modelica.Mechanical.Rotational.Interfaces

 

connector Pin "Pin of an electrical component"

Voltage v "Potential at the pin";

flow Current i "Current flowing into the pin";

end Pin; //From Modelica.Electrical.Analog.Interfaces

 

connector PositivePin "Positive pin of an electrical component"

Voltage v "Potential at the pin";

flow Current i "Current flowing into the pin";

end PositivePin; //From Modelica.Electrical.Analog.Interfaces

 

connector NegativePin "Negative pin of an electrical component"

Voltage v "Potential at the pin";

flow Current i "Current flowing into the pin";

end NegativePin; //From Modelica.Electrical.Analog.Interfaces

 

 

 

connector InPort "Connector with input signals of type Real"

parameter Integer n = 1 "Dimension of signal vector";

input Real signal[n] "Real input signals";

end InPort; // From Modelica.Blocks.Interfaces

 

connector OutPort "Connector with output signals of type Real"

parameter Integer n = 1 "Dimension of signal vector";

output Real signal[n] "Real output signals";

end OutPort; // From Modelica.Blocks.Interfaces

 

 

partial model Rigid // Rotational class Rigid

"Base class for the rigid connection of two rotational 1D flanges"

Angle phi "Absolute rotation angle of component";

RotFlange_a rotFlange_a "(left) driving flange (axis directed into plane)";

RotFlange_b rotFlange_b "(right) driven flange (axis directed out of plane)";

equation

rotFlange_a.phi = phi;

rotFlange_b.phi = phi;

end Rigid; // From Modelica.Mechanics.Rotational.Interfaces

 

model Inertia "1D rotational component with inertia"

extends Rigid;

parameter MomentOfInertia J = 1 "Moment of inertia";

AngularVelocity w "Absolute angular velocity of component";

AngularAcceleration a "Absolute angular acceleration of component";

equation

w = der(phi);

a = der(w);

J*a = rotFlange_a.tau + rotFlange_b.tau;

end Inertia; //From Modelica.Mechanics.Rotational

 

partial model TwoPin // Same as OnePort in Modelica.Electrical.Analog.Interfaces

"Component with two electrical pins p and n and current i from p to n"

Voltage v "Voltage drop between the two pins (= p.v - n.v)";

Current i "Current flowing from pin p to pin n";

PositivePin p;

NegativePin n;

equation

v = p.v - n.v;

0 = p.i + n.i;

i = p.i;

end TwoPin;

 

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; // Rotational Flange_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;

 

 

 

class Resistor "Ideal linear electrical Resistor"

extends TwoPin; // Same as OnePort

parameter Real R(unit = "Ohm") "Resistance";

equation

R*i = v;

end Resistor; // From Modelica.Electrical.Analog.Basic

 

class Inductor "Ideal linear electrical Inductor"

extends TwoPin; // Same as OnePort

parameter Real L(unit = "H") "Inductance";

equation

v = L*der(i);

end Inductor; // From Modelica.Electrical.Analog.Basic

 

class Ground "Ground node"

Pin p;

equation

p.v = 0;

end Ground; // From Modelica.Electrical.Analog.Basic

 

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;

 

block Controller

InPort command(n=1);

InPort feedbackv(n=1);

InPort feedbacki(n=1);

OutPort outPort(n=1);

 

Real errorv;

Real errorvi;

Real errori;

Real errorii;

Real vout;

Real pout;

 

parameter Real Kp1=80;

parameter Real Ki1=15;

parameter Real Kp2=20;

parameter Real Ki2=5;

 

parameter Real Max_Output_Pos = 10;

parameter Real Max_Output_Neg = -10;

 

equation

 

errorv = command.signal[1] - feedbackv.signal[1];

errorv = der(errorvi);

vout = Kp1 * errorv + Ki1 * errorvi;

errori = vout - feedbacki.signal[1];

errori = der(errorii);

pout = Kp2 * errori + Ki2 * errorii;

 

 

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;

 

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.feedbackv, motor1.SensorVelocity);

connect(con1.feedbacki, motor1.SensorCurrent);

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;

 

 

simulate( DCMotorControlSystem, stopTime=5 )

 

 

plot({motor1.i,motor1.w})

 

 

2. 引入阻尼弹簧系统

 

type ElectricPotential = Real;

type ElectricCurrent = Real(quantity = "ElectricCurrent", unit = "A");

type Resistance = Real(quantity = "Resistance", unit = "Ohm", min = 0);

type Inductance = Real(quantity = "Inductance", unit = "H", min = 0);

type Voltage = ElectricPotential;

type Current = ElectricCurrent;

 

type Force = Real(quantity = "Force", unit = "N");

type Angle = Real(quantity = "Angle", unit = "rad", displayUnit = "deg");

type Torque = Real(quantity = "Torque", unit = "N.m");

type AngularVelocity = Real(quantity = "AngularVelocity", unit = "rad/s", displayUnit = "rev/min");

type AngularAcceleration = Real(quantity = "AngularAcceleration", unit = "rad/s2");

type MomentOfInertia = Real(quantity = "MomentOfInertia", unit = "kg.m2");

 

type Time = Real (final quantity="Time", final unit="s");

 

type DampingFactor = Real(quantity = "DampingFactor", unit = "N.m/(rad/s)");

type SpringConstant = Real(quantity = "SpringConstant", unit = "N.m/rad");

 

connector RotFlange_a "1D rotational flange (filled square)"

Angle phi "Absolute rotational angle of flange";

flow Torque tau "Torque in the flange";

end RotFlange_a; //From Modelica.Mechanical.Rotational.Interfaces

 

connector RotFlange_b "1D rotational flange (filled square)"

Angle phi "Absolute rotational angle of flange";

flow Torque tau "Torque in the flange";

end RotFlange_b; //From Modelica.Mechanical.Rotational.Interfaces

 

connector Pin "Pin of an electrical component"

Voltage v "Potential at the pin";

flow Current i "Current flowing into the pin";

end Pin; //From Modelica.Electrical.Analog.Interfaces

 

connector PositivePin "Positive pin of an electrical component"

Voltage v "Potential at the pin";

flow Current i "Current flowing into the pin";

end PositivePin; //From Modelica.Electrical.Analog.Interfaces

 

connector NegativePin "Negative pin of an electrical component"

Voltage v "Potential at the pin";

flow Current i "Current flowing into the pin";

end NegativePin; //From Modelica.Electrical.Analog.Interfaces

 

 

 

connector InPort "Connector with input signals of type Real"

parameter Integer n = 1 "Dimension of signal vector";

input Real signal[n] "Real input signals";

end InPort; // From Modelica.Blocks.Interfaces

 

connector OutPort "Connector with output signals of type Real"

parameter Integer n = 1 "Dimension of signal vector";

output Real signal[n] "Real output signals";

end OutPort; // From Modelica.Blocks.Interfaces

 

 

partial model Dampingspring

parameter DampingFactor d = 0.2;

parameter SpringConstant c = 10;

Angle phi;

Angle phic;

Angle phid;

equation

phi = phic + phid;

end Dampingspring;

model Inertia "1D rotational component with inertia"

extends Dampingspring;

parameter MomentOfInertia J = 1 "Moment of inertia";

AngularVelocity w "Absolute angular velocity of component";

AngularAcceleration a "Absolute angular acceleration of component";

equation

w = der(phid);

a = der(w);

J*a = c*phic - d*w;

end Inertia; //From Modelica.Mechanics.Rotational

 

partial model TwoPin // Same as OnePort in Modelica.Electrical.Analog.Interfaces

"Component with two electrical pins p and n and current i from p to n"

Voltage v "Voltage drop between the two pins (= p.v - n.v)";

Current i "Current flowing from pin p to pin n";

PositivePin p;

NegativePin n;

equation

v = p.v - n.v;

0 = p.i + n.i;

i = p.i;

end TwoPin;

 

model DCMotor "DC Motor"

extends TwoPin;

extends Dampingspring;

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;

equation

w = der(phi);

a = der(w);

v = R*i+Ke*w+L*der(i);

tau_motor = Kt*i;

J*a = tau_motor - c*phic;

SensorVelocity.signal[1] = w;

SensorCurrent.signal[1] = i;

end DCMotor;

 

 

 

class Resistor "Ideal linear electrical Resistor"

extends TwoPin; // Same as OnePort

parameter Real R(unit = "Ohm") "Resistance";

equation

R*i = v;

end Resistor; // From Modelica.Electrical.Analog.Basic

 

class Inductor "Ideal linear electrical Inductor"

extends TwoPin; // Same as OnePort

parameter Real L(unit = "H") "Inductance";

equation

v = L*der(i);

end Inductor; // From Modelica.Electrical.Analog.Basic

 

class Ground "Ground node"

Pin p;

equation

p.v = 0;

end Ground; // From Modelica.Electrical.Analog.Basic

 

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;

 

block Controller

InPort command(n=1);

InPort feedbackv(n=1);

InPort feedbacki(n=1);

OutPort outPort(n=1);

 

Real errorv;

Real errorvi;

Real errori;

Real errorii;

Real vout;

Real pout;

 

parameter Real Kp1=75;

parameter Real Ki1=5;

parameter Real Kp2=50;

parameter Real Ki2=15;

 

parameter Real Max_Output_Pos = 10;

parameter Real Max_Output_Neg = -10;

 

equation

 

errorv = command.signal[1] - feedbackv.signal[1];

errorv = der(errorvi);

vout = Kp1 * errorv + Ki1 * errorvi;

errori = vout - feedbacki.signal[1];

errori = der(errorii);

pout = Kp2 * errori + Ki2 * errorii;

 

 

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;

 

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, phi(fixed = true));

CommandSignalGenerator sg1;

Controller con1;

PWMVoltageSource PowerSource1;

equation

connect(sg1.outPort, con1.command);

connect(con1.feedbackv, motor1.SensorVelocity);

connect(con1.feedbacki, motor1.SensorCurrent);

connect(con1.outPort, PowerSource1.Command);

connect(PowerSource1.p, motor1.p);

connect(motor1.phi, inertia1.phi);

connect(motor1.phic, inertia1.phic);

connect(PowerSource1.n, ground1.p);

connect(ground1.p, motor1.n);

end DCMotorControlSystem;

 

 

simulate( DCMotorControlSystem, stopTime=5 )

 

 

plot({motor1.i,motor1.w})

以上是关于直流电机调速仿真作业的主要内容,如果未能解决你的问题,请参考以下文章

机电传动控制——直流电机调速仿真作业

直流电机调速仿真作业

直流电机调速仿真作业

《机电传动控制》——直流电机调速仿真作业

机电传动控制——直流电机调速仿真作业

直流电机仿真调速作业