From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Kalman Gain: Error 41653 in Control Design and Simulation: Number of Rows in G does not equal the number of states in the system model

I have the following Problem while starting the VI Kalman Gain:

 

"Error -41653 occurred at NI_CD_Stochastic Systems.lvlib:cd_verify G and H.vi
Possible reason(s):

Control Design and Simulation:  The number of rows in G does not equal the number of states in the system model.

Complete call chain:
     NI_CD_Stochastic Systems.lvlib:cd_verify G and H.vi
     NI_CD_Stochastic Systems.lvlib:CD Convert Deterministic to Stochastic Model.vi
     NI_CD_State Feedback Control.lvlib:cd_Kalman Gain (Deterministic).vi
     State_Space_4_4.vi"

 

I have created the state space with the "CD Construct State-Space Model VI". The matrices for the input of this VI have the following structures:

A 78x78

B 78x2

C 1x78

D 1x2

Beside the state space wire, the "Kalman Gain VI" is connected to the matrix Q with a size of 1x1 and R with a size of 1x1. The Klaman Gain VI also needs the input G which is also of a 1x1 structure.

From my mind it is neccessary that G and Q have to be from the same dimension. So how can i fix that error?

 

Unbenannt.jpg

 

 

0 Kudos
Message 1 of 26
(3,539 Views)

For this state-space size, your covariance matrices Q matrix has the size n x q and the R matrix has r x q. G also has to have n x q, where n is the number of states (78 for your case) and q is the length of the process noise vector (w) (it depends of your noise vector) and r is the number of outputs ( 1 in your case) .

 

Please use chapter 16 for how to setup your experiment:

http://www.ni.com/pdf/manuals/371057g.pdf

 

Also, please look at this reference for the sizes of stochastic models:

http://zone.ni.com/reference/en-XX/help/371894G-01/lvcdsimshrd/model_definitions/

 

Also, I would advice to use the functions "CD Construct Noise Model" to define the noise system. This is function can provide yoiu more information of what can be incorrect:

http://zone.ni.com/reference/en-XX/help/371894G-01/lvctrldsgn/cd_construct_noise_model_vi/

 

And I think you'd want to use the CD Kalman Gain (Stochastic) instance instead of the deterministic instance since you can first use "CD Construct Stochastic Model" and then use the Kalman Gain to evaluate it:

http://zone.ni.com/reference/en-XX/help/371894H-01/lvctrldsgn/cd_construct_stochastic_model_vi/

http://zone.ni.com/reference/en-XX/help/371894G-01/lvctrldsgn/kalman_gain/

 

 

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 2 of 26
(3,517 Views)

Why do you think that i need a stochastic model?

I want to transfer a control system from a matlab/simulink model to labview to  use it for controlling a compactrio controller. From Matlab/Simulink i only have a determenistic continuous state space model like:

I don't know where to get the process noise vector or measurement noise vector from.

How do you think does the CD Construct Noise Model help to find out what is incorrect?

0 Kudos
Message 3 of 26
(3,493 Views)

If I change the matrix size of G from 1 to 78 the following error occures:

 

"Error -41651 occurred at NI_CD_Stochastic Systems.lvlib:cd_verify m Q R N.vi
Possible reason(s):

Control Design and Simulation:  The dimensions of Q are not equal to the dimension of the process noise.

Complete call chain:
     NI_CD_Stochastic Systems.lvlib:cd_verify m Q R N.vi
     NI_CD_Stochastic Systems.lvlib:CD Verify Noise Model.vi
     NI_CD_Stochastic Systems.lvlib:CD Construct Noise Model (Numeric).vi
     NI_CD_State Feedback Control.lvlib:cd_Kalman Gain (Deterministic).vi
     State_Space_4_4.vi"

0 Kudos
Message 4 of 26
(3,489 Views)

..

0 Kudos
Message 5 of 26
(3,488 Views)

In reviewing my previous post, I noticed I've made a mistake on the sizes. The G matrix is dependent on how many 'noise' channels we have (defined by w). This gives you the relationship beween noise and states, so the size is n x w (states by noise to states). Then Q and R are the convariance matrices. They are 'square' and need to match the size of noise input (to states) and noise to the output. So, for your case, if you have 1 noise signal and 1 output, then you should have a 1x1 matrix with the value that you defined.

 

When I was saying that you should make your model stochastic was because, although you have A,B,C,D matrices defined, you also have a G matrix which represents the stochastic. You can do what you did or you can try to define a stochastics model directly. If you prefer the first option, that is supported too.

 

Here is an example that shows the size of the matrices:

 

Kalman size.PNG

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 6 of 26
(3,470 Views)

I have considered your suggestion and implemented it like the following picture shows.

Matrix G has a diagonal structure with "1" and a size of 78x78.

Q_kalman has a diagonal structure and a size of 78x78.

 

 

Unbenannt.jpg

 

 

But i am still not sure if it works well because the "Kalman Gain.vi"does not run on its own. There are no matrices shown and

"NI_CD_State Feedback Control.lvlib:cd_Verify Q R N G H.vi<append>
<b>Complete call chain:</b>
     NI_CD_State Feedback Control.lvlib:cd_Verify Q R N G H.vi
     NI_CD_State Feedback Control.lvlib:cd_Kalman Gain (Deterministic).vi"

is shown as error out.

Unbenannt2.jpg

0 Kudos
Message 7 of 26
(3,424 Views)

corleone13375,

 

Please look at my picture before. The size of G is 78 x 1 (since you have 78 states and 1 channel with noise on states). Your Q and R are the covariance matrices. they have to be 'square' and depend on the number of noise signals you have. In yoiu case, I think you just need to get both elements with 1x1. So, your R is good and your Q has problems.

 

Anyway, if after this you still have problems, please attach your VI to this post and tell which version of LabVIEW you are using and I would be happy to fix for you.

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 8 of 26
(3,396 Views)

I have tried to set the size of Q to 1x1, but an error occurred. (Error -41651 occurred at NI_CD_Stochastic Systems.lvlib:cd_verify m Q R N.vi). Because of this, i changed the size to 78x1. Now the VI runs as a whole but the single "Kalman Gain.VI" shows an error.

 

I am using Labview 2013 Service Pack 1, Version 13.0.1f2 (32-bit)

0 Kudos
Message 9 of 26
(3,366 Views)

So, I was able to modify your code to make it work: here are the changes:

a. Q matrix incorrect size: The Create Matrix, when you try to use in "diagonal" mode, it will not use the "matrix size" to define the size of the output matrix, but the dimension of you vector. In your case, you had the dimension of 78 on the vector. I just made it 1 for your application.

b. G matrix incorrect size: in your model you have 78 states and 1 'noise' to the states. So, you should have created a column matrix with ones.

 

With those two changes, you will be able to get the function running, BUT it will generate the following error:

Error -41626 occurred at NI_CD_State Feedback Control.lvlib:cd_Verify Q R N G H.vi

Possible reason(s):

Control Design and Simulation: Nbar is not valid because the matrix [Qbar - Nbar.inv(Rbar).Nbar'] is not positive semi-definite.

 

Which means that the computation of this gain will not be stable. If you really want to produce a result, you can try to temporarily change this value on the "Kalman Gain (Deterministic).vi" to 1E-8 and this should provide you a result. However, you will notice that the conditioning of this results are not good.

Kalman capture.JPG

 

Now, on the other hand, if you think you do not have noise signal applied to the states, then you can make the matrices G and Q 'empty', which indicates that you have only noise on the output, and then you will be able to obtain gains for your system.

In attachment you have your VI modified with both behaviors.

 

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 10 of 26
(3,317 Views)