LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a State to Case Structure

I am trying to add another state to a state machine in a program that was written by someone else. I just need to add another state the program will only go to if someone presses a "kill switch." This program controls a motor that places weight on a patient's back and the end user wants the patient to have a kill switch if it becomes too painful.  The problem I'm running into is when I add another state to the state machine by adding it to the Enum it renames all of the other states to numbers, and if I try to add it on the top of the state machine it turns red.  How do I add this "kill switch" state without affecting the other states in the state machine?

 

I've attached the original and a copy with the changes I made to the state machine.

Download All
0 Kudos
Message 1 of 13
(4,482 Views)

I suggest you to hardwire the switch to cut of the motor power first ()without releasing the grip of whatever the moter could drop on your patients head). Then go on with the programming.

 

Felix

 

Edit: Found you software problem: watch the coersion dot! The first case is unconnected tunnel, which defines I32 instead of enum for the whole case. Rearrange cases, then it should be ok (propably you need it before appling the change, use add case after...)

Message Edited by F. Schubert on 06-08-2009 02:51 PM
0 Kudos
Message 2 of 13
(4,480 Views)

Well, if you simply cut power to the motor, then it will leave the weight on the patient. We need the motor to move back to its "upper position." This is an AC motor so I cannot control the position like a servo or stepper motor. The person who designed this system has two switches that indicate when the motor has moved the weight to its lower position and upper position.

 

I've figured out how to add the new position, but now the program automatically jumps to my new state "kill" eventhough the conditions aren't right for it to jump. What I've done now is to add another digital input to the task and if that happens it will jump to the "kill state" where I can write the code for the motor to run into returns the motor to its high position and then it will exit the program. So, why is my program automatically going to the "kill" state?

0 Kudos
Message 3 of 13
(4,466 Views)

From the point of risk management (I guess you are building a medical device because you mentioned a patient) you should think of implementing some hardware means to lift the weight from the patient. Of course depending on the worst possible outcome of an unwanted situation. It can become somehow tricky to lift the weight if the programm or the computer crashed. I would read the emergency push button as an update for software state and the device should automatically lift the weight in case of an emergency (if the worst possible outcome is some injuries).

 

Jörn

0 Kudos
Message 4 of 13
(4,452 Views)

When working with state machines, it is a good idea from the beginning to set up a type def for the enum that defines the states.  That way when you add a state to the type def, all constants, controls and indicators will be automatically updated.  Now that the program is already written, you are force to find all constants and update them manually.

 

If you turn it into a typedef now, you will still be forced to update them all to the typedef version, but once you've done that, you should never need to do it again.

Message 5 of 13
(4,444 Views)

The overall design of the system I cannot change. Someone else designed it, and now they are gone. I am trying to do this remotely using an NI Elvis II instead of the USB DAQ card that is on the equipment 40+ miles away. I was just asked to put in a state that would wait until the motor returns to its up position and terminate the program. 

 

Anyways, I think I have configured it the way I want. I have added "Read DAQmx" for each state. So, the signal can be detected no matter what stage the program is in. If the motor is already in its up stage then it goes directly to finish. However, if the motor is either in the low stage or the run stage it jumps to the kill stage and it runs the motor until it reaches the up stage. Then it goes to finish. I've put a probe to detect what stage it is in, and I can get it to go to the kill and finish stages by using the kill switch, but the actual LabVIEW program does not stop running. Can you see anything that is keeping it from stopping?

0 Kudos
Message 6 of 13
(4,440 Views)
Note, when I mention I cannot change the system design. I am talking about the actual rig that the program is controlling. Raven, thanks for the post. Yeah, the person who wrote this did not do what you suggest. So, I had to go in manually and add the new stage on each one.
Message 7 of 13
(4,438 Views)

"Dittoes" to Raven's Fan  http://forums.ni.com/ni/board/message?board.id=130&message.id=6067#M6067

 

Smiley Sad 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 13
(4,429 Views)

Your program will keep running until one of two things happen to stop the lower while loop.

 

1.  There is an error in the DAQmx Read.  Pretty unlikely this will happen assuming it has already been running just fine.

2.  The user presses the stop program button.

 

You may want to use a notifier or a local variable that gets set when the upper while loop stops in order to tell the lower while loop to stop.

Message 9 of 13
(4,410 Views)

I am having a problem with a state machine where I used the Type Def for the Enum. I am now trying to add a state. I open the Enum Type Def and add a case. When I do this, the Case Structure changes to numerical values from the previous named values. What am I missing? I have auto-updated Type Def enabled.

0 Kudos
Message 10 of 13
(4,028 Views)