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 most recently became current.
Declaration
public static BiasCorrectedGyroscope current { get; }
Property Value
| Type | Description |
|---|---|
| BiasCorrectedGyroscope |
Remarks
The value is null when the platform has no bias-corrected gyroscope.
When a bias-corrected gyroscope is added, it becomes current only if no other bias-corrected gyroscope is current, because its controls are noisy.
When the current bias-corrected gyroscope is removed, the remaining bias-corrected gyroscope that was updated last becomes current.
For more information about when a device becomes current, refer to MakeCurrent().
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()
Makes this device the current device of its type.
Declaration
public override void MakeCurrent()
Overrides
Remarks
Many types of devices have .current getters that return the current device of that type
(for example, current). The current device of a type is the device of that
type that most recently became current. For a built-in sensor, the type is the class that derives directly
from Sensor. For example, an Android gyroscope becomes current.
The Input System calls this method in the following cases:
- When a device is added. If all the device's controls are noisy, the device becomes current only if no other device of its type is current. For example, a second gyroscope doesn't replace the first one as current, because all of a gyroscope sensor's controls are noisy.
- When input changes a control that isn't noisy. Input on noisy controls doesn't call this method.
- When a device's usage changes, with the same rule as when the device is added.
- When a layout change recreates a device. The new device is current if the old one was.
- When a device is removed. The remaining device of its type that was updated last becomes current.
If no device of that type is left,
.currentisnull. If you remove a sensor that isn't current,.currentstays the same.
A device with noisy controls (noisy) can receive events that carry no user interaction. For example, the PlayStation®4 (PS4) gamepad has a gyro and keeps sending events when nobody uses it. Without the rule for noisy controls, the PS4 gamepad would make itself current while the user plays with another gamepad.
When you call this method yourself, the device becomes current even if its controls are noisy.
If you override this method, call base.MakeCurrent(). Otherwise, the built-in .current
getters don't return the device, and the rules above don't apply to it.
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;
}
}