01-31-2015 10:26 AM
Hi,
I am doing my final year project for my degree in Electrical and Computer Engineering. I have created a Fuzzy Logic Controller to control the conditions in a greenhouse. The output of my controller is a time value. For example I want to sample the data from the sensors every minute and based on the data turn on a fan and a humidifer. The output of the controller will specify a time for which the fan and the humidifer will be on and based on my design the maximum amount of time either will ever be on is for 30s. I have an arduino connected to LabVIEW with the sensors and the fan and the humidifer and I would like some guidance as to how to use this time value to turn on either of them for the specified time. For example, lets say the temperature and humidity are 35 and 65 and based on the control, the time the fan should be on is for 20s and the humidifer for 30s. How can I use these times and digital write to turn on these devices for the specified time.
01-31-2015 10:59 AM
For cases where you are working with timespans of larger than a few seconds I would use a timestamp method. When you turn on a device you record the timestamp. As your program runs, periodically check the "change in time" by comparing the current timestamp to the previous timestamp. If it's > X sections, turn off the device.
01-31-2015 05:35 PM
Hi Nathan,
Thanks for the advice. I only have these timing options available and I am new to LabVIEW. Based on the help file for each function, I was thinking about using the Elapsed Time Function and some basic comparisons. I have attached a VI image I am using to figure out how to design my system. I have used simple numeric value of 30, just to simulate a target time of 30 seconds, and have done a comparison checking whether the value is greater than 0, and then checking to see if both the target time value is greater than zero and if the target time has been reached. If it is not reached then the led attached to my arduino (just for testing purposes) is supposed to be on, but when it reached the target time, the led will turn off. I am having some problems with the set time part of the Elapsed Time Function and how to reset it. My Fuzzy controller is supposed to sample the data every minute and based on that data produce an output. The maximum time my output will ever be on for is 30 seconds. So for example if in the first minute the data says to turn on the fan for 30 seconds, but in the second minute when the data is again sampled the controller now says turn on the fan for 20 seconds, I guess I will just connect the output of my controller to the time target of the elapsed time and it will change the target time, but what about reseting the start time and how do I set it. I would greatly appreciate your help with this problem. Here's a link to the VI: https://www.dropbox.com/s/fti7zaj00tc0rme/Test%20Project%20with%20LabVIEW.vi?dl=0
01-31-2015 07:19 PM
A timestamp, to which I previous referred, it given by the "Get Date/Time in Seconds" function. You can see a brief description of functions by pressing "Ctrl+H" to bring up the 'Context Help'. It will show you a description and the inputs and outputs of a function that you are hovering over with your mouse.
You can use the Express VI is you want but I've always found it a bit tricky to play with. Make sure that you have auto reset turned off. Then, when you want to start the timer, you need to send a true to the "Reset" input. You will then get a false out of the "Time has Elapsed" until the time has elapse at which point it will turn true.
Basic advice:
01-31-2015 08:12 PM
I was not able to upload the VI as an attachment, it kept say this is forbidden, buts its the same as the image. Also Get Date/Time in Seconds functions does not have any inputs. I still don't understand how it will be used to measure the time from when the device is turned on. Also I just put in the greaterthan zero becuase there may be an instant where the controller might produce an output of 0s if no action is needed.
01-31-2015 08:59 PM
The "Get Date/Time in Seconds" VI doesn't need any inputs because if you read the description, it says that it gives you the timestamp of "now". I described how to use the timestamps in my original post. Basically it goes like this:
digital pin on => start_timestamp = now_timestamp
if( now_timestamp - start_timestamp >= 30 )
{
// 30 seconds has elapsed
digital pin off
}
01-31-2015 11:10 PM
I tried something with the timestamp. I was able to turn on an LED for a specified amount of time, but it kept looping. I attempted to change the while loop to a for loop with 1 iteration, but it did not work. Also I tried to include another LED and have both turn on/off at certain times. It worked, but when I changed the time for one of the LED, nothing happened. I attempted to do this since in my project I will be controlling a fan and humidifer simulutaneously and they will be operated at different time intervals based on the control rules of my controller. For example at one point in time, the fan may be on for 10 seconds while the humidifier is on for 20 seconds. I should note I did not try it on the arduino as yet, this was only a simulation. I have attached the VI that I used to turn on the LED.
02-01-2015 01:52 AM
When you do it with two, you have two loops. Anything that you do in loop 2 will be 100% independent of anything that is happening in loop 1 (unless of course you program it to do so).
It is repeating because you are effectively resetting the start time. You should only reset the start time when you want to start the specific time period.Also, I would probably refrain from using a literal toggle in your situation. When you start the time interval, set it to true. When the time expires, set it to false. Don't toggle it.
02-01-2015 11:16 AM
I tried to do what I think you were saying to do. I got the LEDs to turn on for different durations and stop the looping problem, so that they turn on then off and never come on again. But for my project, I will be acquiring data from the sensors connected to the arduino every minute and using this data with my fuzzy controller to get a new time for turning on the fan and humidifer, so this leads to hopefully my last major problem. How do I get the VI I created for turning on the LEDs to reset itself, so that it will now operate with the new time values produced by the fuzzy controller. And thank you for all your help so far, I really appreciate it since I am really new to LabVIEW and I was unfamiliar about some of the things you told me to do. I have attached the VI I created.
02-01-2015 01:17 PM
How you do it depends on how your controller works and what you want the LabVIEW program to do (other than turning the digital pins on and off.