Jump to content

How to exit from switch statement when condition is met first time


Recommended Posts

Hi there,

I am trying to implement a blood pressure (BP) monitor in Labview using NI 9239 and NI 9263.

At this time, all I want is that the motor (pump) runs until a user-specified pressure is reached in the cuff. When that pressure is reached, the motor should stop but not the Labview program. As the cuff is deflating slowly through a pressure leakage valve, I want to record the pulses during cuff deflation.

I used a switch statement. Gave it input from a comparator which compares the real-time pressure with user-set pressure. I put the DAQ Assistant inside this switch. I said to NI 9263, keep supplying my motor relay with rated voltage until the pressure is lower than the user-specified pressure. When this pressure exceed the user-specified pressure, I set the DAQ Assistant voltage to relay as zero, since I want the motor to stop.

The above is OK. But when the cuff starts to deflate, again, the pressure becomes lower than the reference (user-defined) pressure. As a result the switch statement switches again and sends voltage to relay to run the motor again.

I want something which can start off my supplying the relay with rated voltage to run the motor. As soon as real-time pressure exceeds user-defined pressure for the 1st time, I want the relay voltage to be set to zero, being unaffected by the fact that during cuff deflation, the real-time pressure will fall again below the reference pressure. I don't want the motor to run after it has pumped to a desired pressure, the first time.

Thanks a lot!

Saif

post-27603-0-92104600-1345168901_thumb.j

post-27603-0-89444000-1345168905_thumb.j

Link to post

Hi Shaun and Asbo,

Thank you for your replies!

I tried what Shaun suggested. Please see pictures.

The Boolean cross-over is detected and the motor stops momentarily. But then turns back on. Sorry but I am still a bit new to Labview.

How do I utilize that cross-over trigger to keep it off for the rest of the recording?

Thanks again!

Saif

post-27603-0-77783600-1345184582_thumb.j

post-27603-0-97819500-1345184586_thumb.j

Link to post
There are several ways. For example, you can use this VI to detect the "direction" of your boolean change.

Thank you I didn't know this VI existed I've always been using the OpenG Boolean Trigger VI, which seems to have a better name, and icon, for the function it performs, but I would rather use a NI VI than an OpenG VI if their functions are the same.

Link to post

Hi Shaun and Asbo,

Thank you for your replies!

I tried what Shaun suggested. Please see pictures.

The Boolean cross-over is detected and the motor stops momentarily. But then turns back on. Sorry but I am still a bit new to Labview.

How do I utilize that cross-over trigger to keep it off for the rest of the recording?

Thanks again!

Saif

The output will be "TRUE" if the direction is detected. It looks like your case structure is set to "False" to turn off. Try swapping the cases around.

It is usually better to post your VI or an example of what you are trying to achieve rather than an image. For simple VIs you sometimes get back the VI with the changes.

Thank you I didn't know this VI existed I've always been using the OpenG Boolean Trigger VI, which seems to have a better name, and icon, for the function it performs, but I would rather use a NI VI than an OpenG VI if their functions are the same.

There is a lot of replication in the openG VIs, presumably for completeness. Not using the openG stuff forces me to look in some of the more obscure palettes.

Link to post

Hi Shaun,

Thank you so much for your response!

I think I tried what you suggested. But it seems to only work with what I have. Do you mean change the initialization pin to TRUE? When I do that, nothing happens.

I am attaching the VI now. I would be very grateful If you could please advise what I might be doing wrong!

Cheers,

Saif

Ex_7a.vi

Link to post

Create a shift register on your loop, OR its value with the output from the boolean direction VI, and store the result back into the shift register. That value represents whether to turn the motor off.

Link to post

Hi Shaun and Asbo,

Thanks so much for your responses.

Shaun, the VI you uploaded works just fine! I used help commands to understand it. The feedback loop combined with AND and OR gate to achieve "latching" is a great idea! Also, the use of selector function for sending command to the motor is simple and straightforward.

Can I please ask another question? Suppose a USER hits the stop button during cuff inflation (motor ON). At that point I would like the motor to stop. The program does EXIT, which is fine. But if the motor could also stop, that would be great!

Hope this is possible :)

Thanks again for all your help!

Saif

Link to post

Suppose a USER hits the stop button during cuff inflation (motor ON). At that point I would like the motor to stop. The program does EXIT, which is fine. But if the motor could also stop, that would be great!

Just put another motor stop (set the motor value to zero) outside the while loop so that it gets executed after the while loop stops. I'll leave you to figure out how to sequence it to make sure it happens after the loop stops rather than while the loop is running (hint, don't use sequence frames, ever!)

Link to post

Hi Shaun,

Thank you so much for all your guidance!

What I did was that I wired the STOP button to the motor voltage module (inside a SWITCH statement) that I kept outside the WHILE loop. So, when STOP is true, I send zero voltage to the motor. This EXITS the program as well as STOPS the motor.

Please see attached VI.

I have two questions:

1. Is this a smart way of doing it?

2. This does not work if the user hits the ABORT button instead of STOP button! So, I went into File --> VI Properties and made the ABORT button invisible when the VI runs. In this situation, the user can only see my STOP button and is forced to use that to exit. Is is this OK?

Thanks again!

Saif

Ex_7b.vi

Link to post

What I did was that I wired the STOP button to the motor voltage module (inside a SWITCH statement) that I kept outside the WHILE loop. So, when STOP is true, I send zero voltage to the motor. This EXITS the program as well as STOPS the motor.

If it works. It's good.

1. Is this a smart way of doing it?

There are many ways of doing things and whilst there are "accepted" solutions to common problems; "Smart" is subjective. Your only objective was to "sequence" the drive shutdown since LabVIEW is inherently parallel, and there are a lot of ways you could have achieved that.

For example. In addition to your solution, you could also have wired the error terminals on the express VIs to outside the loop (a very common way of sequencing VIs). or for that matter, the 0. You could also have OR'd the STOP boolean to the selector. Worry about "smart" when you know where all the things are in the palettes, you've got a few utilities in your toolbox, written a few programs and been on some courses.

This program is the "first pass" (your prototype, if you like). I can guarantee you will be revisiting it making it "smarter", prettier or more flexible.

2. This does not work if the user hits the ABORT button instead of STOP button! So, I went into File --> VI Properties and made the ABORT button invisible when the VI runs. In this situation, the user can only see my STOP button and is forced to use that to exit. Is is this OK?

The stop button in the IDE is for the developer only. In deployed applications, users should not have access to it since it circumvents shutdown procedures by stopping the code dead. Never give the user any opportunity to do something you are not expecting otherwise he/she will!

Edited by ShaunR
  • Like 1
Link to post

2. This does not work if the user hits the ABORT button instead of STOP button! So, I went into File --> VI Properties and made the ABORT button invisible when the VI runs. In this situation, the user can only see my STOP button and is forced to use that to exit. Is is this OK?

Consider the abort button as a synonym to using a concrete wall to stop your car with. It works but can have undesirable effects! :D

  • Like 1
Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By drjdpowell
      I am just starting on trying to be able to use Python code from a LabVIEW application (mostly for some image analysis stuff).  This is for a large project where some programmers are more comfortable developing in Python than LabVIEW.  I have not done any Python before, and their seem to be a bewildering array of options; many IDE's, Libraries, and Python-LabVIEW connectors.  
      So I was wondering if people who have been using Python with LabVIEW can give their experiences and describe what set of technologies they use.
    • By Yaw Mensah
      I have installed Labview 2020 on Dedian Buster using the rpm to deb conversion method via alien. Due to Architecture mismatch i deleted the *i386.rpm files before conversion.
      My Problem is that after creating a project at "Build Specification"-> "rigth click" i am only able to select "Source Distribution". Application does not show up as an option. 
      I will be grateful for any suggestions.
      Thank you in advance.
    • By javier_r
      VIPM.io now allows you to post LabVIEW Resources, Ideas, and Tools. For example, you could post a link to a video tutorial or blog article about a package. You can also post ideas, like feature requests or new tools. Best of all, package developers are notified when you post your ideas and resources, and you can comment and discuss posts with the community. Take a look at this video to learn more: https://www.vipm.io/posts/664960df-f111-4e13-989a-24be8207182d/

    • By Shuvankar Das
      I want to connect My ccd camera with labview. The details of my system is given bellow. I cannot connect it please help   OS:  WINDOWS 7, 64bit   LabView Run-Time 2013(64-bit) NI-IMAQ 4.8 NI-IMAQdx 4.3   Camera: QICAM Monochrome Cooled (QIC-F-M-12-C) Model QICAM Resolution 1392 x 1040 Sensor 1/2" Sony ICX205 progressive-scan interline CCD Pixel Size 4.65 x 4.65µm Cooling Type Peltier thermoelectric cooling to 25˚C below ambient Digital Output 12 bit Video Output FireWire (IEEE 1394b) Max. Frame Rate 10 fps full resolution @ 12 bits Pixel Scan 20, 10, 5, 2.5MHz Mount Type C-mount optical format  
       
    • By javier_r
      Hello everybody!
      Wondering how many people have tried the new vipm.io site. We have added a ton of features to make it easy to Discover LabVIEW Tools and there are some cool ones coming soon.
      Check it out and let me know what you think 😀
       
      Javier

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.