12-08-2012 03:24 AM
Dear All,
I am working on a program to show mouse movement trajectories. Specifically, at first the program is required to provide a target trajectory, e.g. a circle; then the user is required to track the circle using the mouse, so in order to know the user's performance, the program is supposed to show the trajectory of the mouse; in the last, the difference between the target and the mouse movements will be analyzed.
Since I just start to use labview, I really hope you could give me suggestions on how to :
1) show the target trajectory in labview;
2) show the mouse trajectory when tracking the target; (I know how to get the positions of the cursor but I do not know how to show the mouse trajectories)
3) analyze the differences between the two circles.
Thank you very much for your kind help.
Li
12-08-2012 12:03 PM
First I would suggest going through some prep material, such as some of these tutorials.
I'm going to assume you don't have the Vision Development Module, which I believe has some tools which might help with the analysis.
There's a quick example showing drawing points at specific points on the screen in a circular pattern here. Note the shift register which is used to keep the current value of the image. Placing a probe on it and running it with breakpoints or execution highlighting might help to understand how it works.
The basic concept in that example can be used to draw both the circle the mouse points.
The more complex issue might be comparing the two. The naive solution (no clever algorithms) that pops into my mind would be to take N points from when the user has the mouse down and then check their distance from the circle's points. The big question here is which point to check against, and you could either check against M points and use the minimum value or keep track of where you expect to be in the circle (which you might need to).
12-09-2012 12:03 AM
Thank you very much for your instructions. The tutorials and the example are very helpful.
I think it is easier to complete the tasks one by one, so first I have made a simple program to show the target trajectory and the positions of the cursor in the picture. However, I do not know how to show the mouse trajectories using the cursors' positions in the picture. Is it possible to demonstrate the mouse trajectories as the user moves the mouse?
As for comparing the two, I am thinking, for the points have the same x scale in the two circle, the program could calculate the average distance of their y scales.
Thank you again for your help.
Li
12-09-2012 12:28 PM - edited 12-09-2012 12:29 PM
Here's an example modification. Note that I used a completely different method for acquiring the cursor position. There are two reasons for that:
Note that this modification uses several different concepts (using multiple loops, stopping a loop using the error, making sure you're not flooded with events), so be sure you understand all of them.
Also note that the example isn't actually fully correct. It shows the basic example, but it's off and it has some bugs, which I will leave to you to resolve. You will also note that it doesn't save the list of points. You can add a couple of easy modifications for that (hint - a shift register might help if you want to maintain a value between different iterations of a loop and a queue can also help you here).
12-10-2012 03:29 AM
The new method is soooo brilliant. It makes the conversion so much easier by using the coordinates of the cursor to subtract the coordinates of the picture.
I think I can understand most of the example modification, because it is easier to understand than to make it. Thank you a lot. But I cannot find where the bug is.
I add something more to save the list of points in an excel (the pathes should be different on your computer), and use the data to calculate the average distance between the points and the center of the circle, which maybe a simple way to analyze the differences between the two trajectories. However, there seems to be some problems when N is too big. Could you please help me providing a better way?
Li
12-10-2012 08:21 AM
Well, the problems with the code can be seen by running it - things such as the first and last points, what happens when the mouse is not on the picture, what happens when you try to stop the VI, the fact that the circle is not actually drawn where the pointer is, etc.
As for the analysis, using a file to keep the current list of points is a particularly inefficient way of doing this. It would be much more efficient to do this in memory (as I suggested, a shift register or a queue might help you there).
Also, I don't have Mathscript support installed, so I can't really comment on your code. I would suggest rewriting it using LabVIEW primitives, which will also allow you to debug the intermediate values. One thing that comes to mind is that you're analyzing every point, but you're not actually analyzing the average - to do that, you would need to auto index the values out of the loop, which will build an array of the results. Another thing is that you would probably want to analyze each point individually, as the average can lie if points outside the circle have corresponding points inside the circle. One last thing is that this doesn't check the order and distribution of the points, only that they're all on the circumference.
12-11-2012 12:50 AM
You are right that the solution with the shift register is more convenient. I did not know that before.
I have removed the Mathscript part by using the LabVIEW primitives. Now after the ANALYZE and STOP button are pressed, the average distance can be calculated.
As for the problems, I think maybe boundaries can be set in the program. As shown in the figure, the black circle is the target trajectory, while the red circles are the boundaries. If the cursor enter the region between the two red circles, the mouse trajectory will be displayed. If the cursor is out of the region, the path should not be demonstrated. Then the problems with the first points can be solved. Is this ok? The problem is that I do not know how to set these boundaries in the program, so could you teach me with that? And I do not know what do you mean by the circle is not actually drawn where the pointer is. Thank you very mush for your kind help!
Li
12-12-2012 03:15 PM
More comments:
12-17-2012 08:34 PM
I think comment 2# is very good, but I do not know how to combine the mouse click with this program. Could you help me with that? Thank you very much.
12-18-2012 01:43 AM
I didn't mean you should generate a mouse click, but that you should let the user click on the picture to trigger the monitoring. You can identify that mouse click with the event structure.
Remember that eventually you're going to have to do the actual work yourself, so it would help if you had a clear picture in your mind of how the UI and the program should behave. Once you know that, it will give you a direction for how to proceed with the actual code.