Skip to content

Commit 32059a4

Browse files
committed
added reverse accelerations to the IMU publisher
1 parent 3c8bb56 commit 32059a4

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

Runtime/Scripts/ROS/Unity/Publishers/ZOROSIMUPublisher.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ public CoordinateSystemEnum CoordinateSystem {
4949
set { _coordinateSystem = value; }
5050
}
5151

52+
public bool _reverseLinearAccelerations = false;
53+
54+
/// <summary>
55+
/// Flips gravity vector.
56+
/// Why would you: the accelerometer is an intertial sensor and it measures inertial force.
57+
/// The accelerometer doesn’t measure G-force, but rather the force that resists to G.
58+
/// The resisting force aims up to the ceiling.
59+
/// </summary>
60+
/// <value></value>
61+
public bool ReverseLinearAccelerations {
62+
get { return _reverseLinearAccelerations; }
63+
set { _reverseLinearAccelerations = value; }
64+
}
65+
66+
5267

5368
private ZOROSTransformPublisher _transformPublisher = null;
5469
public ZOROSTransformPublisher TransformPublisher {
@@ -102,6 +117,12 @@ private Task OnPublishImuDelegate(ZOIMU lidar, string name, Vector3 linearAccel,
102117
_imuMessage.header.Update();
103118
_imuMessage.header.frame_id = TransformPublisher.ChildFrameID;
104119

120+
121+
if (ReverseLinearAccelerations == true) {
122+
linearAccel = linearAccel * -1;
123+
}
124+
125+
105126
if (_coordinateSystem == CoordinateSystemEnum.ROS_RightHanded_XForward_YLeft_ZUp) {
106127
_imuMessage.linear_acceleration.UnityVector3 = linearAccel;
107128
_imuMessage.angular_velocity.UnityVector3 = angularVelocity;
@@ -133,7 +154,7 @@ private Task OnPublishImuDelegate(ZOIMU lidar, string name, Vector3 linearAccel,
133154
_imuMessage.linear_acceleration.z = linearAccel.z;
134155

135156
_imuMessage.angular_velocity.x = angularVelocity.x;
136-
_imuMessage.angular_velocity.y = -angularVelocity.y;
157+
_imuMessage.angular_velocity.y = angularVelocity.y;
137158
_imuMessage.angular_velocity.z = angularVelocity.z;
138159

139160
} else if (CoordinateSystem == CoordinateSystemEnum.Unity_LeftHanded_XRight_YUp_ZForward) {
@@ -153,6 +174,8 @@ private Task OnPublishImuDelegate(ZOIMU lidar, string name, Vector3 linearAccel,
153174
}
154175

155176

177+
178+
156179
ROSBridgeConnection.Publish(_imuMessage, ROSTopic, Name);
157180

158181
return Task.CompletedTask;

Runtime/Scripts/Sensors/IMU/ZOIMU.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@ namespace ZO.Sensors {
1515
[RequireComponent(typeof(Rigidbody))]
1616
public class ZOIMU : ZOGameObjectBase, ZOSerializationInterface {
1717

18-
[Header("IMU Parameters")]
19-
public bool _flipAccelerations = false;
20-
21-
/// <summary>
22-
/// Flips gravity vector.
23-
/// Why would you: the accelerometer is an intertial sensor and it measures inertial force.
24-
/// The accelerometer doesn’t measure G-force, but rather the force that resists to G.
25-
/// The resisting force aims up to the ceiling.
26-
/// </summary>
27-
/// <value></value>
28-
public bool FlipAccellerations {
29-
get {return _flipAccelerations;}
30-
set {_flipAccelerations = value;}
31-
}
3218

3319

3420
[Header("Noise Models")]
@@ -115,12 +101,6 @@ protected override async void ZOFixedUpdate() {
115101
_acceleration = (velocity - _lastVelocity) / Time.fixedDeltaTime;
116102
_lastVelocity = velocity;
117103

118-
// apply gravity
119-
if (FlipAccellerations == true) {
120-
_acceleration += transform.InverseTransformDirection(UnityEngine.Physics.gravity * -1);
121-
} else {
122-
123-
}
124104

125105
// calculate gravity
126106
_acceleration += transform.InverseTransformDirection(UnityEngine.Physics.gravity);
@@ -136,10 +116,6 @@ protected override async void ZOFixedUpdate() {
136116
Vector3 publishedAngularVelocity = _angularVelocity;
137117
Quaternion publishedOrientation = transform.rotation;
138118

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

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

0 commit comments

Comments
 (0)