04-08-2018 06:40 PM
I'm building a House Smart meter in Labview. Part of what I am trying to do is calculate the total power consumed during the week and the weekend. To do this, I created two separate while loops and found the total using numerics. Now using the local variables, I am trying to sum up the total power consumed.
Is there a way to do this? Any help is appreciated!
04-08-2018 06:56 PM
Bob, you're right.
I'm trying to model the electrical consumption and cost over a week's time of a home, where various appliances are turned on at various times. I want to be able to log the toal kWh for each day. I want to graph the unit price per hour & Measured kW per hour (both are done), and have the model the time passed vs. kWh used (also been done).
04-08-2018 07:19 PM
So pick one appliance, think about what you want to do (write it down!), and make (several) simple VIs to implement it.
Bob Schor
04-08-2018 07:22 PM
Bob, the subVi are already complete. I have all the power consumed for each day. However, these values only show for a split second on a numeric then disappears and shows the total power consumed for the next day. Instead of these values disappearing, I'd like to log them into a table or array. Is there a way to do this?
04-08-2018 07:23 PM
Instead of using Local Variables, learn about keeping "variables" in Shift Registers and getting rid of all Local Variables (they seem like a neat idea, but there are many reasons to avoid them like the plague). IMHO, they should be banned for LabVIEW beginners, and only available once you get a CLD certification (not a totally serious proposition, but as I've gotten better at LabVIEW, my projects get more (>400) VIs and fewer (< 1) Local Variables.
Bob Schor
04-08-2018 07:46 PM
The simplest way is to have a loop that runs every day. Maybe have an Enum that goes "Sunday, Monday, ... , Saturday" and increments (carried on a Shift Register) each loop. Inside there's a Case Statement that has two Cases: Monday .. Friday and Saturday .. Sunday. Hmm, that may be slightly thinking about it the wrong way -- what is different about the weekend? You could have a sub-VI that takes the "Day-of-Week" Enum and returns a 2-value Enum, WeekDay or WeekEnd. You can now have an Array for, say, "Hours of Use" that has WeekDay and WeekEnd entries. So now you have a For Loop that runs, say, 365 days, has a Day-of-Week Variable that you pass through the WeekDay/WeekEnd function (to give you WeekDay or WeekEnd), and use this to the Usage Array to get the WeekDay or WeekEnd Usage (as appropriate) for each Appliance.
See how writing things down with pencil and paper (or keyboard and Forum Entry) can help you figure out what you want to do and suggest a reasonable way to do it? Try it (and start doing your own work instead of breaking your unwieldy VI into little pieces and asking us to solve each piece ...).
Bob Schor
04-08-2018 09:17 PM
Attach your simple VI with one Appliance that demonstrates this behavior and one of us will (a) remove all the Local Variables and (b) fix the "disappearing" indicator (provided it is clear, when we run it, that the problem is obvious to us). We, of course, need a VI that we can run, so a picture just won't do ... Also, remember the Keep It Simple, Schor (K.I.S.S) principle and give us a single appliance ...
Bob Schor
04-08-2018 09:19 PM
Okay. This is VI I used.
04-09-2018 04:47 AM
Both your loops can be highly cleaned up by making a loop of your measurements. I'll attach a cleaned up version with the top loop fixed. I also noticed you have mixed Oven 2 and Microwave 2 in the 2 clusters, which is yet another reason to use loops and arrays. Also, why do you bundle the results instead of simply use arrays?
/Y
04-09-2018 09:18 AM
One of the first books on LabVIEW I read (it was actually the second book, and the first one I read cover-to-cover at least four times) was "The LabVIEW Style Book", by Peter Blume. In it, he stressed the idea of LabVIEW having a "Style" that, if followed, makes LabVIEW code particularly easy to follow, easy to develop, easy to maintain, and remarkably powerful.
In my comments to you, I tried to "nudge" you towards a better Style (elements of which include "Every Block Diagram fits in a 1024 x 768 pixel Window", "Every Label makes logical sense", "Every VI has an Icon"). It does take a little more effort to write "stylish" code, but the rewards are tremendous.
Sadly, you didn't take my hints. I see two Clusters on the Front Panel, without labels (I figure out that the "Input" cluster was on the right, the "output" cluster on the left). Each has a Boolean named "Boolean", giving no idea of purpose. The Input cluster has "Run Time" and "Time On" controls, no explanation of purpose. The code is a mishmash, no documentation, no labels, no explanations, no sub-VIs. There are no loops, so it is unclear how to "test" the code.
I think, at one point, I suggested using Pencil (or pen, or keyboard) and paper (or a text file) to write What you are trying to do. You should do this not for us, but for yourself. You need to identify ideas of what (there's that word, again) you want to do, and leave the How (i.e. the implementation details) to much later.
I have a colleague who has actually been using LabVIEW longer than I. His code is typically a mess (I show one of his Block Diagrams to students as an example of "what not to do"). He'll call me, say "I can't get my VI to work", and when I ask "What is it supposed to do", he starts pointing at the big mess on the screen and tries to walk me through the code. We then have the "What?" vs. "How?" discussion, which usually ends up in something like "Acquire some data, do some processing to gather intermediate values, and simultaneously save in a data stream", to which I say "That's three sub-VIs you need to write, each with a "pure" purpose and mission". While doing this, the wire count drops dramatically, and the problem often "solves itself".
Good luck on your Project.
Bob Schor