網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
將名為imu_20220923的rosbag類(lèi)型數(shù)據(jù)包中imu話(huà)題的數(shù)據(jù)使用命令
rostopic echo -b imu_20220923.bag /imu > imu_angle.txt
轉(zhuǎn)成名為imu_angle.txt的txt文件,結(jié)果如下:
現(xiàn)在想要單獨(dú)將其中的x,y,時(shí)間戳信息提取出來(lái)做成excel表格,使用代碼
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
import os
import shutil
import xlwt
row=0
######################字符串分割為字符函數(shù)#############################
def split_str(s):
return [ch for ch in s]
#################################
root = '/home/jyy/下載/python腳本/'
file_path = os.path.join(root, 'imu_angle.txt')
temp_x = []
temp_y = []
temp_sec = []
temp_nsec = []
if os.path.isfile(file_path):
with open(file_path,'r') as f:
for line in f.readlines(): # 讀取每行數(shù)據(jù)
data = line.split('/t/n') # 按空格劃分每行數(shù)據(jù)
#print("line=",line) # split_str
# print("data=",data) # split_str
#print("line.split[0]= ",line.split(':')[0])
#print("line.split[1]= ",line.split(':')[1]
######################進(jìn)行數(shù)據(jù)分類(lèi)和提取#########
# 按 ':' 劃分每行數(shù)據(jù),結(jié)果保存在字符串?dāng)?shù)組中,每行劃分為包含倆個(gè)元素的字符串?dāng)?shù)組,
#數(shù)組的第一個(gè)元素是數(shù)據(jù)標(biāo)識(shí),用來(lái)判斷,第二個(gè)元素就是對(duì)應(yīng)的數(shù)據(jù)。
#使用數(shù)組的第一個(gè)元素(數(shù)據(jù)標(biāo)識(shí))判斷分類(lèi)
if( line.split(':')[0] ==' secs'): #!!!!注意標(biāo)識(shí)符前面的空格也要加上!!!!
print("split_line.x=",line.split(':')[1])
temp_sec.append((line.split(':')[1])) #將數(shù)組的第二個(gè)元素保存到臨時(shí)列表中
if( line.split(':')[0] ==' nsecs'): # secs# nsecs# y
print("split_line.x=",line.split(':')[1])
temp_nsec.append((line.split(':')[1])) #添加到臨時(shí)列表中
if( line.split(':')[0] ==' x'): #!!!!注意標(biāo)識(shí)符前面的空格也要加上!!!!
print("split_line.x=",line.split(':')[1])
temp_x.append((line.split(':')[1])) #添加到臨時(shí)列表中
if( line.split(':')[0] ==' y'): # secs# nsecs# y
print("split_line.x=",line.split(':')[1])
temp_y.append((line.split(':')[1])) #添加到臨時(shí)列表中
######################分類(lèi)好的數(shù)據(jù)保存在一個(gè)單獨(dú)的txt文件中#########
fh1 = open('sec.txt', 'w')
fh2 = open('nsec.txt', 'w')
fh3= open('only_x.txt', 'w')
fh4 = open('only_y.txt', 'w')
for data1 in temp_sec: #時(shí)間戳的秒數(shù)據(jù)保存在一個(gè)單獨(dú)的txt文件中
fh1.write(data1)
print("fh1.write.temp_sec=",data1)
fh1.close()
for data2 in temp_nsec: #時(shí)間戳的納秒數(shù)據(jù)保存在一個(gè)單獨(dú)的txt文件中
fh2.write(data2)
print("fh2.write.temp_nsec=",data2)
fh2.close()
for data3 in temp_x: #imu的x保存在一個(gè)單獨(dú)的txt文件中
fh3.write(data3)
print("fh3.write.temp_x=",data3)
fh3.close()
for data4 in temp_y: #imu的y保存在一個(gè)單獨(dú)的txt文件中
fh4.write(data4)
print("fh4.write.temp_y=",data4)
fh4.close()
執(zhí)行代碼生成4getxt文件
其中nsec.txt中提取到的數(shù)據(jù)結(jié)果如下:
然后在windows中使用excel整合到一個(gè)表格就行。
原文鏈接:https://blog.csdn.net/weixin_50508111/article/details/127028916
相關(guān)推薦
- 2022-10-25 docker 啟用時(shí)報(bào)錯(cuò)System.InvalidOperationException: Fail
- 2022-10-23 Redis?如何清空所有數(shù)據(jù)_Redis
- 2022-07-19 詳解c語(yǔ)言中的動(dòng)態(tài)內(nèi)存分配問(wèn)題
- 2022-09-09 使用PyTorch實(shí)現(xiàn)隨機(jī)搜索策略_python
- 2022-12-27 查看Python安裝路徑幾種方法小結(jié)_python
- 2022-06-10 Docker部署springboot項(xiàng)目到騰訊云的實(shí)現(xiàn)步驟_docker
- 2021-09-09 Linux下NTP服務(wù)器配置詳細(xì)過(guò)程_Linux
- 2022-06-29 超級(jí)詳細(xì)的nginx負(fù)載均衡配置_nginx
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支