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

On your design function, you have some other problems too.

 

For this code, here:

d.PNG

 

Your stochastic state-space model is already discrete (you used 0.1666... as sampling time). If your model is continuous, then you have to NOT wire the sampling time to it and use the CD Convert Continuous Stochastic to Discrete function to convert. Of course, in this case you can just remove the 'Convert' function.

 

On the function:

ddd.PNG

 

You are feeding a Discrete Stochastic State-space model. This will also generate an error. In this case, you MUST use the LQR instance and not the Discretized LQR.

 

So, in short, you design code would just work if when you created the Stochastic State-Space as a Continuous System (Sampling time equal to zero) and then, do the operations that you've done afterwards. That would just work (if the size is correct). However, since you defined a dT different than zero, then the Create function makes it a discrete model and everything afterwards would not make sense.... 

 

Hopefully this helps with your design code...

 

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 21 of 26
(1,246 Views)

One more thing: part of the problem is the 'size' of your noise matrix. For example, if you look at the function, the sizes are defined by the number outputs and noise signal and not state. So, for you case, which apparently it is 1 output and 1 noise matrix (G has only one column), then here is the expected Q and R for Kalman. Basically, your Q and E{w} had an extra dimension.

 

dddd.PNG

 

This and removing the 'sampling time' from the Create Stochastic State-Space model would avoid any error on your design.

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 22 of 26
(1,243 Views)

Hey Barp,

 

Again, thanks for taking the time to look through the code.

 

I made the changes you mentioned here:     Soft_Robot_Model .

 

But I have a few further questions. For example, you said 


@Barp wrote:

One more thing: part of the problem is the 'size' of your noise matrix. For example, if you look at the function, the sizes are defined by the number outputs and noise signal and not state. So, for you case, which apparently it is 1 output and 1 noise matrix (G has only one column), then here is the expected Q and R for Kalman. Basically, your Q and E{w} had an extra dimension.

 

dddd.PNG

 

This and removing the 'sampling time' from the Create Stochastic State-Space model would avoid any error on your design.


The errors are not there no more like you rightly pointed out but why should the KF Q matrix by 1 X 1? The function says Q is based on the length of the noise vector {=2). I believe it is Chapter 16 of your CD Control and Sim module user manual that says Q = q x q matrix where q = "length" of the noise vector (not # of columns). I tried your suggestion with one 1 X 1 matrrix and the code still runs.

 

What I fail to understand is why the Kalman filter does not run within the timed loop and why I am not getting any errors despite the KF not updating. BTW, I am implementing the algorithm on a real time target (NI-myRIO). Every other portion of the code runs except for the KF part. Is the Discrete KF not supposed to work on RT targets?

 

Also, in my penultimate post (the other hard-coded LQR gain code), the code runs great on RIO. But when I probe the KF output wired, nothing is going on. This is repeated in the posted link in this post. I think I am doing everything right. But for some reason which I fail to catch, the KF is not working in while/timed/control and simulation loops.

 

Could you try running the code on a RIO when you have the time please?

 

I will just like to confirm this is not a RIO issue in case of future projects.

 

Thank you!

 

 

0 Kudos
Message 23 of 26
(1,224 Views)

Lexicondi,

 

Here are some more comments:

 

If you 'noise vector' is 2, then you G matrix has to be updated accordingly. Right now, the G matrix is only '1' column, which would indicate a 1 noise signals. The important is to have all the 'sizes' consistent (otherwise, the error woudl happen, as you are now very familiar with it).

 

About the manual, when it say "Length of process noise vector w", it means that how many noise 'signals' you are adding to the system. For example, as far as I could see, you have one noise signal. If you have two, then you q would be 2, and for eample, G would also have to have 2 columns. In short, when we say 'length', we means how many noise signals we have. Although, I do agree that wording is a bit confusion...

 

The Kalman Filter works on any of our targets, as the cRIO. IF you are having problems, it is most likely just a problem with how the parameters are 'entered' into the function. If any error happen, the KF will NOT update. So, you need to have the correct conditions for it to work properly... Although I have to say, getting the right size can be tricky, as you are experiencing right now...

 

Probes and cRIO can be difficult to make it work correctly. Remember that when you probe, we have to stablish communication between host and target and have the right channels. So, a better way to accomplish this is to create a indicator from the output of the KF on the front panel, and then try to see if you can look at the parameters and don't use the 'probe'. The front panel communication should be more reliable.

 

Hopefully now I was able to give a better idea in how to use this function.... 🙂

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 24 of 26
(1,204 Views)

It's now updating. You guys probably need to tidy up the CD User Manual for the KF.

 

Q is a {1 X 1} matrix for the KF even though my state space model is of two states. But my output is 1. I do not see why Q had to be a {1 X 1} matrix given that Q is the noise model built into the state transition matrix x(k + 1) . Same goes for R.

 

This has been an uncomfortable journey and a tweaking of the choice of words in your manual such as "length" when you actually meant number of noise vectors would help minimize the gargantuan calamity of error 41655 and such that I faced and possibly many others would face in the future.

 

Thanks anyway, Barp. You've been very helpful indeed. I am leaving the link to the code herre in case someone wants to find out how I made it work in the future (https://github.com/SeRViCE-Lab/ACCCodes/blob/master/Soft_Robot_Model_Conf.vi).

 

Cheers!

 

 

0 Kudos
Message 25 of 26
(1,189 Views)

Lexicondi,

 

Yes, the wording and the sheer size of number of matrix can be a problem for using the KF. I will try to make sure this feedback is sent to the right people.

 

As I said before, the Q matrix in KF is different than the Q matrix in LQR. That is part of the confusion about sizes too. The Q and R matrix for KF are 'auto-covariance' matrices that are based on the number of noise signals to w and v and N is the cross-covariance matrix that depends on size of w and v. So, no states involved, different than LQR. But probably we should have used different symbols for it, just to make sure such confusion would not happen again.

 

Your feedback about the error is noted too. I personally run into this problem before and that is the reason I created those panels in the configuration of the Discrete Kalman Filter. The idea is that, if you define the sizes first, then the matrices would be automatically created for you and, then, you just need to enter the values with the sizes defined.

 

Hope you can make your application work well now. All the best

 

 

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 26 of 26
(1,168 Views)