sensors icon indicating copy to clipboard operation
sensors copied to clipboard

Provide a way of tying sensor requests to animation frames

Open tobie opened this issue 11 years ago • 10 comments
trafficstars

Copy pasted from @domenic's original issue https://github.com/rwaldron/sensors/issues/5

For games and other animation frame loop-based situations (off the top of my head, accelerometer-based scrolling comes to mind) you want one value per animation frame.

Chrome is actually doing work specifically to integrate our scheduling of input events and animation frames, see Blink Scheduler design doc.

Off the top of my head, frequency: "animationframe" might be good. The contract being that, if you pass that in to the constructor, then given

requestAnimationFrame(function frame() {
  console.log(mySensor.value);
  requestAnimationFrame(frame);
});

you will get an updated value every frame.

I don't think frequency: 60 is quite the same thing (but I could be wrong; will try to tag in some Blink engineers) since animation frames often vary away from 60 Hz and so you will quickly get out of sync.

Posted to blink-dev: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/fLucJ2QH3fA unsure whether people will follow-up here or there.

Proposed resolution: Enabling developers to tie the frequency of sensor updates to animation framerate is a desirable feature. Further research is needed to see whether or not that is implementable.

Actions:

  • [x] research whether sensor update frequency can be tied to animation framerate.
  • [ ] design the API so that developers can indicate the sensors update frequency must be framerate dependent.

tobie avatar Nov 14 '14 13:11 tobie

I don't think frequency: 60 is quite the same thing [...] since animation frames often vary away from 60 Hz and so you will quickly get out of sync.

I think you meant frequency: 16 (ms) here.

But yes, I agree they are not the same thing in general. The risk here is that we will actually have stale sensor data that is between 0 to 16 milliseconds old by the time it is rendered to the screen in an animation frame loop. For Device Orientation data that is the difference between a nausea-inducing latency between screen rendering and the real world and a less-sickening experience :D

Thus, we should figure out a way to sync hardware sensor polling with the animation frame interval and always try to deliver the freshest sensor data for the next animation frame loop.

We discussed this in a bit in https://github.com/w3c/sensors/issues/6 and further feedback on how we can do this, possibly just using ms intervals that were discussed in that thread would be good.

richtr avatar Nov 17 '14 15:11 richtr

I don't think frequency: 60 is quite the same thing [...] since animation frames often vary away from 60 Hz and so you will quickly get out of sync.

I think you meant frequency: 16 (ms) here.

Thanks for catching this. I'm an idiot. Fixing issue #6 conversation now, where I continuously referred to ms when I wanted to say Hz. Sorry. :-/

tobie avatar Nov 17 '14 17:11 tobie

Frequency is measured in Hz, not milliseconds. Period is measured in milliseconds.

domenic avatar Nov 17 '14 17:11 domenic

@domenic yeah, sorry, I always meant Hertz. No idea why I typed ms all day throwing confusion all over the place.

tobie avatar Nov 17 '14 17:11 tobie

@domenic thanks for providing this distinction.

rwaldron avatar Nov 17 '14 20:11 rwaldron

I was going off what was written in the respective repo issues (which was ms). Thank you for the clarification @domenic.

richtr avatar Nov 18 '14 10:11 richtr

Enabling developers to tie the frequency of sensor updates to animation framerate is a desirable feature. Further research is needed to see whether or not that is implementable.

Actions:

  • research whether sensor update frequency can be tied to animation framerate.
  • design the API so that developers can indicate the sensors update frequency must be framerate dependent.

tobie avatar May 10 '15 09:05 tobie

The WebVR spec attempts to solve the issue with:

getState() Return a VRPositionState dictionary containing the state of this position sensor state for the current frame (if within a requestAnimationFrame context) or for the previous frame. This state may be predicted based on the implementation’s frame scheduling.

The VRPositionState will contain the position, orientation, and velocity and acceleration of each of these properties. Use hasPosition and hasOrientation to check if the associated members are valid; If these are false, those members MUST be null.

anssiko avatar Jun 11 '15 12:06 anssiko

ACTION: @mfoltzgoogle will follow up with Blink devs about the feasibility of tying sensor reads to animation frames.

markafoltz avatar Oct 27 '15 08:10 markafoltz

Looking at the underlying APIs on iOS and Android, I don't see how that could be possible, unfortunately.

tobie avatar Feb 04 '16 11:02 tobie