LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulation Loop Acting Weird

Solved!
Go to solution

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? )

 

Simulation.png

LabVIEW Enthusiast
0 Kudos
Message 1 of 7
(3,432 Views)

The snippet hasn't worked (at least for me) - so I can only comment based on the screenshot. Did you create the png using 'Edit'>'Create VI Snippet from Selection'?

 

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.

 

SimLoop.png

 

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.

0 Kudos
Message 2 of 7
(3,420 Views)

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 wasn´t 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)

 

Simulation.png

 

Thank you very much for the help and support.

LabVIEW Enthusiast
0 Kudos
Message 3 of 7
(3,405 Views)
Solution
Accepted by topic author Javi_Rome

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.

 

By the way, you can look at the shipping example for linear simulation:

C:\Program Files (x86)\National Instruments\LabVIEW 2014\examples\Control and Simulation\Case Studies\Mechatronics\Inverted Pendulum\Linear Inverted Pendulum Simulation.vi

 

Or nonlinear simulation:

C:\Program Files (x86)\National Instruments\LabVIEW 2014\examples\Control and Simulation\Case Studies\Mechatronics\Cart-Pole\CDEx Cart-Pole Control and Simulation.vi

 

as a reference for your example. Notice you even reuse the animation for your application.

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 4 of 7
(3,380 Views)

Thanks very much Barp, I´m going to check how to use the memory blocks you told me and those examples too. I have some spare time this afternoon so I could post here my conclusions.

 

The main purpose of the "shift registers" I added to the VI, was to set an initial value for some of the feedback variables of the control algorithm, in order to keep the dataflow paradigm.

 

Let me work on your advices and I´ll post here the results.

 

Best regards.

LabVIEW Enthusiast
0 Kudos
Message 5 of 7
(3,362 Views)

It seems to work using the memory blocks instead the shift registers.

LabVIEW Enthusiast
0 Kudos
Message 6 of 7
(3,313 Views)

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 glad it is working for you now...

Barp - Control, Simulation, RTT and HIL - National Instruments
0 Kudos
Message 7 of 7
(3,264 Views)