Discrete state-space representation in FPGA

Hello all,
My aim is to simulate a discrete state-space model is the cRIO FPGA (in order to use an observer).
I am currently trying to simulate it on my computer without using the discrete state-space VI from the Control Design and Simulation toolbox (because there is not state-space model VI for the FPGA). However my discrete state-space model representation does not work.
There is below the continuous state-space model:
Then I obtained the discretized model (using the zero-order-hold and t=0.01s):
Below is the discretized state-space model I designed (in order to design a similar model in the FPGA):
Here is the discrete state-space VI I'm using to compare the results:
The graph plots the state X1, which is infinitely increasing. However it should look like a first order, as you can see:
I understand why the state X1 is increasing like this, I know I'm missing something (integration saturation ?).
Thanks in advance
Regards!
PS: Does somebody know if implenting other controller than the PID is doable in the cRIO FPGA? I also asking myself about matrix inversion if I want to use the Kalman gain in my observer.
PS2: I apologize for my disorganized/unclear Labview files, I'm beginning with it.
Solved!
Go to Solution.
Attachments:
SS Discret Simulation.vi ‏544 KB
SS Discret Model.vi ‏21 KB

Hi,
I think the problem might be caused by rounding errors in your A and B matrices.  Have you tried getting it to display the values with greater precision?
Matlab calculates those values as:  A = [0.995, 0.009925; 0 0.99],  B = [2.488e-5; 0.004975]
Regards,
Ian

Similar Messages

  • Implementation of state space model with constant disturbance in mathscript and simulation

    I am new to LabVIEW and now I am doing a project realizing heater control in 8 rooms.
    I have realized the state space model in the form x(k+1)=x(k)+u(k) using mathscript (using c_to_d) and feed it into control and simulation loop for simulation.
    My problem is, in my project, I have to consider the disturbance from the other rooms. So the statespace model changed to be x(k+1)=x(k)+u(k)+E*d, where E is the matrix concerning the disturbance and d is the vector of disturbance. How could I implement the disturbance and discretize the new model in mathscript and which function to choose for the simulation. Discrete state space stochastic model?
    Appreciate your kind help.

    Hello, state space models in LabVIEW most of the time are being implemented by utilizing mathscript syntax
    in addition with some functions of the LabVIEW Control Design and Simulation Module.
    There´s a couple of nice tutorials for control design with these tools which I´d like to point you to as a first step.
    http://www.ni.com/white-paper/6368/en/
    http://www.ni.com/white-paper/6368/en/
    http://www.ni.com/white-paper/6435/en/
    http://home.hit.no/~hansha/documents/lab/Lab%20Work/MathScript/MathScript%20Lab%20-%20Part%20II.pdf
    regards
    Marco Brauner AES NIG

  • (Control Design & Simulation) State-Space block doesn't give output

    I've tried and tried but can't get the State-Space block module to give me a graph / output.
    I have no idea what the problem is and hope that somebody can help me. The numbers and calculations work in Matlab (Simulink) but i can't get it to simulate in labview. 
    Anybody got any ideas?
    Solved!
    Go to Solution.
    Attachments:
    Cavities.vi ‏30 KB
    Matrixes.vi ‏27 KB

    The problem is that you are assuming that LabVIEW executes left to right. Dataflow doesn't work this way. Your code as this:
    does not tell LabVIEW that it has to execute everything from left to right. What is happening is that he is executing the 3 'island' of code in parallel and, in this case, it will have 'empty' values. You have to remove the local variables to make this work and dataflow paradigm will execute your code from left to right, as you want. here is the code:
    Also, one more thing. Your input to the "CD Linear Simulation" is all zero. That means that you are trying to input zero input to a linear system, which will give you a zero output to the response. You probably do not want that since zero as input doesn't give you any more information. If you want to see how to system goes to zero after initial conditions, you should use "CD Initial Response". Or you should modify the input signal to the system. Please study this shipping example to understand how to use Linear Simulation and Initial Response:
    C:\Program Files (x86)\National Instruments\LabVIEW 2012\examples\Control and Simulation\Control Design\Time Analysis\CDEx Time Domain Analysis.vi
    Hope this helps...
    Barp - Control and Simulation Group - LabVIEW R&D - National Instruments

  • I have a state space model of a complex system. can anyone help me for implementi​ng MPC and e-MPC control for the same?????

    Hi everyone. I am new to the forums, so let me be as mprecise as possible. i know the basic functionalities of Labview with MPC block etc. However, i dont know how to go ahead with implementing MPC control for a system whose state space model i possess. can anyone help me out?? the problem is that i dont even know the approach or the starting point..

    This happens if you remove a program manually, but still have the registry keys to load files from this program.<br />
    You can use the MSConfig program or the Autoruns utility to see which software and services are getting started.
    *http://technet.microsoft.com/en-us/sysinternals/bb963902.aspx
    You can use registry editor and do a search (Ctrl+D) for imesh to see if you can locate the registry key(s) that launches this program on a reboot.
    Try to ask advice at a Windows oriented forum if you can't fix this.
    * http://www.bleepingcomputer.com/forums/ - BleepingComputer.com - Computer Help Forums
    * http://windowssecrets.com/forums/ Windows Secrets Lounge

  • Plot a state-space model

    Hi!
    I'm currently doing a project and I'm stuck and am in need for some help.
    I've done a state-space model that I'm using for this project. I've used Matlab (with and without simulink) to simulate this model and to plot its behaviour. But when I want to do this in LabVIEW, i get stuck.
    I dont want to use Mathscript 'cause then it would be using Matlab. 
    Does anybody have some ideas of how I can simulate and plot my state-space model from the  matrix parameters that i have?
    Look at the attachment, I want to plot x.
    Solved!
    Go to Solution.
    Attachments:
    State-Space Model.png ‏11 KB

    We have so many different ways to do this. Try to look at the following shipping examples:
    C:\Program Files (x86)\National Instruments\LabVIEW 2011\examples\Control and Simulation\Control Design\Model Construction\CDEx Creating SS Model from String Matrix.vi
    C:\Program Files (x86)\National Instruments\LabVIEW 2011\examples\Control and Simulation\Control Design\Model Construction\CDEx Rendering State-Space Equations.vi
    C:\Program Files (x86)\National Instruments\LabVIEW 2011\examples\Control and Simulation\Control Design\Time Analysis\CDEx Time Domain Analysis.vi
    C:\Program Files (x86)\National Instruments\LabVIEW 2011\examples\Control and Simulation\Simulation\Continuous Linear\SimEx state space.vi
    They show how you can use the product to create a State-Space (SS) model, show the rendered model on the front panel, do a linear simulation of a model and implement the state-space model in the Control and Simulation Loop, respectively.
    Notice also that we have an extensive amount of examples available for you. Hope this helps...
    Barp - Control and Simulation Group - LabVIEW R&D - National Instruments

  • Fpga disabled code using space on a FPGA

    I have a endable/disable diagram for emulation a FIFO during emulation mode. see atached picture.
    Does the disabled code use space on an FPGA ( I have not enough space on my 3Mgate FPGA for my program)
    I ask this because in some other part of the labview code I had compiling error (in VHDL code) in disabbled laview code.
    So it looks like if the disabled code takes space on the FPGA, is this the case?
    Frank
    Attachments:
    FIFO emulation.GIF ‏10 KB

    The code in disable structure doesn't take space on the FPGA, I use it often and it works.
    But in your case, i guess you should disable the for loop too. Because you have an empty loop that have an auto-index activated, and since this part is not disabled, it takes space on your FPGA.
    Hope this helps,
    Xavier

  • Can i change the value of the discrete states in EMI_CB_CalculateResetStates?

    can i change the value of the discrete states in EMI_CB_CalculateResetStates?
    The help of LabVIEW said that calculates the values to which to reset the states of an external model in it.But it didn`t said how to reset the discrete states in it.EMI_GetNextDiscreteStates said it can be called only within the EMI_CB_CalculateDiscreteStates function.So if the discrete states can be reset in EMI_CB_CalculateResetStates,how to do it?
    THX

    What is EMI_CB_CalculateResetStates?  If I knew what you were asking about I could give a little more inteligent answer.
    Kelly Bersch
    Certified LabVIEW Developer
    Kudos are always welcome

  • Control and design applying ramp input and plotting polar coordinates state space

    Hi
    I am trying to do a fairly simple state space task with Control Design and Simulation toolbox, however I am quite new at using this toolbox and need some help :-)
    I want to simulate a MIMO system of a 2-DOF robot arm. The robot arm consists of two links, the first link can rotate arround its origo at its end, and the next link moves inside the first link, in and out.
    So the two outputs is define as
    r (radius), which is the distance to the end-effector of the robot, and
    theta, which is the angular postion of the robot arm
    FYI, the two inputs are the currents send to the two motors controlling each link.
    I have set up A, B, C and D matrices in the attached VI file and putted it inside a simulation loop.
    Now I need help :-)
    I want to simulate the system when a ramp input is applied to the two inputs and plot the two outputs in a polar graph to show the end-effectors position when the system is just "let loose". The result should be a spiral (this is verified in MATLAB simulink).
    So please, I need help setting up the VI to do the above, can anyone help?
    Best regards
    Simon
    MSc. Eng.
    Message Edited by SCMAJA on 10-16-2009 11:21 AM
    LabVIEW 8.6 / 2009 / 2010
    Vision Development Module 8.6 / 2009 / 2010
    VBAI 3.6 / 2010
    Attachments:
    2 DOF robot with ramp input, polar coordinates plot, state space.vi ‏49 KB

    Hello Simon,
    The error comes from your Ramp Input. Since your system is MIMO, you would need to feed in a vector input to the system.
    I've changed your VI and attached here~!
    Andy Chang
    National Instruments
    LabVIEW Control Design and Simulation
    Attachments:
    MIMO Robot VI.vi ‏76 KB

  • State space of continuous systems with discrete mesurements

    Hello everyone,
    I want to implement some estimation techniques for continuous systems using discrete measurement but I'm having some trouble finding a communion between the two concepts in labview. Basically what I want to do is to solve the ODE for the system continuously, while just getting measurements every some time step (bigger that the ODE solver), then using both quantities for state estimation. Any advice on this? 
    Thank you,
    Juan E Tapiero

    Hi!
    Have you tried taking a look at the ODE solver.vi in LabVIEW? You can find more information on this VI here:
    http://zone.ni.com/reference/en-XX/help/371361G-01/lvanlsconcepts/ode_solvers_in_labview/
    Daniel G.
    Applications Engineer
    National Instruments

  • Is there a discrete, limited space for apps on the macbook air?

    I bought a new "air" for my wife and she loves it but ...  Yesterday a message popped up about insufficient space for apps. The box popped up repeatedly and could not be dismissed.  Today, on "spec" I deleted the Google Chrome app and restarted the machine and now it seems OK.  I want to know more.

    Darrell Mcdonald wrote:
    The computer has 128GB and when I checked I found about 100 available. However, that was after we got it started again.  When the message was appearing we could do nothing with the computer.
    I realize this is a small "hard drive" but she has had it only 2 weeks and it is not loaded up (yet).  What I really want to know is if discrete sections of the solid state drive have been pre-designated for certain tasks. Specifically is there a limited amount of space given to apps?
    No, there is just 'space' and you can put anything you want in it.
    How much space is free on your hard (ssd) drive
    Go to Apple>About this Mac>More Info>Storage and post the answer please

  • State space and noise models of a signal

    Hello
    I would like to apply Kalman filter to the signal in the attached file. I am asking how to generate the required matrices for the space state and noise models, which I should input to the filter.
    It is my first exposure to this subject,and I much appreciate simple explanations and a practical help.
    Thank you
    Attachments:
    Signal 2.xlsx ‏10 KB

    Yeah, unfortunately I don't think I'll be able to make it down to Austin for the conference.
    But more importantly, I don’t think I completely solved my curve fitting problem.  The curve fitting vi that I am using isn’t generating the output that I was expecting.  My goal is to simply add noise to a signal, then reconstruct the signal finding the best fit line/curve, which best represents the original signal.  Here is where I currently stand:
    The frequency of the new graph is too high.  A sinc function is produced, but it doesn’t share the same form as the original signal. 
    I've tried other options, such as the Levenberg-Marquardt method, but this is proving to be a bit difficult to understand.  I will attach the curve_fitting.vi and the Levenberg-Marquardt example that I was looking at.  I think the LM vi is very close to what I need, but I’m having trouble integrating my own numbers into the program, to generate the results that I need.  If anyone has any advice with the curve fitting, or any information that might 'dumb-down' some of the sub vi's in the Levenberg-Marquardt program model, it would help me out.
    Attachments:
    SimpleFit.zip ‏147 KB
    curve_fitting.vi ‏163 KB

  • State space time out

    hi all,
    I wanted to actually ask what is a good way for implementing a software timeout with in a state. Normally I use tick count for measuring the elaspsed time and once 5 or 10 seconds have been passed then time out condition occurs and state changes. As in the sample VI i am attaching. Now I know this is a crude form of time out so I was wondering what is actually a good programming practice to do such a task. Keep in mind I am not talking about event structure or some visa comunication (as i know they handle time out them self) ....purely software based .
    p.s its not home work . simply just something I am wondering over.
    Best Regards
    Regards
    Attachments:
    time out lv11.vi ‏8 KB
    time outlv12.vi ‏11 KB

    I usually just use the Elapsed Time express VI.  I have taken it and made my own version to use, but the concept is the same.  But it does really depend on what you are doing.  Most times, you have the option for the user to abort.  So you will want to bounce between a Check Time and Wait For Event states.  The Wait For Event state will have a timeout of its own (something like 100ms usually works well).  Instead of using the Tick Count, use the timestamp instead.  It will give you a larger range to work with and you won't have to worry about the overflow.  It is also easier to debug since you can see the actual time that it starts the current time.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Input for CD Linear Simulation.vi in a Simulation Loop

    Hi I'm new to LabView and I was trying to implement a real time estimator for a linear system, so a steady
    state gain is acceptable (estimator doesn't need to be adaptive). It will be
    implemented in real time target (cDAQ). The estimator will get the acquired
    data (there are 2 inputs and 1 output) from the real system.
     I have learned and tried few different ways to do it but finally decided to try using CD State
    Estimator.vi (standalone) in a Simulation Loop. My questions are:
     1. I found that the only way to use the estimator model with the acquired input is by
    using CD Linear Simulation.vi. Is there another alternative to do the
    estimation?
     2. However, with CD Linear Simulation.vi I had problem: According
    to the LabView help, if the input signals are more than 1, we have to specify
    the input as 2D array with smaller dimension as the number of channels and the
    larger dimension as number of points in each channel.
     While for every execution in the loop I will get only 2 x 1 data (see appended array 3 in the
    attached example file). How can I be able to use the measured data as the two
    inputs for the CD Linear Simulation.vi?
     Thank you.
    Attachments:
    2015_03_31_Test DAQ in sim loop.vi ‏299 KB

    Hi Mike,
    Thanks for the reply.
    I browsed through some examples and tried some things; here are the updates, maybe useful for others in the future.
    About the CD Linear Simulation.vi; In the example finder I found CDEx Kalman Filter.vi which uses CD Linear Simulation.vi to compare the estimation with real system states for two inputs.  The number of samples of the inputs was given as a constant (e.g. N samples), from which the array of N x 2 data is built and fed to CD Linear Simulation.vi. So up to now I can’t see a way of using CD Linear Simulation for feeding input to the estimator model built from CD State Estimator.vi in a “real time “ way.
    I look forward to hearing from anyone if it can be done.
    So, from here I tried another alternative to implement this real time estimator: using Discrete State Space Function. So I generate the estimator state space model in Mathscript and feed it to that function.
    I use kalman (mathscript) function to generate the estimator model.
    Interesting thing is, (although irrelevant with my original enquiry), that this kalman command seems not generate correct estimator model with multiple input (e.g. if in the original system there are inputs u1 and u2 with one output y, I expect the generated estimator model would have three inputs i.e. u1, u2, and y. But the generated estimator only has one input (??)).
    I remember that the kalman command from Matlab has the same problem which I neglected at that time.
    So this time in labView I also did the same thing as the last time, which is taking the gain generated from the same kalman command and build manually the A and B matrices of the estimator.
    I haven't browsed though to see if someone has used this kalman command for multi input system and noticed this. 
    Nevertheless, this alternative seems working well so hopefully it works well too with the RT target.
    Thanks.

  • How to make 1D Array but with only one element filled in Real Time

    Hi folks,
    here I am with another question. I want to implement an prediction discrete state space observer which is going to run on a CRIO real time target. I am going to do it just like in the example which comes with LV.
    I have some questions regarding the input and outputs which in the example those are "dummy".
    My model is a SISO model, but the function "Construct SS model" returns parameters (A,B,C,D Matrices) as 2D arrays, so once you connect the cluster model into the Discrete Observer model, it takes y and u as 1D arrays despite of the fact that there is a SISO model.
    I realized that the function I am using in the simulations, uses 1D arrays but with only one element filled:
    Does anyone knows how to implement such 1D arrays in Real Time? I guess the way to do it is preallocating one array of zeros of size 1, and then recirculating it through some SR, and replacing the element with my real input and output, but at the dummy.vi, they are using a simple "build array"
    function.

    Ok, I did it that way. But I am facing another problem right now...
    At some point the Discrete Observer return a NAN array, you will see the code in the code snippet?
    I get rid of that component by component, but the observer gets "stuck" in it. So my Control law is zero... but the state stimate is NAN.
    Also I am attaching the VI.
    I do not know why, since in the simulation program all runs well. any thoughts? Maybe the internal numeric precision of the State Space Model?
    Attachments:
    RT - Pole Placement + Complete Observer.vi ‏40 KB

  • Control Design and Simulation and DAQ

    I'm learning Control Design and Simulations. I have some questions about it.
    1. For System Identification use, we can find the transfer function/model of the system by feeding data measurement from the system. But, how long data do we need to be sufficent for Identification System to estimate the model? Until the get saturated value (steady state)? or any other intervals? What if the system is unstable? How will Identification System Toolkit estimate that case?
    2. For connecting to hardware, we just connect the clock in the simulation loop to the hardware? And the simulation loop will simulate the blocks inside once it got the trigger/data from the DAQ? what about the step time and solver? Do they follow the timing from hardware? or they will run on their own supplied values/clock?if we use USB DAQ, we can't have any clock from it (as far as I know it's because USB connection is not that stable for clocking since it might be any jitters or delays.) So, how do we configure the timing parameter for USB DAQ?
    3. There is possibility to convert model in transfer function to state space, how do we know the states inside that conversion?
    Any helps would be great...
    Thanks in advance...

    Dear Chin ho,
    After going through your questions I found some documentation which will be useful for you. But I you still have more questions, you can reply me any time.
    1- About the data and amount of it I couldn't find any info but maybe you can use the new functions in LV version 2009 and find your answer.
    Estimating States of Nonlinear Stochastic State-Space Models with Extended Kalman Filters
    In previous versions of the LabVIEW Control Design and Simulation Module, you can use the Discrete Kalman Filter function and the Continuous Kalman Filter function to estimate the states of a linear discrete or linear continuous stochastic state-space model, respectively. In the LabVIEW 2009 Control Design and Simulation Module, you can use the Continuous Extended Kalman Filter function and the Discrete Extended Kalman Filter function to estimate the states of a nonlinear continuous or a nonlinear discrete stochastic state-space model, respectively.
    The Continuous Extended Kalman Filter function and the Discrete Extended Kalman Filter function estimate model states of a partially observable plant based on noisy measurements. First, use the SIM Discrete Nonlinear Plant Model template VI or the SIM Continuous Nonlinear Plant Model template VI, located in the labview\templates\Control and Simulation directory, to define the system model. Then use the the Discrete Nonlinear Noisy Plant function or the Continuous Nonlinear Noisy Plant function to simulate the discrete or continuous nonlinear model, respectively, with the addition of noise. Finally, use the Continuous Extended Kalman Filter function or the Discrete Extended Kalman Filter function to estimate the states of your model.
    The Continuous Extended Kalman Filter function and the Discrete Extended Kalman Filter function linearize the nonlinear system either by calculating a Jacobian matrix internally or by using an external Jacobian matrix that you define. Use the SIM Continuous Jacobians template VI or the SIM Discrete Jacobians template VI, located in the labview\templates\Control and Simulation directory, to define an external Jacobian matrix.
    Refer to the LabVIEW Control Design User Manual, accessible by navigating to the labview\manuals directory and opening CD_User_Manual.pdf, for more information about estimating the states of nonlinear stochastic state-space models with extended Kalman filters.
    2- I think that I found a pdf document about this part of your question which will be helpful. If you would like to give your email address, I can send it to you.
    3- About this part you can check the help function in LabVIEW when you open the "CD Convert Transfer function To State-space" function in your front panel.
    I pasted some info about the mathematic part below.
    The LabVIEW Control Design and Simulation Module provides tools to study the dynamics of systems described by linear time-invariant (LTI) continuous and discrete models. You can create deterministic state-space, transfer function, and zero-pole-gain models. You also can create stochastic state-space models and the second-order statistics noise models.  You can use these forms to describe both single-input single-output (SISO) and multiple-input multiple-output (MIMO) systems.
    Continuous transfer function and zero-pole-gain models use the s variable to define time, whereas discrete transfer function and zero-pole-gain models use the z variable to define time.  Continuous state-space models use the t variable to define time, whereas discrete state-space models use the k variable to define time. 
    Deterministic State-Space Model
    Continuous
    x(t) = Ax("t) + Bu(t)
    y(t) = Cx(t) + Du(t)
    Discrete
    x(k + 1) = Ax(k) + Bu(k)
    y(k) = Cx(k) + Du(k)
    Stochastic State-Space Model
    Continuous
    x(t) = Ax(t) + Bu(t) + Gw(t)
    y(t) = Cx(t) + Du(t) + Hw(t) + v(t)
    Discrete
    x(k + 1) = Ax(k) + Bu(k) + Gw(k)
    y(k) = Cx(k) + Du(k) + Hw(k) + v(k)
    Second-Order Statistics Noise Model
    Q = E{w . wT} – E{w} . ET{w}
    R = E{v . vT} – E{v} . ET{v}
    N = E{w . vT} – E{w} . ET{v}
    where
    t is continuous time.
    k is the model sampling time multiplied by the discrete time step, where the discrete time step equals 0, 1, 2, …
    x is the model state vector.
    u is the model input vector.
    y is the model output vector.
    w is the process noise vector.
    v is the measurement noise vector.
    A is an n × n state matrix of the given model.
    B is an n × m input matrix of the given model.
    C is an r × n output matrix of the given model.
    D is an r × m direct transmission matrix of the given model.
    n is the number of model states.
    m is the number of model inputs.
    r is the number of model outputs.
    G is a matrix relating w to the model states.
    H is a matrix relating w to the model outputs.
    Q is the auto-covariance matrix of w.
    R is the auto-covariance matrix of v.
    N is the cross-covariance matrix between w and v.
    E{} denotes the expected value or the mean of the enclosed term(s).

Maybe you are looking for

  • How can I delete phantom User ID's in quota list?

    When I go to the Quotas tab in Server Admin I notice that there are about 40 User ID's (1631, 1632, etc.) listed along with the 150 user names on our Xserve. These User ID's correspond to user accounts that I deleted last year or at the beginning of

  • SSO fails - userPassword having special characters

    Hi, This is a tricky situation i'm handling. I did a insert of around 1000 users into Sun DS whose userPassword contained special characters accepted by DS. mainly + and ;. For seeing if authentication will work, i just created a user through AM Cons

  • I'm on iPhoto 5 and have a iPhone 4S ...

    I'm on iPhoto 5 and have a iPhone 4S ... to start with the photos I took downloaded to my mac with no problem at all but now when I connect my phone to mac it boots up iPhoto but doesn't download ...help?!

  • Script for auto recovery of standby node - Simple dataguard

    Hi. I have set up several solutions with Oracle SE and simple dataguard on linux. On physical standby, I have created a script which performs the recovery every 15 minuts: source /u01/app/oracle/sb_scripts/.profile_websb /u01/app/oracle/product/10.2.

  • How  to identfy  rows  with  same  column value

    Hi I have a table student id ( pkey) name class marks i need to check the existence of duplicate values like say the values are : id name class marks 1 alan 6 85 2 victor 4 97 3 alan 6 85 i need to know if there is any matching row in the table --- l