当前位置:网站首页>Experiment notes - Convert Carmen (.Log.Clf) file to rosbag
Experiment notes - Convert Carmen (.Log.Clf) file to rosbag
2022-06-27 10:20:00 【gwpscut】
The direct source code is as follows , For more information, please refer to the blog :
Study notes —— Generation of data set _gwpscut The blog of -CSDN Blog
#!/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 This is the original laser data marked in the original file , Generally, there is no need to change
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' # This is the laser coordinate system id, Change... As needed , stay ROS When reading data in, you will use , Generally, there is no need to change .
t = rospy.Time(float(tokens[(num_scans + 8)])) # Acquisition time
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) # This is the topic of laser data release , Change according to the specific topic subscribed by the node program .
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': # Mark odometer data
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)边栏推荐
- leetcode待做题目
- 使用Karmada实现Helm应用的跨集群部署【云原生开源】
- 你睡觉时大脑真在自动学习!首个人体实验证据来了:加速1-4倍重放,深度睡眠阶段效果最好...
- 有关WIN10的内存压缩
- leetcode:968. 监控二叉树【树状dp,维护每个节点子树的三个状态,非常难想权当学习,类比打家劫舍3】
- 10 常见网站安全攻击手段及防御方法
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- torch.utils.data.RandomSampler和torch.utils.data.SequentialSampler的区别
- torchvision.models._utils.IntermediateLayerGetter使用教程
- Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
猜你喜欢

通俗易懂理解朴素贝叶斯分类的拉普拉斯平滑

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!

前馈-反馈控制系统设计(过程控制课程设计matlab/simulink)

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

Product strength benchmarking seal /model 3, with 179800 pre-sales of Chang'an dark blue sl03

通俗易懂理解樸素貝葉斯分類的拉普拉斯平滑

C# Any()和AII()方法

以后发现漏洞,禁止告诉中国!

感应电机直接转矩控制系统的设计与仿真(运动控制matlab/simulink)

In the three-tier architecture, at which layer is the database design implemented, not at the data storage layer?
随机推荐
邮件系统(基于SMTP协议和POP3协议-C语言实现)
Exception in Chinese character fuzzy query of MySQL database
The R language uses the preprocess function of the caret package for data preprocessing: Center all data columns (subtract the average value from each data column), and set the method parameter to cen
Memory compression for win10
【OpenCV 例程200篇】212. 绘制倾斜的矩形
测试同学怎么参与codereview
细说物体检测中的Anchors
用户认证技术
Reorganize common shell scripts for operation and maintenance frontline work
【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)
CPU设计(单周期和流水线)
运维一线工作常用shell脚本再整理
audiotrack与audioflinger
Dimitt's law
JS client storage
通俗易懂理解朴素贝叶斯分类的拉普拉斯平滑
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
[registration] infrastructure design: from architecture hot issues to industry changes | tf63
10 常见网站安全攻击手段及防御方法
C any() and aii() methods