Why does Greyest not update my initial estimations?
21 views (last 30 days)
Show older comments
I'm trying to identify some parameters of a double inverted pendulum system. I have made the decision to first linearize the system around a point before trying to identify the different variables. On the physical setup I have ran an experiment with a chirp signal as input and also with zero input. When I use greybox estimation for both these setups/tests, my initial parameter guess doesn't get updated. So the parameter vector output of greyest(...) is just my initial guess. When I look at the optimization process, the costs don't really seem to change after the first step. What is exactly going wrong, I am not getting any errors and the only warning I get is the following:
"Warning: For transient data (step or impulse experiment), make sure that the change in input signal does
not happen too early relative to the order of the desired model. You can achieve this by prepending
sufficient number of zeros (equilibrium values) to the input and output signals. For example, a step
input must be represented as [zeros(nx,1); ones(N,1)] rather than ones(N,1), such that nx > model order.
> In idpack.utValidateEstimationData (line 105)
In idpack.utPrepareEstimationOptions (line 62)
In idgrey.validatePEMInputs (line 102)
In idgrey/greyest (line 49)
In iddata/greyest (line 35)
In TestScipt (line 41) "
Here is a screenshot of what the estimation process looks like:

This is the code I´m using to try and estimate or identify the variables
clear
close all
clc
%%
actual_parameters = [9.81, 0.142, 0.0382, 0.042, 0.0487,4352,1 0.000295,0.0499,0.00015,0.1,48101]; %of different test setup, so only use order of magnitude for the estimates.
load 'simlin/Linearized_theta2_only_50s.mat';
y = theta_measurements.data;
y = y(157:end,:); %First few seconds won't be used due to testing conditions
y(:,1) = y(:,1)-pi; %Working with linearized system, so need an angle offset.
u = zeros(length(y),1);
z = iddata(y, u, 0.01);%, 'Name', 'SecondPendulumOnly');
par = [9.81; 0.1; 0.01; 0.01; 0.01; 1000; 0; 0.01; 0.0001; 0.1; 1000];% initial estimates for [g, m1, m2, c1, c2, b1, b2, I1, I2, l1, km]
%% setting up init_sys
init_sys = idgrey(@lin_grey_dyn2, par, 'c');
init_sys.Structure.Parameters(1).Free = false;
for i = 2:length(par)
init_sys.Structure.Parameters(i).Free = true;
init_sys.Structure.Parameters(i).Minimum = 0;
init_sys.Structure.Parameters(i).Maximum = 10^6;
end
opt_grey1 = greyestOptions;
opt_grey1.InitialState = 'auto';
opt_grey1.Display = 'on';
% init_sys.Structure.Parameters(2).Minimum = 0;
% init_sys.Structure.Parameters(3).Minimum = 0;
% init_sys.Structure.Parameters(4).Minimum = 0;
% init_sys.Structure.Parameters(5).Minimum = 0;
% init_sys.Structure.Parameters(6).Minimum = 0;
% init_sys.Structure.Parameters(7).Minimum = 0;
% init_sys.Structure.Parameters(8).Minimum = 0;
% init_sys.Structure.Parameters(9).Minimum = 0;
% init_sys.Structure.Parameters(10).Minimum = 0;
% init_sys.Structure.Parameters(11).Minimum = 0;
%opt = greyestOptions('StabilityThreshold', 1.05);
%% estimating
sys_id = greyest(z, init_sys,opt_grey1);
estimated_parameters = getpvec(sys_id);
estimated_parameters = estimated_parameters(1:11);
%% Chirp signal setup, now estmated values are from previous test
load 'simlin/Linearized_chirp_f0.1_f1_A0.2_50s.mat';
I = theta_measurements.data;
y = I(:,1:2);
y(:,1) = y(:,1)-pi;
u = I(:,3);
z = iddata(y, u, 0.01, 'Name', 'FullPendulum');
%% set up system
%parameters = estimated_parameters;
parameters = [9.81; 0.1; 0.01; 0.01; 0.01; 1000; 0; 0.01; 0.0001; 0.1; 1000];
%parameters = [9.81, 0.142, 0.0382, 0.042, 0.0487,4352,1 0.000295,0.0499,0.00015,0.1,48101];
init_sys2 = idgrey(@lin_grey_dyn2, parameters, 'c');
init_sys2.Structure.Parameters(1).Free = false;
for i = 2:length(parameters)
init_sys2.Structure.Parameters(i).Free = true;
init_sys2.Structure.Parameters(i).Minimum = 0;
init_sys2.Structure.Parameters(i).Maximum = 10^5;
end
% init_sys2.Structure.Parameters(2).Minimum = 0;
% init_sys2.Structure.Parameters(3).Minimum = 0;
% init_sys2.Structure.Parameters(4).Minimum = 0;
% init_sys2.Structure.Parameters(5).Minimum = 0;
% init_sys2.Structure.Parameters(6).Minimum = 0;
% init_sys2.Structure.Parameters(7).Minimum = 0;
% init_sys2.Structure.Parameters(8).Minimum = 0;
% init_sys2.Structure.Parameters(9).Minimum = 0;
% init_sys2.Structure.Parameters(10).Minimum = 0;
% init_sys2.Structure.Parameters(11).Minimum = 0;
%% system identification
sys_id2 = greyest(z, init_sys2, opt_grey1);
estimated_parameters2 = getpvec(sys_id2);
estimated_parameters2 = estimated_parameters2(1:11);
%[g, m1, m2, c1, c2, b1, b2, I1, I2, l1, km]
%% comparings shit
opt_comp = compareOptions('InitialCondition','auto');
compare(z,sys_id2,opt_comp)
And this is the code for my ODE which calculates my A,B,C and D matrices
function [Ac, Bc, Cc, Dc] = lin_grey_dyn2(par, varargin)
% Extract parameters from the vector
g = par(1);
m1 = par(2);
m2 = par(3);
c1 = par(4);
c2 = par(5);
b1 = par(6);
b2 = par(7);
I1 = par(8);
I2 = par(9);
l1 = par(10);
km = par(11);
%[g, m1, m2, c1, c2, b1, b2, I1, I2, l1, km]
% syms theta1 theta2 theta1_dot theta2_dot u 'real' % state and input variables for differnetiation while setting up state matrices
%
% P1 = m1*c1^2 + m2*l1^2 + I1;
% P2 = m2*c2^2 + I2;
% P3 = m2*l1*c2;
% g1 = (m1*c1 + m2*l1)*g;
% g2 = m2*c2*g;
%
% M = [P1+P2+2*P3 *cos(theta2) P2+P3*cos(theta2);
% P2+P3*cos(theta2) P2];
%
% C = [b1-P3*theta2_dot*sin(theta2) -P3*(theta1_dot+theta2_dot)*sin(theta2);
% P3*theta1_dot*sin(theta2) b2];
%
% G = [-g1*sin(theta1)-g2*sin(theta1+theta2);
% -g2*sin(theta1+theta2)];
%
% Mtheta_dotdot = [km*u;0] - C*[theta1_dot;theta2_dot] - G;
% fx = [theta1_dot; theta2_dot; M\Mtheta_dotdot];
%
%
% % Linearization
%
% % Equilibrium point
% xe = [pi;0;0;0];
%
% % A
% x = [theta1;theta2;theta1_dot;theta2_dot];
% J_A = jacobian(fx,x);
% Ac = double(subs(J_A,x,xe));
%
% % B
% J_B = jacobian(fx,u);
% Bc = double(subs(J_B,x,xe));
%
% Cc = [1 0 0 0; 0 1 0 0];
% Dc = [0; 0];
syms theta1 theta2 theta1_dot theta2_dot u 'real'
P1 = m1*c1^2 + m2*l1^2 + I1;
P2 = m2*c2^2 + I2;
P3 = m2*l1*c2;
g1 = (m1*c1 + m2*l1)*g;
g2 = m2*c2*g;
M = [P1+P2+2*P3 *cos(theta2) P2+P3*cos(theta2);
P2+P3*cos(theta2) P2];
C = [b1-P3*theta2_dot*sin(theta2) -P3*(theta1_dot+theta2_dot)*sin(theta2);
P3*theta1_dot*sin(theta2) b2];
G = [-g1*sin(theta1)-g2*sin(theta1+theta2);
-g2*sin(theta1+theta2)];
Mtheta_dotdot = [km*u;0] - C*[theta1_dot;theta2_dot] - G;
fx = [theta1_dot; theta2_dot; M\Mtheta_dotdot];
% Linearization and discretization
% Equilibrium point
xe = [pi;0;0;0];
% A
x = [theta1;theta2;theta1_dot;theta2_dot];
J_A = jacobian(fx,x);
Ac = double(subs(J_A,x,xe));
% B
J_B = jacobian(fx,u);
Bc = double(subs(J_B,x,xe));
Cc = [1 0 0 0; 0 1 0 0];
Dc = [0; 0];
end
Answers (0)
See Also
Categories
Find more on Linear Model Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!