当前位置:网站首页>实验笔记之——CARMEN (.log .clf)文件转换为rosbag
实验笔记之——CARMEN (.log .clf)文件转换为rosbag
2022-06-27 10:07:00 【gwpscut】
直接给出源代码如下,更多介绍可以参考博文:
学习笔记之——数据集的生成_gwpscut的博客-CSDN博客
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import rospy
import rosbag
from sensor_msgs.msg import LaserScan
from nav_msgs.msg import Odometry
from math import pi
from tf2_msgs.msg import TFMessage
from geometry_msgs.msg import TransformStamped
import tf
def make_tf_msg(x, y, z,theta, t,parentid,childid):
trans = TransformStamped()
trans.header.stamp = t
trans.header.frame_id = parentid
trans.child_frame_id = childid
trans.transform.translation.x = x
trans.transform.translation.y = y
trans.transform.translation.z = z
q = tf.transformations.quaternion_from_euler(0, 0, theta)
trans.transform.rotation.x = q[0]
trans.transform.rotation.y = q[1]
trans.transform.rotation.z = q[2]
trans.transform.rotation.w = q[3]
msg = TFMessage()
msg.transforms.append(trans)
return msg
# 0 | 1 | 2 - 1+num_readings | 2+num_readings | 3+num_readings |
# xLASER | num_readings | [range_readings] | x | y |
#-------------------------------------------------------------------------------
# 4+num_readings | 5+num_readings | 6+num_readings | 7+num_readings |
# theta | odom_x | odom_y | odom_theta |
#-------------------------------------------------------------------------------
# 8+num_readings | 9+num_readings | 10+num_readings
# ipc_timestamp | ipc_hostname |logger_timestamp
with open('mit-killian.clf') as dataset:
with rosbag.Bag('MIT.bag', 'w') as bag:
for line in dataset.readlines():
line = line.strip()
tokens = line.split(' ')
if len(tokens) <= 2:
continue
if tokens[0] == 'FLASER': #FLASER这是原始文件中原来标注激光数据的,一般不需要更改
msg = LaserScan()
num_scans = int(tokens[1])
if num_scans != 180 or len(tokens) < num_scans + 9:
rospy.logwarn("unsupported scan format")
continue
msg.header.frame_id = 'base_laser' #这是激光坐标系id,根据需要更改,在ROS中读取数据时会使用到,一般也不需要更改。
t = rospy.Time(float(tokens[(num_scans + 8)])) #获取时间
msg.header.stamp = t
msg.angle_min = -90.0 / 180.0 * pi
msg.angle_max = 90.0 / 180.0 * pi
msg.angle_increment = pi / num_scans
msg.time_increment = 0.2 / 360.0
msg.scan_time = 0.2
msg.range_min = 0.001
msg.range_max = 50.0
msg.ranges = [float(r) for r in tokens[2:(num_scans + 2)]]
bag.write('scan', msg, t) #这是激光数据发布的话题,根据节点程序订阅的具体话题更改。
tf_msg = make_tf_msg(0.1, 0, 0.2, 0, t,'base_link','base_laser')
bag.write('tf', tf_msg, t)
# odom_x, odom_y, odom_theta = [float(r) for r in tokens[(num_scans + 2):(num_scans + 5)]]
# odom_x, odom_y, odom_theta = [float(r) for r in tokens[(num_scans + 5):(num_scans + 8)]]
# msg1=Odometry()
# msg1.header.stamp=t
# msg1.header.frame_id='odom'
# msg1.child_frame_id='base_link'
# msg1.pose.pose.position.x=odom_x
# msg1.pose.pose.position.y=odom_y
# msg1.pose.pose.position.z=0
# q = tf.transformations.quaternion_from_euler(0, 0, odom_theta)
# msg1.pose.pose.orientation.x = q[0]
# msg1.pose.pose.orientation.y = q[1]
# msg1.pose.pose.orientation.z = q[2]
# msg1.pose.pose.orientation.w = q[3]
# bag.write('odom', msg1, t)
# 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
# ODOM| x | y |theta| tv| rv|accel|ipc_timestamp|ipc_hostname|logger_timestamp
elif tokens[0] == 'ODOM': #标志里程计数据
odom_x, odom_y, odom_theta = [float(t) for t in tokens[1:4]]
t = rospy.Time(float(tokens[7]))
msg=Odometry()
msg.header.stamp=t
msg.header.frame_id='odom'
msg.child_frame_id='base_link'
msg.pose.pose.position.x=odom_x
msg.pose.pose.position.y=odom_y
msg.pose.pose.position.z=0
q = tf.transformations.quaternion_from_euler(0, 0, odom_theta)
msg.pose.pose.orientation.x = q[0]
msg.pose.pose.orientation.y = q[1]
msg.pose.pose.orientation.z = q[2]
msg.pose.pose.orientation.w = q[3]
bag.write('odom', msg, t)
# tf_msg = make_tf_msg(odom_x, odom_y,0 , odom_theta, t,'odom','base_link')
# bag.write('tf', tf_msg, t)边栏推荐
- Google browser chropath plug-in
- 小白也能看懂的网络基础 03 | OSI 模型是如何工作的(经典强推)
- [200 opencv routines] 212 Draw a slanted rectangle
- leetcode待做题目
- 一次线上移动端报表网络连接失败问题定位与解决
- R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行center中心化(每个数据列减去平均值)、设置method参数为center
- R langage plotly visualisation: visualisation de plusieurs histogrammes normalisés d'ensembles de données et ajout d'une courbe de densité KDE à l'histogramme, réglage de différents histogrammes en ut
- 【面经】云泽科技
- C語言學習-Day_04
- leetcode:968. Monitor the binary tree [tree DP, maintain the three states of each node's subtree, it is very difficult to think of the right as a learning, analogous to the house raiding 3]
猜你喜欢
![[200 opencv routines] 211 Draw vertical rectangle](/img/57/5ff4ccb6f003e1ec6c49de8c8fde16.png)
[200 opencv routines] 211 Draw vertical rectangle

【HCIE-RS复习思维导图】- STP

2-4Kali下安装nessus

leetcode:522. 最长特殊序列 II【贪心 + 子序列判断】
![[200 opencv routines] 212 Draw a slanted rectangle](/img/cf/da8fff386d011c939946326c55671f.png)
[200 opencv routines] 212 Draw a slanted rectangle

QT运行显示 This application failed to start because it could not find or load the Qt platform plugin

详细记录YOLACT实例分割ncnn实现

【OpenCV 例程200篇】212. 绘制倾斜的矩形

audiotrack与audioflinger

Easy to understand Laplace smoothing of naive Bayesian classification
随机推荐
R language plot visualization: visualize the normalized histograms of multiple data sets, add density curve KDE to the histograms, set different histograms to use different bin sizes, and add edge whi
Advantages and disadvantages of distributed file storage system
Mongodb cross host database copy and common commands
unity--newtonsoft. JSON parsing
10 常见网站安全攻击手段及防御方法
更改pip镜像源
Xiaobai can also understand how the basic network 03 | OSI model works (classic push)
Oracle trigger stored procedure writes at the same time
torchvision.models._utils.IntermediateLayerGetter使用教程
lvi-sam 总结
细说物体检测中的Anchors
border影响父元素的高度-解决方案
我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
oracle触发器 存储过程同时写入
Record in detail the implementation of yolact instance segmentation ncnn
R language plot visualization: plot to visualize the two-dimensional histogram contour map, add numerical labels on the contour lines, customize the label font color, and set the mouse hover display e
6月23日《Rust唠嗑室》第三期B站视频地址
[200 opencv routines] 211 Draw vertical rectangle
C language learning day_ 06
Freemarker