網站首頁 編程語言 正文
將名為imu_20220923的rosbag類型數據包中imu話題的數據使用命令
rostopic echo -b imu_20220923.bag /imu > imu_angle.txt
轉成名為imu_angle.txt的txt文件,結果如下:
現在想要單獨將其中的x,y,時間戳信息提取出來做成excel表格,使用代碼
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
import os
import shutil
import xlwt
row=0
######################字符串分割為字符函數#############################
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(): # 讀取每行數據
data = line.split('/t/n') # 按空格劃分每行數據
#print("line=",line) # split_str
# print("data=",data) # split_str
#print("line.split[0]= ",line.split(':')[0])
#print("line.split[1]= ",line.split(':')[1]
######################進行數據分類和提取#########
# 按 ':' 劃分每行數據,結果保存在字符串數組中,每行劃分為包含倆個元素的字符串數組,
#數組的第一個元素是數據標識,用來判斷,第二個元素就是對應的數據。
#使用數組的第一個元素(數據標識)判斷分類
if( line.split(':')[0] ==' secs'): #?。。。∽⒁鈽俗R符前面的空格也要加上?。。?!
print("split_line.x=",line.split(':')[1])
temp_sec.append((line.split(':')[1])) #將數組的第二個元素保存到臨時列表中
if( line.split(':')[0] ==' nsecs'): # secs# nsecs# y
print("split_line.x=",line.split(':')[1])
temp_nsec.append((line.split(':')[1])) #添加到臨時列表中
if( line.split(':')[0] ==' x'): #?。。?!注意標識符前面的空格也要加上?。。?!
print("split_line.x=",line.split(':')[1])
temp_x.append((line.split(':')[1])) #添加到臨時列表中
if( line.split(':')[0] ==' y'): # secs# nsecs# y
print("split_line.x=",line.split(':')[1])
temp_y.append((line.split(':')[1])) #添加到臨時列表中
######################分類好的數據保存在一個單獨的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: #時間戳的秒數據保存在一個單獨的txt文件中
fh1.write(data1)
print("fh1.write.temp_sec=",data1)
fh1.close()
for data2 in temp_nsec: #時間戳的納秒數據保存在一個單獨的txt文件中
fh2.write(data2)
print("fh2.write.temp_nsec=",data2)
fh2.close()
for data3 in temp_x: #imu的x保存在一個單獨的txt文件中
fh3.write(data3)
print("fh3.write.temp_x=",data3)
fh3.close()
for data4 in temp_y: #imu的y保存在一個單獨的txt文件中
fh4.write(data4)
print("fh4.write.temp_y=",data4)
fh4.close()
執行代碼生成4getxt文件
其中nsec.txt中提取到的數據結果如下:
然后在windows中使用excel整合到一個表格就行。
原文鏈接:https://blog.csdn.net/weixin_50508111/article/details/127028916
相關推薦
- 2022-03-31 nginx平滑重啟和平滑升級的圖文教程_nginx
- 2022-10-06 C語言實現短字符串壓縮的三種方法詳解_C 語言
- 2022-08-28 Redis唯一ID生成器的實現_Redis
- 2022-12-08 C/C++高精度運算(大整數運算)詳細講解_C 語言
- 2022-04-22 Number精度超了如何解決
- 2022-03-16 Android線程池源碼閱讀記錄介紹_Android
- 2022-06-21 C#連接數據庫的幾種方法_C#教程
- 2022-05-17 Spring boot 集成Redis客戶端Lettuce,導致服務線程數不斷增加
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支