Skip to content

Commit 2db0947

Browse files
committed
IMU flip accelerations flag
1 parent 8aedabc commit 2db0947

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Runtime/Scripts/Sensors/IMU/ZOIMU.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ namespace ZO.Sensors {
1616
public class ZOIMU : ZOGameObjectBase, ZOSerializationInterface {
1717

1818
[Header("IMU Parameters")]
19-
public bool _flipGravity = false;
19+
public bool _flipAccelerations = false;
2020

2121
/// <summary>
22-
/// Flips gravity vectory.
22+
/// Flips gravity vector.
2323
/// Why would you: the accelerometer is an intertial sensor and it measures inertial force.
2424
/// The accelerometer doesn’t measure G-force, but rather the force that resists to G.
2525
/// The resisting force aims up to the ceiling.
2626
/// </summary>
2727
/// <value></value>
28-
public bool FlipGravity {
29-
get {return _flipGravity;}
30-
set {_flipGravity = value;}
28+
public bool FlipAccellerations {
29+
get {return _flipAccelerations;}
30+
set {_flipAccelerations = value;}
3131
}
3232

3333

@@ -116,12 +116,14 @@ protected override async void ZOFixedUpdate() {
116116
_lastVelocity = velocity;
117117

118118
// apply gravity
119-
if (FlipGravity == true) {
119+
if (FlipAccellerations == true) {
120120
_acceleration += transform.InverseTransformDirection(UnityEngine.Physics.gravity * -1);
121121
} else {
122-
_acceleration += transform.InverseTransformDirection(UnityEngine.Physics.gravity);
122+
123123
}
124-
124+
125+
// calculate gravity
126+
_acceleration += transform.InverseTransformDirection(UnityEngine.Physics.gravity);
125127
_acceleration = _linearNoise.Apply(_acceleration);
126128
_acceleration = ZO.Math.ZOMathUtil.lowPassFilter(_acceleration, prevAcceleration, _preFilterAccelerationAlpha);
127129

@@ -134,6 +136,10 @@ protected override async void ZOFixedUpdate() {
134136
Vector3 publishedAngularVelocity = _angularVelocity;
135137
Quaternion publishedOrientation = transform.rotation;
136138

139+
if (FlipAccellerations == true) {
140+
publishedAcceleration = publishedAcceleration * -1;
141+
}
142+
137143

138144
if (OnPublishDelegate != null) {
139145
await OnPublishDelegate(this, Name, publishedAcceleration, publishedAngularVelocity, publishedOrientation);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.fsstudio.zerosim",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"displayName": "ZeroSim",
55
"description": "ZeroSim ROS robotic simulator in Unity.",
66
"unity": "2020.1",

0 commit comments

Comments
 (0)