LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

IF THEN Functions help on VI

Hi there,

 

I am working on a VI where I am trying to control a step motor using LABVIEW. Here, I have on the block diagram a Boolean Property to "stop motor" as well as a "Speed Change"

 

The problem I am now faced is, everything when I have both the "stop motor" property on TRUE as well as the "speed change" property on TRUE, the block diagram would read stop motor and then change speed which then leads to the block diagram not responding to my stop motor instead.

 

Can anyone help me out here in my block diagram where I can hit the "stop motor" property and would force all the other commands property, IE: "Speed change" to go to false?

 

I have attached my VI and a print screen. Hope this helps.

Download All
0 Kudos
Message 1 of 35
(4,299 Views)

How are you running your VI?

 

You have one small while loop doing voltage output, but the section with your case structures doing the motor control will only run once because it is outside of the while loop.

 

If you don't want the other parts of the code to run if it is stop motor, why don't you put that code in the False case of the stop motor button?

 

Another alternative is to use boolean logic where if speed change is true and stop motor is false, to only run the speed change code.  A compound arithmetic node set for AND, where is it Speed change AND (NOT Stop motor) would work.

0 Kudos
Message 2 of 35
(4,280 Views)

Raven,

 

Thanks for your kind and quick response. Were you able to open up the VI that I have attached? I am sorry because I might not get it completely what you were trying to say.

 

Would you be able to show it to me through the VI that I have attached? Thanks in advance!

0 Kudos
Message 3 of 35
(4,274 Views)

The top part of your code (the big case structure) and the VISA stuff only executes once because it's not inside a loop. The only thing that's in a loop is the "DaqIO Voltage Output Update" VI. See the attached example for the concept.

 

Did you actually write that VI? It looks like a copy and paste of two different VIs. You need to have either two loops if the two parts are supposed to be independent, or you need to put the upper stuff inside the loop. I have no idea which is the proper method since I don't know the details of how your motor control is supposed to work in conjunction with the data acquisition.

Message 4 of 35
(4,264 Views)

I totally understand your reply, but I have tried putting the motor control case structure into the loop and it keeps failing on me. Let me make my problem clear here:

 

If you open up the VI that I have attached, when the "STOP MOTOR" is true, then it will send a SK command which is stop and kill. But IF at the same time the "SPEED CHANCE" case structure is true then, the SK command would not work. I will have to go to my front panel and off the speed change button in order or my stop motor button to work.

 

I am trying to make the stop motor to overwrite all the other command where even if I have my speed change button on, my stop motor button would still work.

 

I have tried all different kinds of way but still doesn't work. I am guessing I must be stupid and dumb. So please bare with me and any help would be very very much appreciated. Thanks in advance.

 

Jlam

0 Kudos
Message 5 of 35
(4,204 Views)

Post your latest version of the VI so we can see what you are doing now.

0 Kudos
Message 6 of 35
(4,195 Views)

You whole architecture is wrong.  The Stop Motor button is read and acted upon before the Speed Change button.  So if you press stop, it is read, and then later the Speed Change button is read and the code replaces whatever stop command with a speed change command.  Just look at the data flow.  The last command to be issued wipes out the previous one.  Also, your top case structure executes only once.  The bottom loop keeps going.  While the bottom loop is running, you could press stop or speed change or reverse all you want, but nothing will happen because that part of the code is over and done with.  It won't run again.

 

You should use an event structure to act upon your buttons.  If you press stop, its event case can send the proper command.  When you press speed change, its event sends its command.  Then there is no overwritting stop commands with speed commands.  Only one command is sent.  This should all be in a loop so that you can repeatedly press buttons to cause actions.  Also have an event case for the End Acquisition button to stop the program.  You acquisition loop can be put into the Timeout case so it executes continuously until someone presses a button.  Or this loop can run in parallel to the event loop, and you would have to use a notifier to send a command from the event loop to stop the acquisition loop.

 

Look at event structures and notifiers (or queues).

 

- tbob

Inventor of the WORM Global
Message 7 of 35
(4,185 Views)

Tbob,

 

Thank you for your kind advice. I tried using the event structure but wasn't able to wire it. Would you be able to provide me an example on the VI if possible? Thanks.

0 Kudos
Message 8 of 35
(4,161 Views)

The attached vi is in LV2009.  It is a state machine with an event structure in it. The vi is not complete.  It is just a starter.  You will have to add your code where indicated.  Also you have to create events for two of the buttons.  I wanted you to get some practice.

The state machine starts with initialization code, which you have to put in.  The next state is the events state.  Here, the code waits for the user to press a button.  If it is a button to send a serial command, the command is put on the shift register and the next state called is the SendCmd state which will hold the serial write and read, once you put it there.  After that the next state is back to the events state.  Pressing the stop button calls the exit state which stops the state machine.

 

Now for you parallel Acquisition loop.  Put it in parallel with the state machine.  In order to stop that loop with the same stop button, you can add a notifier to your code.  Set the notifier to True in the exit state.  In the Acquisition loop, read the notifer.  Wire the output to the stop sign.  When you press the stop button, the True boolean will reach the stop sign, stopping that loop as well.

 

If you run into problems, post your code.

 

- tbob

Inventor of the WORM Global
Message 9 of 35
(4,111 Views)

Also you should always try and use enumerated value as the state control for your SM.  It should be saved as a unique type def. 

 

0 Kudos
Message 10 of 35
(4,089 Views)