LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Design Trigger Mechanism to send Commands using Case structures

Solved!
Go to solution

Hello, I am working with a sensor that measures gas ppm and communicates over a serial port. I am designing a trigger mechanism using case structures that if true sends a command to my sensor to begin calibration. If false, then the current code should continue until the true condition arrives (struggling to write the false condition). Once the calibration is completed, the slope checking can continue, but the true condition should not be allowed to activate again. Basically, I don't want to calibrate at the same gas ppm concentration multiple times. As shown in the VI file below, my idea is to use a slope checking condition between two consecutive gas ppm readings. If the change in gas ppm is lower than 20 ppm/s (the slope of the line between the two points), I will consider the concentration reading to be leveling off towards steady state and ready to begin calibration. I was hoping to use the measurement that is 10 readings away from the current measurement, but I don’t know how to index into the array I am creating using shift registers. I also want to prevent the calibration from activating with negative slopes. I have placed string constants in the case structure right now, but I know I will need to nest case structures in order to complete all my goals.

0 Kudos
Message 1 of 12
(308 Views)

Hi vance,

 


@vanceblake wrote:
I have placed string constants in the case structure right now, but I know I will need to nest case structures in order to complete all my goals.

When you think about nested case structures then most often there are better options!

 

What is your actual question?

Why don't you use InRangeAndCoerce to test for a range of values?

Why don't you use a Select instead of that case structure?

Why don't you cleanup your block diagram?

Best regards,
GerdW


using LV2016/2019/2020 on Win8.1/10+cRIO
0 Kudos
Message 2 of 12
(304 Views)

Hi GerdW, thanks for reaching out! I didn't know about the methods you mentioned because I am very new to labview. And I used the string constants as placeholders because they should actually be replaced with a command that I would send to my sensor to initiate calibration if true and if false continue sampling the gas ppm. Right now Im just trying to test if my conditional setup is correct, but I didn't want to acutally start the calibration. My questions are 1) how to keep the current block diagram that requests the gas ppm going, if the test condition is false 2) If the condition is true, then I only want it to be able to activate once. To accomplish this task, I was thinking of creating a 1d array intialized at 0 that would change to a 1 once a calibration started. Kind of like an on/off switch for the slope checking process as a whole. 3) How do I index into the array I am building with the shift registers to select the data point that is 10 measurements in the past from the current measurement. For example, if Im on sample 11 then I want to compare it to sample 1, sample 21 compare to sample 11 and so on until the true condition is reached.

 

And yes I apologize for the cluttered diagram, but I'm at the make it work even if it's not pretty development stage right now. 

0 Kudos
Message 3 of 12
(286 Views)
Solution
Accepted by topic author vanceblake

Hi Vance,

 


@vanceblake wrote:

And yes I apologize for the cluttered diagram, but I'm at the make it work even if it's not pretty development stage right now. 


It doesn't help to get an overview of your VI or to understand its code when it is cluttered like this…

 


@vanceblake wrote:

And I used the string constants as placeholders because they should actually be replaced with a command that I would send to my sensor to initiate calibration if true and if false continue sampling the gas ppm. Right now Im just trying to test if my conditional setup is correct, but I didn't want to acutally start the calibration.


So you want to implement different states of your sensor communication, like "normal readings" and "calibration state"?

Ever heard of state machines and how to implement them in LabVIEW?

(As you are very new to LabVIEW you should also take care of those Training resources offered at the top of the LabVIEW board!)

 


@vanceblake wrote:
My questions are
1) how to keep the current block diagram that requests the gas ppm going, if the test condition is false
2) If the condition is true, then I only want it to be able to activate once. To accomplish this task, I was thinking of creating a 1d array intialized at 0 that would change to a 1 once a calibration started. Kind of like an on/off switch for the slope checking process as a whole.
3) How do I index into the array I am building with the shift registers to select the data point that is 10 measurements in the past from the current measurement. For example, if Im on sample 11 then I want to compare it to sample 1, sample 21 compare to sample 11 and so on until the true condition is reached.

Good advice: use some linefeeds in your message text to format the text a litte bit. It helps with reading and understanding the text in general… (Use the formatting options of the message editor like numbered lists would be nice, too.)

 

  1. To stay in the current state of "read gas ppm value" you just call that state again in your statemachine!
  2. To activate just once when a condition changes from FALSE to TRUE you need to detect a "rising edge". There's a PtByPt-BooleanCrossing function to check exactly this…
  3. You may setup your own array of 10 elements: rotate the array by one position, then pick the oldest element value and replace it with your new value. Now compare old and new value…
    You may also use the PtByPt-DataQueue function which does the same, but already wrapped in a ready-to-use function!

General advice:

Before starting with "how to implement my algorithm using which LabVIEW functions" you should ask yourself "what exactly do I want to implement"! First decide on the "What" (with drawing some sketches on several sheets of paper!) before you go to the "how" stage. That's why I mentioned the statemachine approach…

Best regards,
GerdW


using LV2016/2019/2020 on Win8.1/10+cRIO
Message 4 of 12
(255 Views)

Hi GerdW, 

 

Thank you for all of your insights. I try to make it a point to thoroughly research whatever it is I am trying to do before I come to here because I know there are so many resources and solutions already available. This community reminds me of the matlab message boards, and I do not want to waste anyone's time with things that can be found with a little bit of work. 

 

With that being said, I hadn't come across state machines in my search, but that I can attribute that to the rudimentary phrasing of the questions I asked google and the NI community search bar. 

 

In regards to question 3), does that method work with a 2D array because the array contains both date/time data and gas ppm data? Or are you suggesting I make a separate 1D array that contains just the gas ppm data and then manipulate that array instead?

0 Kudos
Message 5 of 12
(238 Views)

Hi GerdW,

 

Nvm about that 3) point in my haste, I didn't realize that you had also provided a function as well 😅. Thanks for all your help!

0 Kudos
Message 6 of 12
(224 Views)

Hi I am working with a SSM that uses visa serial communication. I havea an issue with the trigger condition for the state switch occuring multiple times instead of just once. I thought that setting the crossing direction as false-true would prevent the trigger from activating again, but it has not. Any suggestions on how to improve this function are greatly appreciated.

0 Kudos
Message 7 of 12
(185 Views)

Hi Vance,

 

please keep related posts in the same thread!

 

Didn't I suggest to cleanup the block diagram to improve readability of your code? Do I need to suggest the same hint twice?

Please:

  • Don't show the label of each and every (basic) function! Use the context help window when you don't know the names yet…
  • Show the radix/display mode indicator for constants of FP elements when you use non-default display modes!
  • There's an InRangeAndCoerce function to check for a range!
  • ...

See this for possible improvements:

(Some improvements, but still a lot to do…)


@vanceblake wrote:

I thought that setting the crossing direction as false-true would prevent the trigger from activating again, but it has not.


Using that function prevents from calling the other state again - as long as there is no new rising edge in your boolean signal!

Is there a new rising edge in that boolean signal?

 

When you want to call the "Zero calibration" state only exactly once then you should use one more shift register to store a flag for that state. As long as the flag is FALSE you may call that state, but inside "Zero calib" you set the flag to TRUE to indicate "no more calling of Zero-ing"…

 

In the end it comes down to your requirement sheet! You need to use clear requirements, describing all conditions for calling states…

Best regards,
GerdW


using LV2016/2019/2020 on Win8.1/10+cRIO
0 Kudos
Message 8 of 12
(175 Views)

Hi GerdW,

 

Thanks again for chiming in on my problem. I thought I cleaned it up pretty well from where it started...but I guess more white space between everything is better? 

 

And the labels aren't for me. They are for the people I am presenting to who have no familiarity with LabVIEW or the functions. I just think it is easier for them to follow when I am not there explaining it for them over zoom. But, I see your point; it is hard connecting wires without intefering with the function titles. 

 

And I did make a requirements sheet, but clearly it wasn't exhaustive enough 😅. Nevertheless, thank you for helping me again. Going forward, how do I keep related questions in the same thread?

 

 

 

0 Kudos
Message 9 of 12
(162 Views)

Also, I see you are using a different function to conduct the boolean checks before the PtbyPt-Boolean crossing, where would I find it on the palette or what is its name?

0 Kudos
Message 10 of 12
(159 Views)