Timing a simulation in a control loop - labview

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

The simplest option, if it does what you need, is probably the 'Elapsed Time' Express VI.
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.

The most natural option would be to use a Timed-loop, this allows you to detect whether your code can run in the supplied time and select a hardware time clock.

Related

Seeking suggestion to count time inside the loop

I am trying to measure/count the time inside the while loop, I tried a couple of methods but couldn't find the solution yet.
Here is my current VI.
 
In short, I am trying to measure the time as long as the "Boolean is on/true" and once it's off/false the time must be displayed.
If something is not clear then please let me know.
I may be repeating Fourier's answer, but typing it in two different forms may be helpful to you since I note you haven't accepted that answer yet.
Remove the outer While Loop. It is superfluous.
Then do this:
In the "turn on" frame, you gather the current Tick Count and stash it in a shift register. In the "turn off" frame, you gather the Tick Count again and subtract. In all the other frames, make sure you wire the two tunnels together so you don't lose your Tick Count. Side note: you probably want Boolean to be an indicator, not a control, so your user cannot click on it and toggle it directly.
You can reach your goal with simpler code. You should use one while loop only with the Event Structure:
When List of Conditions changes, intercept the event (as you are already doing) and register the time when this event happen (with the VI Tick count for example).
in two shift registers,"save" the time you registers in the previous point and the status of your count (a boolean should be enough: counting/not counting).
Then, in the Timeout event you calculate in real time the time passed with the following operation current time (Vi Tick count) - event time (save in the shift register).
You should count time only if your boolean Counting/not counting is True.
When you detect another event List of Conditions Value Change, you should check if you should stop count time or not.
Finally, in the Timeout event or in the List of Conditions Value change event, evaluate the stop condition for your while loop.

Conditional parallelism on LabVIEW

I am writing an application to update the numeric value given user's input value and depending on the user's input value the program checks if it is greater than 10 if it is greater than 10 then the program waits for 1 second and then will have a popup message says "true".
My intention was to call the conditional check, printing true every one second if the user's input value is greater than 10; in other words, the case structure was to be called regardless of the event structure in the same loop infinitely.
But it doesn't seem to work the way I expected. Unless there is user's new input value, getting into the event structure, the program doesn't get to the case structure even though the case structure is in a loop.
Is there any way to call the case structure not dependent to the event structure but I want to use a shift register for the numerical value and also having an event structure and a case structure in parallel.
Thanks.
You've created an Event Structure that handles the Value Change input for your numeric control, so that will do exactly what it says: wait for a Value Change event to happen. When that event is received, the code in its Event Structure frame will execute and then the Event Structure will exit.
It looks as if you've wired a value from the shift register to the timeout terminal of the Event Structure, so I assume you must also have created a Timeout event case? If so, the event structure should stop waiting after the number of milliseconds wired to the timeout terminal.
The value you check in order to decide whether to show your true message is the value that was passed in to the shift register on the previous loop iteration. If the control value changes, that comes from the NewVal terminal in the Value Changed event case. But where does it come from in the timeout case? It looks to me as if you haven't wired it in that case, because the terminal coming out of the event structure has a little dot in it instead of being solid orange. That means you will get a default value for any case where the terminal wasn't wired. The default value for numerics is zero. So if the event structure times out, the value going in to the shift register is zero, you get zero out of the shift register on the next iteration, zero is not greater than 10, so you don't see the message again.
I don't understand what you're trying to do in the event case where you've wired the NewVal terminal to a Value property node of the same control. Can you explain what that is supposed to achieve?
Your question reads as if this is a programming exercise where you have to use these specific LabVIEW structures, so rather than suggest better ways of achieving what you say you want this code to do, I'll leave it to you to decide how to change it. In the meantime though I do recommend re-reading the Event Structure help and the caveats and recommendations it links to.

vb.net program to register time on multiple runners

I building a program to track the time of up to 60 runners. My idea is to use a DataGridView with columns for:
ID (DataGridViewTextBoxColumn)
Name (DataGridViewTextBoxColumn)
Start time (DataGridViewButtonColumn)
Stop time (DataGridViewButtonColumn)
Reset time (DataGridViewButtonColumn)
Finish time (DataGridViewTextBoxColumn)
Adding columns 1-5 including functions is no problem, but I cannot wrap my head around how to display a stopwatch in column 6.
My idea was to add a timer and stopwatch function every time a new row I added, but do I need a timer for each row? If so how do I set the ID of that timer, so I can call the Tick event and display the time in column 6?
Also I assume that I need a stopwatch for each row? So how do I set the name of ID of each Stopwatch - can seem to find any property for that?
See below screen shot of what I am trying to accomplish.
Thanks in advance.
Screen shot

Using Timer in vb.net

How can I use Timer in VB.Net? I want to repeat a statement after every 5 seconds but timer event offers only timer_tick() and timer_disposed()
In which event I can write my required code?
You could write your event in the timer_tick().
It's worth noting that your timer tick is in Milliseconds (ms) so you'll need to set its property to 5000 for 5 seconds.
You'll also need to start the timer (timer1.start) (you can do this on form load if you want the action to start from when the form is first loaded) and then put your loop in the timer_tick() section :)
Have a look here for a rudimentary explanation:
You will want to use the Tick event. When the Timer is enabled, it will be raised on the interval defined by the Interval property.
The timer_tick method is called in time-interval You set. Your code should go there.
You should handle the Timer's Tick Event and write in the required statement which should repeat every 5 seconds there. Have a look at the following example:
http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.tick.aspx

VB time input, a better way to do it?

Working on a handy program for my boss at work as a summer project in between semesters both to make life easier for her, and to practice and improve my skills. Intent is to allow her to quickly and easily calculate the hours and minutes the person worked. The form itself has a series of text boxes for the Clock in and Clock out time for each day that week. Currently it attempts to convert the txtbox text into a Date variable, then .Subtract()'s the start from the end and stores it in a rolling total variable which is displayed at the bottom of the form. I can't help but think there is a better way of going about doing this, and I'm absolutely certain that having the below block of code 21 times (7 days, 3 shifts) is inefficient.
Dim StartTime As Date
Dim EndTime As Date
Dim Worked As System.TimeSpan
Dim WorkedTotal As System.TimeSpan
If chkFirst.Checked = True Then
StartTime = CDate(txtMonStart.Text)
EndTime = CDate(txtMonEnd.Text)
EndTime = EndTime.AddHours(12)
Worked = EndTime.Subtract(StartTime)
lblMonWork.Text = Worked.ToString()
WorkedTotal += Worked
Currently it works, mostly. The user has to enter the ":" in the time input, and if the total exceeds 24 hours, it displays a day column (40 hour 12 min work week displays as 1.16:12). I'd like to eliminate both of these unplanned features and allow for my input validation to take place when the focus changes to another box. A changing bgcolor would indicate an invalid input.
Any bright ideas?
Instead of using TextBox for the time input, use DateTimePicker, just change the Format property to Time.
Handle the Validating event of the DateTimePicker and if it's invalid just set e.Cancel = False, that way they can't save changes unless it's valid. Or if you want them to be able to leave the DateTimePicker and just change the colour, just handle the ValueChanged event instead.
Regarding your code sample, I haven't really looked at the logic of it, but instead of having the same code 21 times, just move the code into a separate function and then call that function with the start and end times as parameters and it can return the workedtime as it's return value.
I'm not sure what your UI looks like but if you're repeating the start time and end time input control multiple times as well it might be worth looking at creating your own usercontrol that can contain one each of the start and end time controls, and then you could have the validation be inside that user control so you don't have to have lots of event handlers etc.