Re: [w3c/gamepad] GamepadHapticActuator pulse should support frequency parameter (#148)

The GamepadHapticActuator definition in the Gamepad Extensions spec is out of date and I don't think it was ever fully implemented in any browser. Firefox has IDL for it but as far as I can tell none of the platform backends ever create any actuators.

Chromium implements the haptics API described in the [pull request here](https://github.com/w3c/gamepad/pull/68). It's designed for DualShock-style haptics as opposed to the pulse effect in the original GamepadHapticActuator spec. DualShock controllers have two eccentric rotating mass (ERM) actuators with differing masses that can be run at different speeds to create rumble effects. The haptics element responsible for vibrating the whole controller is exposed as `Gamepad.vibrationActuator`. Example usage:

    let gamepads = navigator.hid.getGamepads();
    if (gamepads[0] && gamepads[0].vibrationActuator) {
      gamepads[0].vibrationActuator.playEffect(
          'dual-rumble',  // Effect type
          {duration:1000,  // Vibration duration, in milliseconds
           startDelay:0,  // Delay before starting the effect, in milliseconds
           strongMagnitude:0.5,  // Vibration intensity of the "strong" (low frequency) rumble motor
           weakMagnitude:1.0});  // Vibration intensity of the "weak" (high frequency) rumble motor
    }

Currently the spec only defines one type of effect. I think the best user experience occurs when applications can use a single effect type and browsers do their best to support that effect type across all gamepads, even if the gamepad does not have the correct hardware to support that type of effect. For instance, Chrome supports sending `dual-rumble` effects to a Switch Joy-Con even though the Joy-Con has a linear resonant actuator (LRA) instead of the dual-ERM configuration. This approach might also be appropriate for Oculus VR controllers.

To allow apps to specify a frequency for the effect, we can define new effect types that are better suited for the vibration actuators found in VR controllers. In the Oculus SDK documentation there are two haptics interfaces: OVRInput Haptics which takes `(frequency, amplitude, controllerMask)` parameters and OVRHaptics which is deprecated. To support the OVRInput Haptics interface perhaps we can add something like:

    actuator.playEffect(
        'frequency-pulse',  // Play a pulse effect at a specific frequency
        {duration:1000,  // Vibration duration, in milliseconds
         startDelay:0,  // Delay before starting the effect, in milliseconds
         frequency:60,  // Vibration frequency, in Hz
         magnitude:1.0});  // Vibration intensity (0 = no vibration, 1 = max vibration)

`Gamepad.vibrationActuator` is intended for effects that vibrate the whole controller, but VR controllers typically have one device per hand, each with its own vibration actuator. I think the best approach here is to expose separate GamepadHapticActuator objects to represent the actuators in the left- and right-hand controllers:

    gamepad.leftVibrationActuator.playEffect('frequency-pulse', /*params*/);  // Play effect on left-hand actuator
    gamepad.rightVibrationActuator.playEffect('frequency-pulse', /*params*/);  // Play effect on right-hand actuator
    gamepad.vibrationActuator.playEffect('frequency-pulse', /*params*/);  // Play effect on both hands

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/gamepad/issues/148#issuecomment-814500019

Received on Tuesday, 6 April 2021 23:36:44 UTC