由于项目需要,跟C老师学了下如何把rosbag里的gps信号转化成轨迹
一、录制数据
通过ros录制SLAM数据,可以参考我如下的文章
ros上使用usb摄像头和激光雷达录制rosbag,并在rviz上播放https://blog.csdn.net/weixin_43046168/article/details/151261488?spm=1001.2014.3001.5501不过需要修改下录制的话题名,需要加上imu和gps的数据/imu/data是imu数据的话题,/fix是GPS数据的话题
rosbag record /velodyne_points /imu/data /fix二、从bag中导出数据
将bag中的/fix数据导出为csv文件
rostopic echo -b your.bag -p /fix > fix.csv通过py脚本,将csv转化为TUM格式
import os import rosbag import utm bag_path = os.path.expanduser("~/bags/zk/zk_260426_1.bag") topic_name = "/fix" out_file = "gps_all.tum" coords = [] with rosbag.Bag(bag_path, 'r') as bag: for topic, msg, t in bag.read_messages(topics=[topic_name]): if msg.status.status < 0: continue lat = msg.latitude lon = msg.longitude alt = msg.altitude ts = msg.header.stamp.to_sec() x, y, zone_number, zone_letter = utm.from_latlon(lat, lon) coords.append((ts, x, y, alt)) if not coords: raise RuntimeError("No GPS data found!") x0, y0, z0 = coords[0][1], coords[0][2], coords[0][3] with open(out_file, "w") as f: for ts, x, y, z in coords: tx = x - x0 ty = y - y0 tz = z - z0 f.write(f"{ts:.6f} {tx:.6f} {ty:.6f} {tz:.6f} 0 0 0 1\n") print(f"saved to {out_file}")得到gps_all.tum
三、通过evo工具生成轨迹
evo_traj tum gps_all.tum -p --plot_mode xy如果想保存图,可以使用
evo_traj tum gps_all.tum -p --plot_mode xy --save_plot gps_all_xy.pdf最后即可得到gps生成的轨迹图