Class BiasCorrectedGyroscope
Input device that reports angular velocity with the sensor bias removed.
Inherited Members
Namespace: UnityEngine.InputSystem
Assembly: Unity.InputSystem.dll
Syntax
public class BiasCorrectedGyroscope : Sensor
Remarks
Like Gyroscope, this device measures the angular velocity of a device in radians per second. Unlike Gyroscope, the platform removes the sensor's bias before it reports the value, so a device held still reads approximately zero on all three axes. Integrating the value over time therefore drifts far less, because bias is the dominant source of that drift. It doesn't remove drift altogether: noise and any residual calibration error still accumulate. For the difference between the two, refer to Gyroscope bias and drift.
What Gyroscope reports depends on the platform: on some platforms it already has the bias removed, and on others it's the uncorrected sensor value. That behavior stays the same for compatibility, so use this device when you need the correction to be guaranteed rather than incidental.
A platform that can't supply a bias-corrected value doesn't add this device at all, so check that the device exists before you use it.
On platforms where the correction comes from a fused sensor pipeline, enabling this device also starts that pipeline, which uses more power than the uncorrected sensor alone.
Examples
class MyBehavior : MonoBehaviour
{
protected void OnEnable()
{
// All sensors start out disabled so they have to manually be enabled first.
if (BiasCorrectedGyroscope.current != null)
InputSystem.EnableDevice(BiasCorrectedGyroscope.current);
}
protected void OnDisable()
{
if (BiasCorrectedGyroscope.current != null)
InputSystem.DisableDevice(BiasCorrectedGyroscope.current);
}
protected void Update()
{
if (BiasCorrectedGyroscope.current == null)
return;
var angularVelocity = BiasCorrectedGyroscope.current.angularVelocity.ReadValue();
//...
}
}
Properties
angularVelocity
Angular velocity of the device in radians per second, with the sensor bias removed.
Declaration
public Vector3Control angularVelocity { get; protected set; }
Property Value
| Type | Description |
|---|---|
| Vector3Control |
Remarks
The axes are fixed to the device in a right-handed frame: X points right, Y points up, and Z points out of the screen. Positive rotation follows the right-hand rule, so a rotation is positive when it appears counter-clockwise to an observer looking at the device from the positive end of an axis.
This is the platform's own frame rather than Unity's left-handed convention, so account for the difference when you apply the value to a Transform.
The axes don't change with device orientation. When compensateForScreenOrientation is enabled, the value is rotated to match the current screen orientation.
See Also
current
The bias-corrected gyroscope that was last added or had activity last.
Declaration
public static BiasCorrectedGyroscope current { get; }
Property Value
| Type | Description |
|---|---|
| BiasCorrectedGyroscope |
Remarks
The value is null when the platform has no bias-corrected gyroscope.
See Also
Methods
FinishSetup()
Perform final initialization tasks after the control hierarchy has been put into place.
Declaration
protected override void FinishSetup()
Overrides
Remarks
This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.
Examples
public class MyDevice : InputDevice
{
public ButtonControl button { get; private set; }
public AxisControl axis { get; private set; }
protected override void OnFinishSetup()
{
// Cache controls in getters.
button = GetChildControl("button");
axis = GetChildControl("axis");
}
}
See Also
MakeCurrent()
Make this the current device of its type.
Declaration
public override void MakeCurrent()
Overrides
Remarks
This method is called automatically by the input system when a device is
added or when input is received on it. Many types of devices have .current
getters that allow querying the last used device of a specific type directly (for
example, see current).
There is one special case, however, related to noise. A device that has noisy controls
(i.e. controls for which noisy is true) may receive input events
that contain no meaningful user interaction but are simply just noise from the device. A
good example of this is the PS4 gamepad which has a built-in gyro and may thus constantly
feed events into the input system even if not being actually in use. If, for example, an
Xbox gamepad and PS4 gamepad are both connected to a PC and the user is playing with the
Xbox gamepad, the PS4 gamepad would still constantly make itself current
by simply flooding the system with events. Hence why by default, noise on .current getters
will be filtered out and a device will only see MakeCurrent getting called if their input
was detected on non-noisy controls.
See Also
OnRemoved()
Called by the system when the device is removed from devices.
Declaration
protected override void OnRemoved()
Overrides
Remarks
Examples
using UnityEngine.InputSystem;
public class MyDevice : InputDevice
{
public static MyDevice current { get; private set; }
protected override void OnRemoved()
{
// use this context to unassign the current device for instance
base.OnRemoved();
if (current == this)
current = null;
}
}