Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imu calc #56

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Assets/UnitySensors/Runtime/Scripts/Sensors/IMU/IMUSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ public class IMUSensor : Sensor
public Vector3 angularVelocity { get => _angularVelocity; }

public Vector3 localVelocity { get => _transform.InverseTransformDirection(_velocity); }
public Vector3 localAcceleration { get => _transform.InverseTransformDirection(_acceleration); }
public Vector3 localAcceleration { get => _transform.InverseTransformDirection(_acceleration.normalized) * _acceleration.magnitude; }

private float _dt { get => base._frequency_inv; }

private Vector3 _gravity;
private float _gravityMagnitude;

protected override void Init()
{
_transform = this.transform;

_gravity = Physics.gravity;
_gravityMagnitude = _gravity.magnitude;
}

protected override void UpdateSensor()
Expand All @@ -46,7 +52,7 @@ protected override void UpdateSensor()

_velocity = (_position - _position_last) / _dt;
_acceleration = (_velocity - _velocity_last) / _dt;
_acceleration += _transform.InverseTransformVector(Physics.gravity);
_acceleration += _transform.InverseTransformVector(_gravity).normalized * _gravityMagnitude;

Quaternion rotation_delta = Quaternion.Inverse(_rotation_last) * _rotation;
rotation_delta.ToAngleAxis(out float angle, out Vector3 axis);
Expand Down
10 changes: 10 additions & 0 deletions Assets/UnitySensors/Samples/IMU/IMU.unity
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ PrefabInstance:
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 8550806465241961968, guid: 884f57c81164231419af9316aaca015d,
type: 3}
propertyPath: m_LocalScale.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8550806465241961968, guid: 884f57c81164231419af9316aaca015d,
type: 3}
propertyPath: m_LocalScale.z
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8550806465241961968, guid: 884f57c81164231419af9316aaca015d,
type: 3}
propertyPath: m_LocalPosition.x
Expand Down