mpcmove command for real time application

I am trying to use MATLAB's mpcmove function to calculate optimal control actions for a real time application (controlling level in a tank). My process variable values (ym) are being read from the plant using OPC. I then feed these values into the mpcmove command, calculate the new u(k) and then output this to my manipulated variable in the field. I have tested this and my mpcmove command only seems to output my lower constraint. I am not sure if there is an issue with my methodology as far as using OPC to try and achieve control or if there is maybe an issue using mpcstate for the mpcmove command.
If anyone had any ideas as to what I was doing wrong it would be greatly appreciated. I have attatched my MATLAB code to see exactly what I am doing. I use MATLAB's tic and toc function to run a while loop for a pre-determined amount of time.
% This MATLAB code will connect with the Experion Pilot plant server PPserver1
% via a OPC connection and control the level in CSTR3 using PP_681.
clear
clc
% ======================== Setup OPC Connection ===========================
% Client and server configuration
data_access = opcda('ppserver1', 'HWHsc.OPCServer');
% Connect to the above server data_access
connect(data_access);
% Set up group for CSTR3 Temp transmitter control module TT_663
temp_CSTR3 = addgroup(data_access, 'TT_663');
PV_temp_CSTR3 = additem(temp_CSTR3, 'TT_663.TT_663.PV', 'double');
% Set up group for CSTR3 Level transmitter control module LT_667
level_CSTR3 = addgroup(data_access, 'LT_667');
PV_level_CSTR3 = additem(level_CSTR3, 'LT_667.LT_667.PV', 'double');
% Set up group for CSTR1 Steam valve control module FCV_622
steam_CSTR3 = addgroup(data_access, 'FCV_662');
PV_steam_CSTR3 = additem(steam_CSTR3, 'FCV_662.FCV_662.PV', 'double');
% Set up group for Drain pump control module PP_REF_681
drain_CSTR3 = addgroup(data_access, 'PP_REF_681');
PV_drain_CSTR3 = additem(drain_CSTR3, 'PP_REF_681.PP_681.PV', 'double');
% Set up group for Drain pump control module PP_REF_681
drain_CSTR3_on = addgroup(data_access, 'PP_OFF_681');
PVFL_drain_CSTR3 = additem(drain_CSTR3_on, 'PP_OFF_681.PP_ON_OFF.PVFL', 'double');
% Set up group for Drain pump control module PP_REF_681
CSTR3_agitator_on = addgroup(data_access, 'AG_661');
PVFL_agitator_CSTR3 = additem(CSTR3_agitator_on, 'AG_661.AG_ON_OFF.PVFL', 'double');
%================== Model Predictive Control Setup ========================
% LTI model for CSTR3 Level and Product Pump
plant_model = ss(tf(-0.297, [1 0]));
% Design MPC Controller using mpc command
Ts = 0.1; % Controller sample time
P = 20; % Prediction horizon
M = 6; % Control horizon
Weights.MV = 0.5; % Input weighting factor
Weights.OV = 1; % Output weighting factor
% MV.RateMin = -10; % Minumum rate of change of manipulated variable
% MV.RateMax = 10; % Maximum rate of change of manipulated variable
MV.Min = 0; % Upper constraint on MV
MV.Max = 100; % Lower constraint on MV
mpccontroller = mpc(plant_model, Ts, P, M, [], MV);
% mpccontroller.plant.Nominal.U = 5; % Assigns initial/steady state value to input
% mpccontroller.plant.Nominal.Y = 1; % Assigns initial/steady state value to output
xstate = mpcstate(mpccontroller); % Initial state of the controller for use in mpcmove command
set_point = 80; %Setpoint/reference signal for mpcmove command
% Modify MPC upper bound for simulation
MPCopt = mpcmoveopt; % mpcmove options
MPCopt.MVMin = 2; % Lower constraint for input - mpcmove command
MPCopt.MVMax = 40; % Upper constraint for input - mpcmove command
% ======================= Define Variables ================================
sim_time = 30; % Loop time in seconds
turn_on = 1; % Turning on pump/agitator
turn_off = 0; % Turning off pump/agitator
iteration = 0;
PV_array = [];
write(PVFL_drain_CSTR3, turn_on) % Turns on pump for control
tic
% ====================== Implement Control via OPC ========================
while toc < sim_time % this while loop will run for sim_time
iteration = iteration + 1;
% Setpoint changes according to toc counter
if toc > 180
set_point = 85;
elseif toc > 360
setpoint = 75;
elseif toc > 540
setpoint = 80;
end
current_level = read(PV_level_CSTR3); %Reads current level via OPC
PV_array = [PV_array; [current_level.Value]];
ym = PV_array(iteration,:);
[MV, info] = mpcmove(mpccontroller, xstate, ym, set_point, [], MPCopt); % Calculate control action
xstate.LastMove = MV;
new_control_action_level = MV;
if new_control_action_level > 40 % if statement incase constraints did not work
new_control_action_level = 40;
elseif new_control_action_level < 1
new_control_action_level = 1;
end
write(PV_drain_CSTR3, new_control_action_level); % Writes control action to PP_681
display = [ym new_control_action_level set_point toc]; % Displays current process values
disp( ' Level Pump_OP Setpoint Time ' )
disp(display) % Displays current process values
pause(1);
end

Risposte (0)

Tag

Richiesto:

il 17 Ott 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by