Skip to content

Commit e2a689b

Browse files
committed
Collect GNSS latitude and longitude from septentrio
1 parent 073bf49 commit e2a689b

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

GEMstack/offboard/calibration/capture_ouster_oak.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ROS Headers
22
import rospy
3-
from sensor_msgs.msg import Image,PointCloud2
3+
from sensor_msgs.msg import Image,PointCloud2,NavSatFix
44
import sensor_msgs.point_cloud2 as pc2
55
import ctypes
66
import struct
@@ -12,12 +12,15 @@
1212
import os
1313
import time
1414

15+
# TODO: change these arrays to use dictionaries, format eg. {filename: data}
1516
lidar_points = []
1617
camera_images = []
1718
depth_images = []
19+
gnss_locations = []
1820
lidar_filetype = ".npz"
1921
camera_filetype = ".png"
2022
depth_filetype = ".tif"
23+
gnss_filetype = ".npy"
2124
bridge = CvBridge()
2225

2326
def lidar_callback(lidar : PointCloud2):
@@ -32,6 +35,10 @@ def depth_callback(img : Image):
3235
global depth_images
3336
depth_images.append(img)
3437

38+
def gnss_callback(sat_fix : NavSatFix):
39+
global gnss_locations
40+
gnss_locations.append(sat_fix)
41+
3542
def pc2_to_numpy(pc2_msg, want_rgb = False):
3643
gen = pc2.read_points(pc2_msg, skip_nans=True)
3744
if want_rgb:
@@ -63,8 +70,11 @@ def clear_scan():
6370
camera_images = []
6471
global depth_images
6572
depth_images = []
73+
global gnss_locations
74+
gnss_locations = []
6675

67-
def save_scan(lidar_filenames, camera_filenames, depth_filenames, index):
76+
# TODO: when data is stored in dictionaries, change to only save files which exist and change error checking
77+
def save_scan(lidar_filenames, camera_filenames, depth_filenames, gnss_filenames, index):
6878
if len(lidar_filenames) != len(lidar_points) or len(camera_filenames) != len(camera_images) or len(depth_filenames) != len(depth_images):
6979
print("Missing data, scan", index, "cannot be saved")
7080
return
@@ -91,6 +101,12 @@ def save_scan(lidar_filenames, camera_filenames, depth_filenames, index):
91101
# print("Depth pixel range",np.min(dimage),np.max(dimage))
92102
dimage = dimage.astype(np.uint16)
93103
cv2.imwrite(depth_fn,dimage)
104+
105+
for i in range(len(gnss_locations)):
106+
sat_fix = gnss_locations[i]
107+
gnss_fn = gnss_filenames + str(index) + gnss_filetype
108+
coordinates = np.array(sat_fix.latitude, sat_fix.longitude)
109+
np.save(gnss_fn, coordinates)
94110

95111
def main(folder='data',start_index=0):
96112
# Initialize node and establish subscribers
@@ -103,6 +119,7 @@ def main(folder='data',start_index=0):
103119
cam_rl_sub = rospy.Subscriber("/camera_rl/arena_camera_node/image_raw", Image, camera_callback)
104120
cam_rr_sub = rospy.Subscriber("/camera_rr/arena_camera_node/image_raw", Image, camera_callback)
105121
depth_sub = rospy.Subscriber("/oak/stereo/image_raw", Image, depth_callback)
122+
gnss_sub = rospy.Subscriber("/septentrio_gnss/navsatfix", NavSatFix, gnss_callback)
106123

107124
# Store scans
108125
index = start_index
@@ -119,7 +136,8 @@ def main(folder='data',start_index=0):
119136
os.path.join(folder, 'fl'), os.path.join(folder, 'fr'),
120137
os.path.join(folder, 'rl'), os.path.join(folder, 'rr')]
121138
depth_files = [os.path.join(folder, 'depth')]
122-
save_scan(lidar_files, camera_files, depth_files, index)
139+
gnss_files = [os.path.join(folder, 'septentrio')]
140+
save_scan(lidar_files, camera_files, depth_files, gnss_files, index)
123141
clear_scan()
124142
index += 1
125143

0 commit comments

Comments
 (0)