Re: sampling rate problem




"wanwan" <ericwan78@xxxxxxxxx> wrote in message
news:1163191311.122185.46730@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

First, this is a threading nightmare.
You need to syncronize so that your reading of mousepos_x and
mousepos_y is atomic. Also, there is no guaranty that your other
thread's data will be accessible to this thread unless you syncronize.

I don't need the mouse positions to be precise to the pixel. I wrote
this class strictly for the purpose of data collection. Data analysis
is not done in real time.

It would ALSO probably be better for you to use the Timer class,
instead of busy-waiting.

Since I made the mouse sampling class a thread, it is doing something
independent of the rest of the software (I am writing a GUI). So I
thought it'd be same idea as Timer class

The other suggestion I have for you is to instead use temporal event
based updates (calculating the change in time from the last position),
rather than polling every n milliseconds.

What is a temporal event? It sounds like interrupt vs polling in asm.
But what in Java can achieve the interrupt effect?

The real question I have for you is, why do you want to sample mouse
movement at all? Is it for some sort of macro? Just an excercise?
Something else that could be done using standard libraries instead of
writing your own sampling method?

It is a software used for engineering research purposes

Well, hope the suggestions help, good luck finding the right way.
Thanks

Since it is unlikely that you will ever get exact timing from sleep or timer
facilities in Java (they make disclaimers about precision and accuracy), it
is better to turn the problem on its head. You get mouse move events from
the system. Check the system time when you get the event, and calculate the
time between events.

I had a similar problem getting accurate timer delays while measuring wind
speed in a weather application that I wrote. I finally realized that I could
use the timer to provide reasonably periodic wake-up events, but I needed to
determine the actual interval since the last event and calculate the wind
velocity using the measured time interval. This works even when huge delays
due to other applications bogging down the system (which can cause delays of
several seconds in some cases). I wrote an article about it - want to read
it? Here it goes: http://mysite.verizon.net/Karl_Uppiano/winddata.html


.



Relevant Pages

  • Re: Time accuracy
    ... WarpVision isn't using the hires timer". ... thread 1 and perform some benchmark counting in thread 2, or is there another way to get delays smaller than DosSleep's lores delays? ... Create the necessary semaphore and data structures ... For anything requiring more than 15 frames per second of animation, the only way to do it reliably on nearly all versions of OS/2 is to interface with the TIMER0 device driver. ...
    (comp.os.os2.programmer.misc)
  • [GIT pull] timers core for 2.6.36
    ... timers: ... +delays - Information on the various kernel delay / sleep mechanisms ... +it really need to delay in atomic context?" ... void msleep; ...
    (Linux-Kernel)
  • Re: Multithread operations
    ... Often this kind of problems are solved by simple disabling the timer at the beginning of the tick event and enable it again at the end. ... It sends the request, receives the answer and updates the controls. ... These delays are due to the send/receive/elaborate functions. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: What can be the cause of slower API execution ?
    ... |> delays on their computers. ... |>> Start = Timer ... Some Windows security settings? ...
    (microsoft.public.vb.general.discussion)