-
Notifications
You must be signed in to change notification settings - Fork 0
/
lidar_gen.py
51 lines (33 loc) · 1.36 KB
/
lidar_gen.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
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Python 2/3 compatibility
from __future__ import print_function
# Built-in modules
import os
import sys
import time
# External modules
import cv2
import numpy as np
# ROS modules
from std_msgs.msg import Time,String
import rospy
import tf2_ros
from cv_bridge import CvBridge, CvBridgeError
import ros_numpy
from sensor_msgs.msg import Image, CameraInfo, PointCloud2
def callback1(msg):
global lidtnew
off=float(lidt)-float(msg.data)#compute the offset between the sync event generated clock and the lidar topic header timestamp
lidtnew=float(lidt)+float(off)#add the offset to the lidar topic timestamp
def callback_fun(msg):
global lidt
lidt=str(float(msg.header.stamp.secs)+(float(msg.header.stamp.nsecs)/(10**9)))#get the lidar topic header timestamp
subnew=rospy.Subscriber('/signal',String,callback1)#get the sync event along with the timestamp from clock,passed as a String
points = ros_numpy.point_cloud2.pointcloud2_to_array(msg)
nametosave=str(lidtnew).ljust(13,'0')
np.save('./offset/imgs/'+str(nametosave),points)#save the lidar pointcloud with timestamp as the name
if __name__ == '__main__':
rospy.init_node('calibrate_camera_lidar', anonymous=True)
sub=rospy.Subscriber('/velodyne_points',PointCloud2,callback_fun)#subscribe to lidar topic
rospy.spin()