08-21-2012 01:42 PM - edited 08-21-2012 01:44 PM
Hello again,
Is there a way to call a state in a state machine after it has already ran? To elaborate, I have a program that will set pressure in increments of 20% and will then write to a file. Once it is done with the highest pressure state (100%), I want it to repeat the test again, but this time in decrements of 20%. So, it will do:
1. Set pressure at lowest point
2. Read meter and write value
3. Set pressure at 20%
4. Read meter and write value
All the way up to 100%, then:
5. Set pressure at 80%
6. Read meter and write value
7. Set pressure at 60%
8. Read meter and write value
All the way down to the lowest point.
Is there a way to do this instead of making a state for read and writes at each percentage? That way I don't have Read Agilent 20% Increment, Read Agilent 40% Increment, etc.
I've attached the code to help explain what I'm talking about.
Thanks everyone, still a newbie
Solved! Go to Solution.
08-21-2012 01:45 PM - edited 08-21-2012 01:51 PM
The app will have to have some kind of logic to feed back the states the values you want to change.
You can put the variables in a cluster, and put the values into an array, and then you can index the array to feed the values into the cluster for each state. So then you have one pressure state that uses different values.
In your example you could use a shift register to hold the multiplier value, and index values into the shift register after each time the pressure is called.
***
If you just want to get your program done, you could index the states ( 20%, 40%, etc...) so that after each "write data agilest" you could feed the next % state to the state shift register. This is not the preferred method from scratch, IMHO, but if you just want to get you program going as you already made all the % states ... 🙂
08-21-2012 01:48 PM - edited 08-21-2012 01:53 PM
Hi Mark,
Is it possible to do this without any user intervention? I want it to be 100% automated aside from putting the part number in. If so, I'm not sure how to do that. Do you know of any examples I could look at?
I do want to get the program going, but I don't mind deleting the states if there's a better way. If there's a better way to do it I would love to do it because I would use the design in the future.
08-21-2012 01:53 PM - edited 08-21-2012 01:56 PM
Yes, everything I described is automatic, no user intervention. ( I edited my post, please review ). As I understand what you are asking, you don't want to have multiple states where the only difference is the multiplier value.
But, you do already have all those states, so you can decide to re-write for flexibility and future expansion, or just index the state enum as described above.
***
Missed the part about decrementing afterwards. The idea is identical, you have an array that has the values you want in the order you want. If the pattern repeats, then you have to reset the index to start at the beginning after each run.
If you are going up then down, then repeating, I would suggest putting the values in order 20,40 ...100 .... 40, 20, and then repeat that sequence.
Alternatively, you can use an array of the state names as you already have the 20, 40, ... etc... states written.
08-21-2012 01:55 PM
Mark,
Can you provide me with an example? I really don't know where to begin on your solution but it sounds like the perfect solution.
08-21-2012 02:16 PM - edited 08-21-2012 02:21 PM
Ha Ha, Ok, here is a functionality example. The loop pulls values from an array and passes them into the same state (pressure). Much like passing in your multiplier value.
This VI runs forever, so I put in a stop button. A real app will have more complicated stop conditions. Also, in you app, you would put the indexing into it's own state so that it fires only after the "write agilent" state. So you would go --> init stuff, pressure, read agilent, write agilent, index (with index check), check stop conditions, ..(repeat at pressure).
Hope this helps.
(Paste snippet to desktop, drag onto a VI.)
08-21-2012 02:20 PM
Awesome, thanks for your help Mark. I appreciate it greatly.
Take care
08-21-2012 04:25 PM
Given that you don't really have a state machine in this case but simply an adjustment to a setting here is an alternative solution.
08-21-2012 06:06 PM - edited 08-21-2012 06:06 PM
@Mark_Yedinak wrote:
Given that you don't really have a state machine in this case but simply an adjustment to a setting here is an alternative solution.
Hello Mark,
Thanks for replying. I've been trying to figure out how to incorporate the code that I accepted as a solution into the state machine I already have, but I'm not sure how. How would I make this a state inside the state machine? Also, in the application, the min and max pressures won't be constants, they'll change with the corresponding part.
Thanks for your help
08-22-2012 08:02 AM
Here's the steps that I want the state machine to do:
1. Before initializing, user enters a part number which is sent to a database to return values
2. Begin the state machine with the Initialize Druck (pressure calibrator) state
3. Pull the beginning pressure from the database and Set Pressure.
4. Initialize Agilent Multimeter
5. Read Meter
6. Write Data from Meter
7. Return to step 3, incrementing the pressure by 20%
8. Repeat steps 5 & 6
9. Return to step 3, incrementing pressure by 20%
This repeats steps 3, 5 and 6 until it has gone from the lowest pressure to the highest pressure by increments of 20%, then down to the lowest pressure by decrements of 20%. 0-100-0. I'm not sure how to include the proposed above solutions in the "Set Pressure" state.
Thanks again for the help.