07-05-2018 08:51 AM
Hello,
I am currently fairly new to LabVIEW, I have created a code (i will attach as soon as the laptop it is on is returned to me) this code uses the LINX software for arduino. What I did originally was create a code that ran based on a measured value and would activate after a certain g was reached and would run my hardware so that it would inflate or deflate airbags appropriately. This code worked fine and all was going well until a design error on the actual product occurred which will not allow me to mount the sensor appropriately. To solve this I need to change the code that I have not instead of running the way that it was originally programmed to run it now must run for a certain amount of time lets say 3 seconds once g reading is reached. I have tried to do this using while and for loops along with the elapsed time tool, but it has not been successful because once I do that the sensor kicks on and off continuously when I actually only need it to run once.
Another issue it that for example lets say I need it to initially kick on for 3 seconds when .2 g is reached but I need it to kick on again for 2 seconds once .45 g is reached. Now I assume that will be easy to do once I figure out how to get the 1st part to run but the issue with this is that okay now that I have inflated the airbags twice because it made it to or past the .45 g it then starts to decline so the g is back to .2 or around .2 so it does not need so much air in the airbag how would have it then deflate? I have thought about this alot and can not think of a soltuion because if I set it to start deflating for x seconds at .22 g (remember all these numbers are just example) then it would deflate when the g force was still climbing because it would inflate at .2 g, then lets say it continues to climb to the .45 g where it needs to inflate again but it would have already deflated because of the deflate setting at .22g.
I know this is probably extremely confusing without the vi. but I will add that as soon as I can, but anything you can do to help would be greatly appreciated.
Best regards,
Zacahry
07-05-2018 09:27 AM
You are new to LabVIEW, so the "How to Do It" might be new, but think about your Task, and ask yourself "What" do you want to do.
As you describe it, it sounds like the following:
So what are your Conditions? Condition 1 might be "Measurement reaches 0.2g". Condition 2 might be "3 seconds elapses" (but what if the Measurement dips below 0.2 g during those 3 seconds? Oops, need to think about that ...).
There's a key word up there that has a particular (and slightly different) meaning in LabVIEW -- "until". Because LabVIEW deals in Virtual Instruments (that's what the "VI" in the name LabVIEW stands for), this really means "until the time that a particular Condition, which might be measurable, is reached". Most Programming Languages with "until" do whatever they do "as fast as they can", whereas LabVIEW has Timing functions built into it so that "until" can (and often does) take on units of Time.
Let's say you decide you want to "quantize" time to a tenth of a second, so that your loop runs at 10 times/second. Do you know how to do that? Have you learned about the Timing VIs, in particular, the Wait (ms) VI?
What we are describing above is called a State Machine. It involves a Loop (that we are going to run 10 times a second), a "State" that describes What we do in that part of the State Machine, and a "Rule" that determines what the next State will be.
Do you know how to build Example Projects in LabVIEW? One is called the Simple State Machine. Create it for yourself, and think about how you could adapt it to handle the tasks you need to do.
Bob Schor
07-05-2018 10:23 AM
Guys,
Okay here are my VIs the reading senso vi being what I orginally created and the times reading vi being the one I am trying to work on. I get that the timed vi probably looks silly but as I said I am relativily new to this stuff and am unsure how to make this happen so that it will take the measurement and run only one time until changes have happened.
I kind of got it to work by removing the loops and changed the auto reset to off
Bob, first off thank you for the reply, you bring up some really good points I will start looking into them and well take a look at the vi and see if it changes anything.
Best regards,
Zachary
07-05-2018 10:27 AM
sorry guys the last response was me, I failed to realize that my coworker had logged in and that I was in his account I am sorry if this causes any confusion
07-05-2018 03:01 PM
If you find yourself doing "almost the same thing" more than once, think "Arrays" and "Loops". If you find yourself outputting (or inputting) "almost the same data" more than once, think "Clusters". If you see your VI taking a lot of space doing things over and over, think Arrays and Clusters (and sub-VIs, but that is for Next Week) and Make It Smaller (so you can see what's going on without using the Mouse).
Bob Schor
07-06-2018 08:42 AM
Bob again i really appreciate the response and the input and I will definitely use your advice! but I have encountered a problem where I have it running now for the set amount of time and that works great but the issue is that once I hit the value I need in g to inflate it does but once that value comes back down for example it starts at 0 increases to .27 so it inflates for three seconds because it went through the constraint saying that if g is between .2 and .25 inflate, but then we start to level out and the value drops down to .14 which would be fine other then the fact in doing so the reading would pass through the range again and inflate when it does not need to because the value of the g is decreasing.
Do you or anyone else have an idea on how to counter act this ?
Thank you and Best regards,
Zacahry
07-06-2018 09:26 AM
Maybe to word this simpler I should say it like this.
Once the airbag has inflated I do not want it to have the possibility to inflate again until after it drops below a certain point, once that lower limit has hit then it can inflate again if the numbers fall into range.
Essentially that lower limit would lie somewhere in the deflate stage so that it has the ability to deflate before air is put back into it .
07-06-2018 11:55 AM
Zachary,
Have you looked up State Machines? Did you try building the Simple State Machine that ships with LabVIEW? Start LabVIEW, click Create Project on the left pane, Simple State Machine on the right pane, and study what comes out. Note there are other ways to do this, but this gives you the general idea.
It seems to me that you might have the following States -- Initialize, Idle, Inflate, Hold, Deflate, and Quit. You have "things you can do" (like turn on inflation, or reset-and-start timer), things you can measure (like pressure or the elapsed time), and some notion of Clockwork, i.e. how often you want your main Loop to run. Notice that this last point sets LabVIEW apart from many other programming systems, which don't have "Time" as a built-in primitive, and just run "as fast as you can", rather than at some deliberate rate that is more appropriate to a Control Task.
Try designing with pencil and paper. Make some assumptions (how about "Loop 10 times a second, or every 0.1 seconds"). Also how about "record Pressure at beginning of Loop". Suppose you are Idle. What would make you want to change the State to Inflate? What is the next State if you don't change the current State? What do you need to "remember" if you change State? [Hint -- what keeps you in a State like "Inflate", and what do you need to know in order to end that State?]
State Machines are about "doing something" and "deciding what the Next State should be, even if it is the Same State". Draw it on paper, then think about how to code this in LabVIEW. The Simple State Machine example should give you some clues.
Bob Schor