07-06-2015 09:42 PM
I'm writing some code to turn two stepper motors with various functions. This is my first program, so I'm sure it's all terrible, but I'm very interested in getting this to work. I've checked for data depenecy, and followed some suggestions to use local variables to fix the issue. This didn't work, so now I'm trying to figure this out.
I know that all functions were capable of running simultaniously, but after some changes (notably putting the whole thing in a while loop to keep the program running until someone hits the exit button), no functions can currently work simultaniously.
I'll post my code in case anyone has the time to look at it (I'd really appreciate it if someone did), but I'm also looking for other issues which might be the source of the problem.
Really, any help is greatly appreciated.
Thanks in advanced
Solved! Go to Solution.
07-06-2015
11:36 PM
- last edited on
12-04-2024
02:19 PM
by
Content Cleaner
Oh boy, there are many many problems 🙂 But it is good, large room to improve and learn! 🙂
Just some points:
I really recommend you to learn LabVIEW, start with the Core 1 and Core 2 course. Here you can find info about options to reach free teaching material:
https://forums.ni.com/t5/Community-Documents/Unofficial-Forum-Rules-and-Guidelines/ta-p/3536495 (under section: "looking for free training")
Have a look at this also:
http://www.ni.com/newsletter/51735/en/
edit: State machine example:
edit2: this is a link you can find from one of the above, but in case you miss it:
http://www.ni.com/newsletter/51770/en/
07-07-2015 12:08 AM
Some additional comments:
07-07-2015 12:04 PM
07-07-2015 12:45 PM - edited 07-07-2015 12:54 PM
In my opinion subVIs only will not fix this enough. I understand time is often critical, but many people do not consider how much time they will lose when the software does not work as it should during its usage. In the end, you may lose more time due to an immature software than win by finish it "fast".
edit: I really would like to help, but due to the size of the VI, it is not something I could clean up in a few minutes or even hours, specially since I do not know the task of the code... 19 frames in a stacked sequence, many hidden controls used as variables instead of using wires and data flow, this code is over which i can consider refactorable...
But for sure we could help to guide you through to rewrite the code. Learn how to program a state machine at least, it is pretty easy. I believe, here you need to use a state machine, probably with an Event structure...
First create a flow chart what your code needs to do, what are the tasks, and the transitions between states + conditions. After this you can program a proper state machine.
07-07-2015 01:10 PM
I completely agree with Blokk.
Having councilled colleagues with similar poorly-structured code to "Start Over" (and to first write down what they want to do, and not to worry about how they need to do it) and seen this advice ignored "because I need this quickly", when a few weeks have gone by and it is still not working, I have occasionally Started Over on their code, and after a few days, had something that "mostly" worked (and was much easier to debug) and frequently worked much better (i.e. was faster, or permitted 24 parallel processes instead of 7, etc.). The "catch", of course, is you need to "give up" on such things as Stacked Frames, Block Diagrams that span multiple monitors, code that has more Wires than Sub-VIs + functions (that's a measure that I just made up, but some of the more atrocious code I've seen has wires running everywhere, crossing up and down, across 3-4 monitors, and connecting only a handful of functions and no user-written sub-VIs).
An Investment of a Week now can save you months down the road ...
Bob Schor
07-07-2015
01:10 PM
- last edited on
12-04-2024
02:20 PM
by
Content Cleaner
To supplement what Blokk is saying, take a look at this.
07-07-2015 03:23 PM - edited 07-07-2015 03:32 PM
To answer a previous question, yes, I have a good bit of experience with text-based programming languages. I'm sure it shows.
So just use a state machine for the initialization function intstead of using the 19 long stacked sequences?
I'm a bit confused about how to do wait timers in a data flow scenario, unless you maybe do a while loop sub-vi with a case statement inside, and have the iteration variable (i) and a division with remander (mod) to select what to do during the while loop?
For instance my sweep function has 4 basic things inside of it, a move left, a wait, a move right, and then another right. I would want to do a mod4 function on the iteration variable. Make a while loop, using the event handler, then where mod4 produces a 1, move left, when mod4 produces a 2, move right, etc...
Another quesiton about state machines. Do you suggest that I put the whole thing into a state machine? Looking at them, it seems like it would require mulitple states to exist simultaniously. Which doesn't seem to be the way any examples I've looked at work. They each have 1 user imput, which then changes the state to something else. I would want at minimum 2 states to exist simultaniously if i'm thinking of states as calls to a function. (Which again, might not be the correct way to think about it)
edit: Also - i'm also 95% sure that you're right about the while loop waiting until the inside loop finishes. I'll select one button go button, then that while loop starts. Clicking another go button would do something, except that the outside while loop has already decided that it doesn't need to run that function (since at the beginning, it was turned off), thus it's waiting for the inside loop to finish before it repeats the check to see which functions need to run. Is that what you meant?
07-07-2015 03:40 PM
Here's an Idea (not necessarily the Best Idea) for adding a Wait to a State Machine -- make a State called (are you ready?) Wait. Create two Shift Registers, one with an I32 with a label called "Delay" and a second labelled "State After Delay" for the State after the Delay. Now, if State 3 is supposed to be followed by a 4 second delay, followed by State 4, before leaving State 3 wire 3000 (3 seconds) into Delay, State 4 into State After Delay, and make the Next State "Wait". You will enter the Wait State, wire the Delay into a Wait (ms) function and wire the State After Delay to Next State. You'll wait for the Delay Time, then do what you were supposed to do after the Next State. Note that the Wait State is very flexible -- it can wait for any amount of time (you decide) and do any subsequent State (again, you decide).
Bob Schor
07-07-2015 09:08 PM
When someone is new to LabVIEW, it's not ideal to give them broken tools. Why would you ever suggest he setup something that will prevent his code from responding to user input for 3 seconds?
That's twice you've suggested this behavior today. Please spend more time with the wait functions before suggesting how to use them =/