ROS修改rosbag中话题的frame_id,以及发布坐标在Rviz中与点云融合显示
- 读取rosbag,修改话题frame_id与话题名并循环发布
import rosbag
import rospy
import numpy as np
from sensor_msgs.msg import PointCloud2
bag_file = 'cumt_1204_2022-12-04-20-01-08.bag'
bag = rosbag.Bag(bag_file, "r")
rospy.init_node('change_frameid')
rate = rospy.Rate(10)
while 1:
bag_data = bag.read_messages('/laser_cloud_surround')
for topic, msg, t in bag_data:
msg.header.frame_id = 'livox'
point_pub = rospy.Publisher('laser_surround', PointCloud2, queue_size=50)
point_pub.publish(msg)
rate.sleep()
- 读取xlsx文件中的坐标并发布
import xlrd
import rospy
from nav_msgs.msg import Path
from geometry_msgs.msg import PoseStamped, Quaternion
import tf
import math
x, y, th = 0, 0, 0
data = xlrd.open_workbook('data.xlsx')
sheet1 = data.sheets()[0]
nrows = sheet1.nrows
ncols = sheet1.ncols
def DataUpdating(path_pub, path_record):
"""
数据更新函数
"""
global x, y, th
current_time = rospy.Time.now()
br = tf.TransformBroadcaster()
br.sendTransform((0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0),
rospy.Time.now(), "livox", "odom")
pose = PoseStamped()
pose.header.stamp = current_time
pose.header.frame_id = 'livox'
pose.pose.position.x = x
pose.pose.position.y = y
pose.pose.orientation.x = 0
pose.pose.orientation.y = 0
pose.pose.orientation.z = 0
pose.pose.orientation.w = 0
path_record.header.stamp = current_time
path_record.header.frame_id = 'livox'
path_record.poses.append(pose)
if len(path_record.poses) > 200:
path_record.poses.pop(0)
path_pub.publish(pose)
def node():
"""
节点启动函数
"""
try:
rospy.init_node('PathRecord')
path_pub = rospy.Publisher('trajectory', Path, queue_size=50)
rate = rospy.Rate(10)
path_record = Path()
for i in range(1, nrows):
current_time = rospy.Time.now()
x=sheet1.cell(i,0).value
y=sheet1.cell(i,1).value
x=float(x)/1000
y=float(y)/1000
br = tf.TransformBroadcaster()
br.sendTransform((0, -1.6, 0.6), (0.001, 0.025, 0.032, 0.999),
rospy.Time.now(), "base", "livox")
br.sendTransform((x, y, 0.0), (0.0, 0.0, 0.0, 1.0),
rospy.Time.now(), "odom", "base")
pose = PoseStamped()
pose.header.stamp = current_time
pose.header.frame_id = 'base'
pose.pose.position.x = x
pose.pose.position.y = y
pose.pose.position.z = 0.0
pose.pose.orientation.x = 0
pose.pose.orientation.y = 0
pose.pose.orientation.z = 0
pose.pose.orientation.w = 1
path_record.header.stamp = current_time
path_record.header.frame_id = 'base'
path_record.poses.append(pose)
if len(path_record.poses) > 100:
path_record.poses.pop(0)
path_pub.publish(path_record)
rate.sleep()
except rospy.ROSInterruptException:
pass
if __name__ == '__main__':
node()
效果视频
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)