Labview Control And Simulation Loop

2 views
Skip to first unread message

Jamie Swearengin

unread,
Aug 4, 2024, 5:20:22 PM8/4/24
to eanmiinacco
TheWhile Loop is LabVIEW is used to just 'repeat' the operation inside the loop until the boolean is change to ON. It does not have notion of time or, the most important, it does not have a solver unless if you code this up. You can use 'wait until next ms' to enforce time and, then, you can try to do integration by any method obtained in text book.

Now, the Control and Simulation loop was designed to solve nonlinear equations. It has a 'solver' under the hood that evaluate the expressions inside the loop. It also has notion of time and it keep track of several states. Also, it allows the signal flow feedback where this would be a broken wire in LabVIEW dataflow. ( -XX/help/371894G-01/lvsim/sim_simulation_loop/). One more thing: if you are using simulation functions (from the Simulation Palette), most of those functions can only be dropped inside the SIM loop.


So, in general, if you do not have any Simulation function (like the integrator) or you don't need to solvers, you should just use the for loop. We have several examples in PID and Fuzzy Logic that don't require the simulation loop since they are solved by using simple discrete time-steps and we used pure LabVIEW code for doing simulation. However, as you start to get more complex system, you will notice that discrete time-steps could not be good enough to solve complex plants, so then you would need to model and use the Control and Simulation loop.


One more thing... you information about While loop is not incorrect, but it would need a lot of coding to make this simulation to work (you have to develop your own solver). The Control and Simulation loop help you to have this coded for you and you can just focus on the nonlinear equation to be solved.


Of course, this is true if you are not using the Single-stepping subsystem. In the mode, we allow you to drop the Subsystem into a simple while, for loop or Timed-loop and we would script the solver 'under the hood' for you. The major difference in this mode is that you only allow you to use "fixed step size" solver. Here is the documentation:


I'm trying to simulate the kinematics of a car and its performance in relation to acceleration. I've tried to use a control & simulation loop to integrate the signal to obtain the velocity as well as the acceleration and im then trying to plot them on an XY graph.


My guess is that the Integrator function is the cause: It's default initial condition is a numeric array ("vector") with just one number inside; the output of your mathscript node is a vector with two numbers. Wiring a correct initial condition into it makes the code work on my end (after some changes as your VIs had more issues).


I have a labview vi which is in a control loop with PID . I want to insert a timer for the simulation. It should display the time of the simulation and also use that time to make changes in the control loop. It is just a simple timer but I am not sure which one and how to use them. please help me


Alternatively you can use the Get Date/Time in Seconds function. Read this function at the start of your simulation and pass the value in to your control loop (or read it on the first loop iteration and store the value in a shift register). Inside the loop, read the same function and subtract the value from the start value; that'll give you the elapsed time in seconds. If you want a display of this value just wire it to a numeric indicator. You can set the display format of the indicator to 'relative time' if you want to show hours, minutes and seconds.


I am wondering if there is someone that could give me a hand with a simulation I am trying to run. I am trying to simulate the behaviour of a system modeled in state space form and make a controller using diferent techniques but I am having problems and cannot progress too far... It seems like the simulation loop enters on some kind of infinite loop and it cannot stop but I do not know waht else to do.... I left attach the block diagram of one of the simulation VIs I have in order that someone might look at it.


This is a model of an Inverted Pendulum System and a cart modeled in state space form and trying to see the behaviour of a pole placement controller due to a impulse imput. Initially I would want to check a non linear model I have but it was acting weird too so I replaced it with the linearized model towards the unstable equilibrium point but the VI get stuck too so I felt motivated to post it here.


(I tried to attach the snippet using the code capture tool generatin the image below, so you can download it and execute the code, but this is my first time using that tool, so I hope it will work well... I created the snippet .png and attached here using inser image... that is correct? )


It seems that you're trying to quit the loop using the elapsed time vi. This vi uses the system time, not the time of the simulation. I think your best bet for setting a time limit on the simulation loop is wiring up the 'Final Time' on the loop input node as below.


I've also added a direct control to halt the loop at any time, and indicator to display what the simulation time currently is. If you want to have a control which sets the maximum simulation loop within the simulation loop you can just use the Halt Simulation and Simuation time VIs.


I used Halt function and Elapsed time because prior of doing that I was using a Final Time constant at the simulation input node and I wasnt able to stop the loop so I thought that way was a better choice. This is the original VI that I wasnt able to stop: (I am creating it this time with the Labview native tool)


In the Simulation node, shift registers could have different behavior that would explain the problem you are running into. So, if you want to 'break' the feedback node (which in general, you should not need to do that), then use the 'memory' block. This will try to behave as you'd expect.


yes, as I said: the variable step time solvers do use the memory block better do compute the next step time instead of the shift registers. So, within SIM, it is always better to use Memory block for your simulation.


I am trying to create two PI controller loops using the control & simulation add on in Labview and when i try to run the program i get an error sayng control & simulation loop failed to compile i have read some of the guidance information on the NI website but didnt understand it well enough to resolve the problem.


The first loop i am trying to create is just a straight forward PI controller with about 5.5 sec deadtime. The second loop i am trying to create uses a smith predictor to reduce this deadtime. Both loops are resulting in the same error. Can anyone help or resolve.


It seems that your diagram had some problems in the generated code. It seems that you are using LabVIEW 2015, but was that created in this version or it was 'migrated' from previous version? It looks like it was created in previous versions and it did not migrate properly.


Anyway, I was able to make it compile for you. To do that, you can just need to open the transfer function, copy the value (the buttons on the right pane have a copy option), change the transfer function to accept the value from the terminal, and then wire it from the outside of the loop, like this:


Another way to make it work is to copy the data from the transfer function, delete the transfer function node from your diagram, drop a new one from the palette and then, paste the controller transfer function back. This should fix the problem you are encountering.


One last thing: did you see the shipping example named "Smith Predictor.vi"? This actually implements similar diagram, but it helps you implementing the PID and shows you some code to demonstrate the concepts:


In the past I have worked with FAST simulation model of wind turbine supplied by NREL, within the Matlab/Simulink environment(Open-loop.mdl). But I realized that the FAST models requires a lot of CPU processing, I was thinkint if it`s possible to make an application of HIL with the current CPU processing power. The integration time-step this simulation its 4ms.


We developed a built-in simulator (both FAST and a simple 1 DOF model) so that we could check-out new controllers in-place, in the exact environment and setup. Here though, it was less important to run in real time (when running the real turbine real-time is critical to keep up with various data streams coming in), and I can say that in our case the FAST model as implemented at 400 Hz ran, last time I checked, it ran just a little slower than real time (FAST took longer than 1/400th of a second, but not by too much). However, like I said since our primary interest was controller checkout prior to operation, this was acceptable.




I am running a control simulation where I created a sub VI to write the data to the file. However, the total data that I receive is extremely large (for a 10 second run time I get around 20000 data points) and hence I thought of saving the data at every few seconds.

So far, the only solution I can think of is using the while loop. But, any use of a while loop inside the sub VI is making the code get stuck there which results in the main VI not working.

I thought of the producer/consumer loop but am not sure if it would be applicable to the simulation loop. I cannot think of any other way to introduce a timing function or a way to reduce the data in a simulation running continuously.

3a8082e126
Reply all
Reply to author
Forward
0 new messages