LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

simulation in real time

Hi,

 

I need help for my labview program.

 

I am using ETS desktop PC as RT target and LV 8.2. My program contains three loops running at different time period. One loop is simulation loop(Control Design and simulation toolbox) I would like to execute the other loops after certain number of simulation loop cycles. My simulation loop time is 1ms and I am using RK 4th order ODE solver.Other two loops should run after every 20ms and 1s resp.

 

My problem is how to count the time in simulation loop and send notification to other loops for execution and stop simulation loop until the other loop finishes its one cycle.  I tried with "wait" for 20ms and 1s in while loop but as the whole program runs on real time, the while loop stops running and simulation loop takes over. I want the while loop to complete its function and then the simulation loop start.

 

Please help me out.

 

Rashmi

 

 

 

0 Kudos
Message 1 of 8
(3,474 Views)
You should look at using the Synchronization functions such as the Notifier, Rendezvous, and Occurrence functions. The LabVIEW Help describes the user of these functions pretty well, and there's also examples that show you how they work.
Message 2 of 8
(3,459 Views)

Hi Smercurio,

 

First of all, thanks for your reply. I was trying the same things you have suggested. But as I mentioned in my first post, I am running three loops in one vi on the ETS PC. One of these is the Simulation loop which runs at 1ms and other two are while loops running at 20ms and 1s time. I am using wait function in while loops.

 

The problem is that when the while loop starts, it is not able to finish as the simulation loop takes over after 1ms. So I am not getting deterministic pulses from 20ms loop. This loop sends ASCII data through RS232 port. Simulation loop and other while loop with 1s time works fine. If I increase the time to 3ms there is no problem. I want the while loop to finish and then the control should be transfered to S.L. I was trying with notifier function but somehow not able to manage. I tried to use case structure instead of while and condition was generated using a counter and memory block in S.L. But it does not work. If I include both the loop codes in the S.L itself it will unnecerary incrase the load on OS.

 

 Thanks once again and sorry for so big post .

 

Rashmi

0 Kudos
Message 3 of 8
(3,433 Views)

I don't have the Control Design and Simulation Module, so I can't really provide an example. However, the simulation loop in the Control Design and Simulation Module is akin to the Timed Loop in regular LabVIEW. You can have this loop running at 1 msec all the time, but you don't necessarily have to execute the code inside the loop.

 

Let me see if I understand your scenario correctly so I can set up an example for you using the Timed Loop. Based on your description the simulation loop chugs along at 1 msec. After 20 msec a while loop (which we'll call WhileLoop1) gets "triggered". At this point the simulation loop should "stop" and "wait" until WhileLoop1 ends its iteration. At that point the simulation loop "starts up" again. Now this is where it gets confusing. Let's assume that WhileLoop1 took 25 msec to execute. The total time counter is now at 45 msec. The simulation loop "starts up" again. You have a second while loop (which we'll call WhileLoop2) that is supposed to be triggered after 1 sec. Is that 1 sec from when the simulation loop started? Is the 25 msec that it took for WhileLoop1 counted into the time? In other words, if the simulation loop was chugging along the whole time, but not actually executing any code for the 25 msec that it took for WhileLoop1 to run, then is the time counter once the simulation loop starts executing code again (it's still running) set to 45 msec, or does it remain at 20 msec?

0 Kudos
Message 4 of 8
(3,412 Views)

Hi,

 

Let me explain you in some more details.

Block Diagram Window: Three independent Lops

 

1. Simulation Loop: Contains Formula node and integrators to solve 12 Ordinary Differential equations(ODEs) with RK 4th order fixed step of 1ms. The clock selected 1 MHz, with period 1000. The 12 state variables are available as local variables.

 

2. While Loop 1: Uses the local variables from simulation loop and after some calculations sends the data through RS232 in ASCII format. This loop should send the data at every 20ms. It should wait for 19ms and then get the values of local variables at that point and execute it. In short, at every 20th ms, I expect both the loops should get over their execution in 1ms. The baud rate of RS232 port is set at 38400. By the time this loop is executing the simulation loop should not update. Again it should wait for 19ms.

 

3. While loop 2: Same as WL1. It sends data through RS232 port in string format at every 1s. The baud rate here is 9600.

At every 1s, all the three loops should execute in 1ms.

 

I am attaching the screen shot of simple block diagram for a better clarity.

 

Rashmi

 

0 Kudos
Message 5 of 8
(3,394 Views)
Does the attached example indicate sort of what you're trying to do? I had to use a Timed Loop to implement a Simulation Loop.
0 Kudos
Message 6 of 8
(3,377 Views)

Hi,

 

I will try to implement my code with the vi you have attached. A small doubt: Now I am using simulation loop to configure simulation parameters like step size, ODE solver method, simulation time etc. How can I set these parameters in Timed Loop? I have to solve 12 ODEs in my code.

 

regards,

 

Rashmi

0 Kudos
Message 7 of 8
(3,365 Views)

The Timed Loop was for demonstration. As I indicated, I don't have the Control and Simulation module, so I can't create a Simulation Loop. I used the Timed Loop as a replacement. I wrote the VI so you could run it and see its behavior to determine if that's what you were looking for, conceptually. Obviously, you should use the Simulation Loop in your real code. 

0 Kudos
Message 8 of 8
(3,354 Views)