简体   繁体   English

Model 机电系统预测控制 (MPC)

[英]Model Predictive Control (MPC) for electromechanical system

So I want to create an MPC controller for my seesaw-cart system .所以我想为我的跷跷板系统创建一个MPC controller 。 All the "grunt work" (getting equations of motion, state-space representation etc.) has been done, so I went into coding into MATLAB.所有“繁重的工作”(获取运动方程、状态空间表示等)都已完成,所以我开始编写 MATLAB。 Here's the following:以下是:

clc; clear all; close all;
yalmip('clear')

%% Parameters

a = 0.116553; % height of center mass of the pendulum, [m]
b = 0; % position of the weight B on the vertical rod (not taken into consideration)
c = 0.180047; % height of the center of mass of the cart, [m]
mA = 4.839; % mass of the pendulum, [kg]
mB = 0; % not taken into consideration
mC = 1; % mass of the cart, [kg]
g = 9.81; % gravity factor, [m/s^2]
kappa = 0.1; % coefficient of the viscous damping in the rotational joint
J = 0.68; % moment of inertia of the pendulum, [kgm^2]
Ke = 0.077; % motor constant of the EM force, [Vs^-1]
Kt = 0.077; % proportional moment motor constant, [NmA^-1]
Ra = 2.6; % electrical resistance, [ohm]
p = 1/3.71; % motor gearbox ratio
r = 7.7*10^(-3); % effective radius of the motor shaft, [m] 

%% Defining the continuous system

A = [0 1 0 0;
    (a*mA*g+b*mB*g)/(J+mB*b^2), -kappa/(J+mB*b^2), -mC*g/(J+mB*b^2), -Ke*Kt/(mC*(J+mB*b^2)*Ra*p^2*r^2);
    0 0 0 1;
    (a*mA*g+b*mB*g)/(J+mB*b^2)-g,  -kappa*c/(J+mB*b^2), -c*mC*g/(J+mB*b^2), -(J+mB*b^2+mC*c^2)*Ke*Kt/(mC*(J+mB*b^2)*Ra*p^2*r^2)];

B = [0; 
    Kt/(mC*(J+mB*b^2)*Ra*p^2*r^2); 
    0; 
    (J+mB*b^2+mC*c^2)*Kt/(mC*(J+mB*b^2)*Ra*p^2*r^2)];

C = eye(4); % check

D = 0;

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

%% Defining the discrete system

Ts = 10e-3; % sample time
sysD = c2d(sysC,Ts); % discrete time
Ad = sysD.A;
Bd = sysD.B;

%% Formulation of the MPC problem

[nx, nu] = size(B);

Q = eye(nx);
R = eye(nu);
N = 1000;

% Input constraints, maximum and minimum voltage
umin = -6; 
umax = 6;

% Still have to find this
xmin = [-deg2rad(10); -deg2rad(50); -0.5; -10];
xmax = [deg2rad(10); deg2rad(50); 0.5; 10];

uVar = sdpvar(repmat(nu,1,N),ones(1,N));
xVar = sdpvar(repmat(nx,1,N+1),ones(1,N+1));
constraints = [];
objective = 0;
ops = sdpsettings('verbose',0,'solver','quadprog');

for k = 1:N
    objective = objective + xVar{k}'*Q*xVar{k} + uVar{k}*R*uVar{k}; 
    constraints = [constraints, xVar{k+1} == Ad*xVar{k} + Bd*uVar{k}];
    constraints = [constraints , umin <= uVar{k} <= umax , xmin <= xVar{k+1} <= xmax];
end
controller = optimizer(constraints, objective,ops,xVar{1},[uVar{:}]);

%% Simulation of the linearized model

nSim = 1000;
x0 = [0; 0; 0; 0.05]; % initial values, check

time = 0:Ts:nSim*Ts;
x = zeros(nx,nSim+1);
u = zeros(nu,nSim);
x(:,1) = x0;
for i = 2:nSim+1
    disp(strcat(['Sim iter: ', num2str(i-1)]));
    uOpt = controller{x(:,i-1)};
    u(:,i-1) = uOpt(:,1);
    x(:,i) = Ad*x(:,i-1) + Bd*u(:,i-1);
end

%% Plot

figure;
subplot(4,1,1);
plot(time,x(1,:), 'LineWidth', 2, 'Color', 'red'); grid; ylabel('{\theta} (rad)'); title('States');
subplot(4,1,2);
plot(time,x(2,:), 'LineWidth', 2, 'Color', [0.6350, 0.0780, 0.1840]); grid; ylabel('$\dot{\theta}$ (rad/s)', 'Interpreter', 'latex');
subplot(4,1,3);
plot(time,x(3,:), 'LineWidth', 2, 'Color', [0.4940, 0.1840, 0.5560]); grid; ylabel('s (m)'); 
subplot(4,1,4);
plot(time,x(4,:), 'LineWidth', 2, 'Color',[0, 0.7, 0.9]); grid; ylabel('$\dot{s}$ (m/s)', 'Interpreter', 'latex'); xlabel('t (s)');

figure;
stairs(time(1:end-1),u, 'LineWidth', 2, 'Color',[1, 0.647, 0]); grid; ylabel('Ua (V)'); xlabel('t (s)'); title('Input');

So I was wondering for any suggestions on improvements.所以我想知道有关改进的任何建议。 What can I do to make my regulator more robust?我可以做些什么来使我的调节器更强大? Here are my outputs for this particular code:这是此特定代码的输出:

输入 状态

Note: I'm using YALMIP for the optimization part of the MPC.注意:我将 YALMIP 用于 MPC 的优化部分。

You lose feasibility after a few iterations,几次迭代后你就失去了可行性,

   sol = 
  struct with fields:

    yalmipversion: '20210331'
    matlabversion: '9.9.0.1524771 (R2020b) Update 2'
       yalmiptime: 0.1159
       solvertime: 0.2331
             info: 'Infeasible problem (QUADPROG))'
          problem: 1

K>> i

i =

     4  

Your MPC controller is thus badly tuned (too short horizon being the obvious start)因此,您的 MPC controller 调得很差(明显的开始范围太短)

Also, your definition of u is weird as it has length 4 instead of length N (thus meaning you have two trailing variables in u which never are used, leading to them having value Nan when you look at them)此外,您对 u 的定义很奇怪,因为它的长度为 4 而不是 N (这意味着您在 u 中有两个从未使用过的尾随变量,导致当您查看它们时它们具有值 Nan)

There are numerous MPC-examples in the tutorials which you should be able to use directly https://yalmip.github.io/example/standardmpc/教程中有许多 MPC 示例,您应该可以直接使用https://yalmip.github.io/example/standardmpc/

YALMIP-specific question are better asked at YALMIP 特定问题最好在

https://github.com/yalmip/YALMIP/discussions https://github.com/yalmip/YALMIP/discussions

https://groups.google.com/g/yalmip https://groups.google.com/g/yalmip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM