@@ -63,11 +63,13 @@ def __init__(self):
6363 # self.heading_sub = self.create_subscription(
6464
6565 self .pub = self .create_publisher (
66- Quaternion ,
67- '/imu/quaternion ' ,
66+ Imu ,
67+ '/imu/data ' ,
6868 50
6969 )
7070
71+ self .last_raw_imu = None
72+
7173 def imu_callback (self , msg ):
7274 """
7375 Gryo Model:
@@ -137,6 +139,8 @@ def imu_callback(self, msg):
137139
138140 """
139141
142+ self .last_raw_imu = msg
143+
140144 # --- Compute dt ---
141145 if self .last_time is None :
142146 self .last_time = msg .header .stamp
@@ -188,12 +192,35 @@ def imu_callback(self, msg):
188192 self .q = self .q / np .linalg .norm (self .q ) # Normalize
189193 # Non-unit quaternions lead to errors
190194 # --- Publish quaternion ---
191- quat_msg = Quaternion ()
192- quat_msg .w = self .q [0 ]
193- quat_msg .x = self .q [1 ]
194- quat_msg .y = self .q [2 ]
195- quat_msg .z = self .q [3 ]
196- self .pub .publish (quat_msg )
195+ imu_msg = Imu ()
196+
197+ # Header
198+ imu_msg .header .stamp = msg .header .stamp
199+ imu_msg .header .frame_id = msg .header .frame_id # imu_link
200+
201+ # Orientation from Mahony
202+ imu_msg .orientation .w = self .q [0 ]
203+ imu_msg .orientation .x = self .q [1 ]
204+ imu_msg .orientation .y = self .q [2 ]
205+ imu_msg .orientation .z = self .q [3 ]
206+
207+ # Orientation covariance (tunable)
208+ imu_msg .orientation_covariance = [
209+ 0.02 , 0.0 , 0.0 ,
210+ 0.0 , 0.02 , 0.0 ,
211+ 0.0 , 0.0 , 0.05
212+ ]
213+
214+ # Pass through gyro
215+ imu_msg .angular_velocity = msg .angular_velocity
216+ imu_msg .angular_velocity_covariance = msg .angular_velocity_covariance
217+
218+ # Pass through accel
219+ imu_msg .linear_acceleration = msg .linear_acceleration
220+ imu_msg .linear_acceleration_covariance = msg .linear_acceleration_covariance
221+
222+ self .pub .publish (imu_msg )
223+
197224
198225
199226def main (args = None ):
0 commit comments