Sampling mouse input at predefined frequency

eghbal.hosseini's Avatar

eghbal.hosseini

10 Feb, 2016 02:52 PM

Hi Chris,

I was wondering if it is possible to sample the mouse_x and mouse_y at a predefined frequency in mworks,(1kHz similar to eye_x and eye_y).

Thanks,
Eghbal

  1. Support Staff 1 Posted by Christopher Sta... on 10 Feb, 2016 03:24 PM

    Christopher Stawarz's Avatar

    Hi Eghbal,

    I was wondering if it is possible to sample the mouse_x and mouse_y at a predefined frequency in mworks,(1kHz similar to eye_x and eye_y).

    You can achieve this using scheduled actions. See the attached example experiment for a demonstration.

    A couple important points:

    • A repeats value of -999 means "repeat forever".
    • The variable associated with the cancel parameter must be set to 1 before the experiment stops. Otherwise, the scheduled actions will continue indefinitely, even after the experiment is closed. (This is really a bug that needs to be fixed).

    Cheers,
    Chris

  2. 2 Posted by eghbal.hosseini on 10 Feb, 2016 08:32 PM

    eghbal.hosseini's Avatar

    Hi Chris,
    Thanks for the code ,
    I am looking at the time steps of mouse updates, and it is variable through the ranging from ~950 us to ~1050 us.Is this expected?
    Thanks
    Eghbal

  3. Support Staff 3 Posted by Christopher Sta... on 11 Feb, 2016 02:50 PM

    Christopher Stawarz's Avatar

    Hi Eghbal,

    I am looking at the time steps of mouse updates, and it is variable through the ranging from ~950 us to ~1050 us.Is this expected?

    Yes, that seems reasonable. The waits between repetitions are software timed, so there's going to be some variability in their durations. (This is opposed to, say, NIDAQ analog input, which is hardware timed, with each sample triggered by an onboard clock.)

    Cheers,
    Chris

  4. 4 Posted by eghbal.hosseini on 11 Feb, 2016 03:20 PM

    eghbal.hosseini's Avatar

    Hi Chris,
    Thanks,
    Is it possible to reduce the variability if I go to lower sampling rate (~200Hz). Ideally, I want to have a fixed sampling interval for the variable.

    Eghbal

  5. Support Staff 5 Posted by Christopher Sta... on 11 Feb, 2016 08:14 PM

    Christopher Stawarz's Avatar

    Is it possible to reduce the variability if I go to lower sampling rate (~200Hz). Ideally, I want to have a fixed sampling interval for the variable.

    No, that won't make any difference. With software-timed waits on a non-realtime operating system like OS X, getting to within a few hundred microseconds of your target is the best you're likely to do.

    Chris

  6. Christopher Stawarz closed this discussion on 17 Feb, 2016 03:25 PM.

  7. eghbal.hosseini re-opened this discussion on 19 Feb, 2016 05:44 PM

  8. 6 Posted by eghbal.hosseini on 19 Feb, 2016 05:55 PM

    eghbal.hosseini's Avatar

    Hi Chris,

    Sorry I had a quick question as I am trying to use the predefined sampling to update the cursor shown on the screen.
     I noticed that if I add a frame list for the cursor display, the update in mouse position happens at a slower sample rate ~150Hz even though the update on mouse is at 1kHz.

    Thanks,
    Eghbal

  9. Support Staff 7 Posted by Christopher Sta... on 20 Feb, 2016 01:31 PM

    Christopher Stawarz's Avatar

    Hi Eghbal,

    By "update in mouse position", do you mean changes to the mouse_x/mouse_y values, or changes in the position of the cursor on screen? I see that your cursor_dot stimulus is using raw_mouse_x/raw_mouse_y for its position, so its position will change only when the mouse actually moves.

    Also, if the Schedule Actions that sets mouse_x/mouse_y falls behind schedule by more than 5ms, you should see warnings and/or errors in the server console. Have you noticed these? I don't see any when I run your example.

    Thanks,
    Chris

  10. 8 Posted by eghbal.hosseini on 22 Feb, 2016 08:02 PM

    eghbal.hosseini's Avatar

    Hey Chris,
    Sorry about the confusion, I wanted to get a readout of mouse_x/mouse_y values, cursor updates correctly on the screen.
    I don't see the error too, but when I look at the data, there are multiple rows(around 7 samples) with the same position values, so the effective sampling frequency is about 150Hz. I have attached an example.

    Thanks,
    Eghbal

  11. Support Staff 9 Posted by Christopher Sta... on 02 Mar, 2016 02:54 PM

    Christopher Stawarz's Avatar

    To close this out: Eghbal was hoping to increase the rate at which the mouse position was actually updated (with new position data) to 1kHz. However, MWorks' mouse interface relies on mouse movement events delivered by the OS, and it can't control the rate at which those events are sent. As an alternative, we might try getting the mouse input data at a lower level (e.g. the raw USB HID events), but that would be complicated and might not yield a better data resolution. I suggested that Eghbal consider using alternative, possibly custom-designed hardware for user input.

  12. Christopher Stawarz closed this discussion on 02 Mar, 2016 02:54 PM.

  13. Christopher Stawarz closed this discussion on 19 May, 2016 07:49 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac