-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtime_synchro.py
39 lines (34 loc) · 1.41 KB
/
time_synchro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import message_filters
import rospy
from message_filters import TimeSynchronizer, Subscriber
from sensor_msgs.msg import Imu
from sensor_msgs.msg import NavSatFix
from novatel_msgs.msg import INSPVAX
# python file solves the timesynchronization problem in Hongkong dataset
imu_sync = rospy.Publisher("/imu/data/sync",Imu,queue_size=10)
def imu_callback(data):
""" Function receives unsynchronized imudata and publishes the imu data synchronized to gps data
Args:
data : imu data from topic in "Sensor_msgs/Imu" messaage type
"""
time = data.header.stamp.secs-2
imu_data = Imu()
imu_data.header.stamp.secs = time
imu_data.header.stamp.nsecs = data.header.stamp.nsecs
imu_data.header.seq = data.header.seq
imu_data.header.frame_id = data.header.frame_id
imu_data.orientation = data.orientation
imu_data.orientation_covariance = data.orientation_covariance
imu_data.angular_velocity = data.angular_velocity
imu_data.angular_velocity_covariance = data.angular_velocity_covariance
imu_data.linear_acceleration = data.linear_acceleration
imu_data.linear_acceleration_covariance = data.linear_acceleration_covariance
imu_sync.publish(imu_data)
def listener():
""" Function runs the ROS init node
"""
rospy.init_node("synchro")
rospy.Subscriber("/imu/data",Imu,imu_callback)
# rospy.Subscriber("novatel_data/inspvax",INSPVAX,nov)
rospy.spin()
listener()