04-05-2017 04:47 AM
Hello everyone
I want to create a VI that simulate the activity of a sensor (motion Sensor). In this case, i want to set up a light that turn on whenever there are people in the room,. The light will keep lighting in the next X (seconds), and then turns off (If there are no more motions sensed by the Sensor).
In the period of X Seconds, if there is any person coming in the room, the led will keep be on until the next period of X seconds passes. And so on.
(e.g) When x = 3(s)
Case 1:
{t:= 0, people coming the room, light = on
t:= 1, (no people), light = on
t:= 2, (n.a)
t:= 3, (no people), light = off
}
Case 2:
{t:= 0, people coming the room, light = on
t:= 1, (n.a)
t:= 2, people coming the room, light = on
t:= 3, (no people, light = on)
...
t:= 5 (no people, light = off)
}
Because i don't have any real material and sensor, i only use a random function to simulate the people entering the room.
I have trouble when building the VI. I tried some version but they are all failure.
Any idea?
Please !
I'm using labview 2011
P/S: English is not my mother-tongue, so please ignore all grammatical mistakes that i have done.
Solved! Go to Solution.
04-05-2017 04:52 AM - edited 04-05-2017 04:53 AM
Hi John,
In the period of X Seconds, if there is any person coming in the room, the led will keep be on until the next period of X seconds passes. And so on.
- You need a signal/flag marking the condition "people are moving": when using a random function you could simplify this to "rnd() >= 0.9"…
- When the condition is met (aka rising edge, detected by PtByPt-BooleanCrossing) you start your timer
- as long as the timer is running you keep the light on
I have trouble when building the VI. I tried some version but they are all failure. Any idea?
Attach your VI and we will tell you what went wrong!
(When "no VI from you" THEN "no VI from us"… :D)
04-05-2017 05:51 AM
@johnnguyen123 wrote:
[...]
I have trouble when building the VI. I tried some version but they are all failure.[...]
Sounds like you require at least a state machine... Have you tried that?
04-05-2017 08:20 AM
Thank you all of you!
I did not want to share my vi because it didn't work. Anyway, this is my Vi
i used labview 2011, if you upload your vi, please save its as labview 2011file. Otherwise my computer can not read.
One more time, thank you all !
04-05-2017 09:19 PM
My new vi:
I am pretty sure that this thing is much more better, but it still doesn't work as i expected.
04-05-2017 09:46 PM
Your outer while loop will only run once because your inner while loop will run forever since you have a false constant wired to the stop terminal. The only way to stop your program is to abort.
Before posting, be sure to run block diagram cleanup so you don't have backwards running wires.
Have you sat down and drawn a simple flowchart or some pseudo code to describe how the program is supposed to work? Right now it looks like just a few functions that should be ones you need to use, thrown down with no logical reason as to why they are there. The local variables really don't need to be there.
You talk about needing two loops, but it seems to me this should be a 1 loop program. But without some logical plan as to how the program should work, there is no point throwing down code on a block diagram.
04-06-2017 03:01 AM - edited 04-06-2017 03:02 AM
This time, everything work quite well. However, there is a problem. After the "Human" Boolean = true, the ligh turn on for 5 sec. However, if at the moment when time = 3, the "Human" Boolean = true (second time), the light only be on for the next 2 seconds ( i want the light to be on for the next 5 seconds then turn off)
From what i assume, the second while loop keep working until it finishes, so that it couldn't update continuously the data from the "human" Boolean. I want the whole different thing, the time still runs, but the time counter will reset to 0 after the "human" Boolean = true again
I have wrote many pseudocode, but it's very different when applying to labview >.<
04-06-2017 08:02 AM
There is still a problem with the extra while loop and unneeded local variables.
Here is how to do it in one loop.
04-06-2017 09:55 AM
OMG, you really did that !!!
But you did that by using some things that i have no idea what they are 😛
Anyway, i believe that i can learn! And it's seem to be the best solution!
Thank you so much!
04-06-2017 10:07 AM
The only thing that might be unfamiliar to you in this VI is the Boolean Crossing Pt by Pt, which is a pretty cool VI that outputs a True only when the input changes.
Actually, I probably should have not used that at all because if you had continuous movement so that "human" was detected on every 1/2 second iteration of the while loop, it would only output a True and reset the timer upon the first True, following a False. So I'd eliminate that and just wire the =1 output directly to the Reset input of the Express VI.