LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use Labview(8.6) to show mouse trajectory

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.Smiley Happy

 

Li

 

0 Kudos
Message 1 of 13
(3,435 Views)

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).


___________________
Try to take over the world!
Message 2 of 13
(3,413 Views)

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. Smiley Wink 

 

Li

 

 

 

0 Kudos
Message 3 of 13
(3,391 Views)

Here's an example modification. Note that I used a completely different method for acquiring the cursor position. There are two reasons for that:

 

  1. Polling is generally not desired. In this case, it's not a big deal, but it's usually prefered to have some sort of event-based system which sleeps when nothing is happening.
  2. The mouse VIs use a global screen coordinate system, which would require several steps to translate to the picture control coordinates. The event uses the same basic system, so the conversion is much easier.

 

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).


___________________
Try to take over the world!
Message 4 of 13
(3,373 Views)

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.Smiley Sad

 

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

 

 

 

 

 

 

0 Kudos
Message 5 of 13
(3,355 Views)

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.


___________________
Try to take over the world!
0 Kudos
Message 6 of 13
(3,339 Views)

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!Smiley Happy

 

Liboundary.png

0 Kudos
Message 7 of 13
(3,318 Views)

More comments:

 

  1. You should always think about the data. You have your array of points in the shift register. You can just take that out of the loop and use that as the input for the processing loop.
  2. It seemed as if you want to analyze the user's performance. To do that, you need to let them perform, not limit them while they're trying to work. If you want to filter bad data, I would suggest a mouse down on the picture to trigger the acquisition and another one to finish it. For the moment, you can use a local variable and set it in the event loop.
  3. In that same direction, if you want a certain piece of code not to execute, you need a conditional block. In LV, that's done with a case structure.
  4. You don't need two separate stops. Just use the one stop to stop both loops.
  5. If you want to compare and analyze something, the Comparison palette has some relevant functions. I would suggest looking at the In Range & Coerce function. You can use that to check that the radius is in the accepted range.

___________________
Try to take over the world!
0 Kudos
Message 8 of 13
(3,289 Views)

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.

0 Kudos
Message 9 of 13
(3,259 Views)

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.


___________________
Try to take over the world!
0 Kudos
Message 10 of 13
(3,252 Views)