07-19-2016 03:37 PM
I'm using labview 2015 to design a laser alignment system, using an ag-uc2 contoller, a piezo driven optical mount, and two webcams. The set up is that the webcams are positioned behind mirrors, which are a little leaky, so the webcam will get a shot of where the laser beam is pointed. The laser is to be manually aligned first, and after one is satisfied with the alignment, this program will be executed once to run in the background. checking the position of the laser a few times a minute to correct for thermal drift. After it is first executed, I'd like the program to take perhaps 10-15 frames, to find an average centroid location on each of the mirrors, then switch over to comparing the new frames to that template centroid. My trouble is that I can't think of a way to obtain a template image and have that info carry over to the next iteration of the while loop that the whole program needs to run in. I've tried using case structures, which I imagine will ultimately be the solution, but it didn't work as expected. I set the case structure to execute depending on the value of the loop iteration indicator of the main loop, and I had a while loop in there with shift registers to collect the centroid for that loop, and store that information for the next loop. I can see after running the program why my set up doesn't work, however I'm not sure how else I can design something that will take an average of multiple frames. I think that I should be using learn and compare template, however I'm not sure how I can convert a cluster (centroid) to the proper data type for the template comparistion VIs. Whether you have suggestions for my existing code, or would like to offer a different approach, I appreciate it. Also let me know if you need any other VIs included.
Solved! Go to Solution.
07-19-2016 04:05 PM
In the past, when I have had to switch between two "modes", as you're doing, I've either used two consecutive While loops, one for the first mode and one for the second, or I'd put in a boolean shift register to indicate which of the two modes the loop was in. If you start in one mode, and then later switch to the other one time and one time only, then you can use an "OR" node as a latch to feed the old mode in, so the first True you feed in keeps it True until the next time you run the VI and it goes back to False.
I would also add that I looked at your VI and the method you use to average 10 frames, while innovative, is generally not a great plan. Instead of having 10 shift registers construct a fixed-size array, just have one array in a shift register, append each new measurement to the end, and use the Mean VI from the mathematics/statistics palette to compute the average.