主要内容

Design MPC Controller for Position Servomechanism

This example shows how to design a model predictive controller for a position servomechanism usingMPC Designer

System Model

A position servomechanism consists of a DC motor, gearbox, elastic shaft, and load.

代表这个体制的微分方程m are

ω. ˙ L = k T J L ( θ. L θ. M ρ ) β L J L ω. L ω. ˙ M = k M J M ( V k M ω. M R ) β M ω. M J M + k T ρ J M ( θ. L θ. M ρ )

where,

  • Vis the applied voltage.

  • Tis the torque acting on the load.

  • ω. L = θ. ˙ L 是负载角速度。

  • ω. M = θ. ˙ M is the motor shaft angular velocity.

其余术语是恒定参数。

Constant Parameters for Servomechanism Model

Symbol

价值(SI单位)

Definition

kT

1280.2

Torsional rigidity

kM

10

Motor constant

JM

0.5

Motor inertia

JL

50JM

Load inertia

ρ

20

Gear ratio

βM

0.1

Motor viscous friction coefficient

βL

25

Load viscous friction coefficient

R

20

Armature resistance

If you define the state variables as

x p = [ θ. L ω. L θ. M ω. M ] T ,

then you can model the servomechanism as an LTI state-space system.

x ˙ p = [ 0 1 0 0 k T J L β L J L k T ρ J L 0 0 0 0 1 k T ρ J M 0 k T ρ 2 J M β M + k M 2 R J M ] x p + [ 0 0 0 k M R J M ] V θ. L = [ 1 0 0 0 ] x p T = [ k T 0 k T ρ 0 ] x p

这controller must set the angular position of the load,θ.L, at a desired value by adjusting the applied voltage,V

However, since the elastic shaft has a finite shear strength, the torque,T, must stay within the range|T| ≤ 78.5 Nm。此外,电压源将施加的电压物理地限制在范围内|V| ≤ 220 V

Construct Plant Model

Specify the model constants.

Kt = 1280.2;% Torsional rigidityKm = 10;%电机常数Jm = 0.5;% Motor inertiaJl = 50*Jm;% Load inertiaN = 20;% Gear ratioBm = 0.1;% Rotor viscous frictionBL = 25;% Load viscous frictionR = 20;%电枢抵抗

Define the state-space matrices derived from the model equations.

A = [ 0 1 0 0; -Kt/Jl -Bl/Jl Kt/(N*Jl) 0; 0 0 0 1; Kt/(Jm*N) 0 -Kt/(Jm*N^2) -(Bm+Km^2/R)/Jm]; B = [0; 0; 0; Km/(R*Jm)]; C = [ 1 0 0 0; Kt 0 -Kt/N 0]; D = [0; 0];

Create a state-space model.

plant = ss(A,B,C,D);

Open MPC Designer App

mpcDesigner

Import Plant and Define Signal Configuration

InMPC Designer, on theMPC Designertab, selectMPC Structure

在“通过导入”对话框的“定义MPC结构”中,选择plantplant model, and assign the plant I/O channels to the following signal types:

  • Manipulated variable — Voltage,V

  • Measured output — Load angular position,θ.L

  • Unmeasured output — Torque,T

ClickDefine and Import

MPC Designer将指定的工厂进口到Data Browser。这following are also added to theData Browser:

  • mpc1— Default MPC controller created usingplantas its internal model.

  • scenario1— Default simulation scenario. The results of this simulation are displayed in theInput ResponseandOutput Response情节。

Define Input and Output Channel Attributes

On theMPC Designertab, in theStructuresection, clickI/O Attributes

In the Input and Output Channel Specifications dialog box, for each input and output channel:

  • Specify a meaningfulNameandUnit

  • Keep theNominal Valueat its default value of0

  • Specify aScale Factorfor normalizing the signal. Select a value that approximates the predicted operating range of the signal:

    Channel Name Minimum Value Maximum Value Scale Factor
    电压 -220 V. 220 V 440
    这ta –π radians π.radians 6.28
    扭矩 -78.5 nm. 78.5 Nm 157

ClickOKto update the channel attributes and close the dialog box.

Modify Scenario To Simulate Angular Position Step Response

In theScenariosection,Edit Scenariodrop-down list, selectscenario1修改默认仿真方案。

In the Simulation Scenario dialog box, specify aSimulation durationof10seconds.

In theReference Signalstable, keep the default configuration for the first channel. These settings create aStepchange of1radian in the angular position setpoint at aTimeof1second.

对于第二个输出,在Signaldrop-down list, selectConstantto keep the torque setpoint at its nominal value.

ClickOK

这app runs the simulation with the new scenario settings and updates theInput ResponseandOutput Response情节。

Specify Controller Sample Time and Horizons

On theTuningtab, in theHorizonsection, specify aSample timeof0.1seconds.

对于指定的示例时间,Ts, and a desired response time ofTr= 2seconds, select a prediction horizon,p, such that:

T r p T s

这refore, specify aPrediction horizonof20

Specify aControl horizonof5

当您更新采样时间和地平线值时,Input ResponseandOutput Responseplots update automatically. Both the input voltage and torque values exceed the constraints defined in the system model specifications.

Specify Constraints

In theDesignsection, selectConstraints

In the Constraints dialog box, in theInput Constraintssection, specify theMinandMax操纵变量(MV)的电压值。

In theOutput Constraintssection, specifyMinandMaxtorque values for the unmeasured output (UO).

这re are no additional constraints, that is the other constraints remain at their default maximum and minimum values,—Infandinfrespectively

ClickOK

响应图更新以反映新的constraints. In theInput Responseplot, there are undesirable large changes in the input voltage.

Specify Tuning Weights

In theDesignsection, selectWeights

In the Weights dialog box, in theInput Weightstable, increase the manipulated variableRate Weight

这tuningWeightfor the manipulated variable (MV) is0。This weight indicates that the controller can allow the input voltage to vary within its constrained range. The increasedRate Weightlimits the size of manipulated variable changes.

由于控制目标是用于负载的角度,以跟踪其设定点,调谐Weighton the measured output is1。这re is no setpoint for the applied torque, so the controller can allow the second output to vary within its constraints. Therefore, theWeight关于未测量的输出(UO)是0, which enables the controller to ignore the torque setpoint.

ClickOK

这response plots update to reflect the increased rate weight. TheInput Responseis smoother with smaller voltage changes.

检查输出响应

In theOutput Response绘图,右键单击这taplot area, and select特征>Peak Response

峰值输出响应发生在3秒的时间,最大过冲3%。由于参考信号步长为1秒,因此控制器的峰值时间为2秒。

Improve Controller Response Time

Click and drag theClosed-Loop Performanceslider to the right to produce a moreAggressive回复。进一步将滑块拖动到右侧,控制器响应速度越快。选择滑块位置,使得峰值响应发生在2.7秒。

这final controller peak time is 1.7 seconds. Reducing the response time further results in overly-aggressive input voltage changes.

生成和运行MATLAB脚本

In theAnalysissection, click theExport Controllerarrow

UnderExport Controller, click生成脚本

In the Generate MATLAB®脚本dialog box, check the box next toscenario1

Click生成脚本

这app exports a copy of the plant model,plant_C,到MATLAB工作区以及仿真输入和参考信号。

Additionally, the app generates the following code in the MATLAB Editor.

%% create MPC controller object with sample timempc1 = mpc(plant_C, 0.1);%% specify prediction horizonmpc1.PredictionHorizon = 20;%% specify control horizonmpc1.controlhorizo​​n = 5;%% specify nominal values for inputs and outputsmpc1.Model.Nominal.U = 0; mpc1.Model.Nominal.Y = [0;0];%% specify scale factors for inputs and outputsmpc1.MV(1).ScaleFactor = 440; mpc1.OV(1).ScaleFactor = 6.28; mpc1.OV(2).ScaleFactor = 157;%% specify constraints for MV and MV Ratempc1.MV(1).Min = -220; mpc1.MV(1).Max = 220;%% specify constraints for OVmpc1.OV(2).Min = -78.5; mpc1.OV(2).Max = 78.5;%% specify overall adjustment factor applied to weightsbeta = 1.2712;%%指定权重mpc1.Weights.MV = 0*beta; mpc1.Weights.MVRate = 0.4/beta; mpc1.Weights.OV = [1 0]*beta; mpc1.Weights.ECR = 100000;%% specify simulation optionsoptions = mpcsimopt(); options.RefLookAhead ='离开'; options.MDLookAhead ='离开'; options.Constraints ='on'; options.OpenLoop ='离开';%% run simulationsim(mpc1, 101, mpc1_RefSignal, mpc1_MDSignal, options);

In the MATLAB Window, in theEditortab, selectSave

Complete the Save dialog box and then clickSave

In theEditortab, clickRun

这script creates the controller,mpc1, and runs the simulation scenario. The input and output responses match the simulation results from the app.

Validate Controller Performance In金宝app

If you have a Simulink®系统模型,您可以模拟您的控制器并验证其性能。金宝appSimulink功能不受支持金宝appMATLAB Online™

Open the model.

Open_System('mpc_motor')

This model uses anMPC Controller阻止控制伺服机构厂。这Servomechanism Modelblock is already configured to use theplantmodel from the MATLAB workspace.

角度参考source block creates a sinusoidal reference signal with a frequency of0.4rad/sec and an amplitude ofπ.

Double-click theMPC Controllerblock.

In the MPC Controller Block Parameters dialog box, specify anMPC Controllerfrom the MATLAB workspace. Use thempc1controller created using the generated script.

ClickOK

At the MATLAB command line, specify a torque magnitude constraint variable.

tau = 78.5;

这model uses this value to plot the constraint limits on the torque output scope.

In the Simulink model window, clickRunto simulate the model.

In the角度scope, the output response, yellow, tracks the angular position setpoint, blue, closely.

See Also

||

Related Topics