首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将IMU传感器(加速度计,陀螺仪)读数与时间戳一起导出到数据文件中。

将IMU传感器(加速度计,陀螺仪)读数与时间戳一起导出到数据文件中。
EN

Stack Overflow用户
提问于 2019-06-07 18:22:56
回答 1查看 201关注 0票数 0

我正在使用一个IMU传感器,并获取3个读数(XYZ_acceleration,XYZ_angular速度,XYZ_magnetometer),我想将它们与它们的时间戳一起导出到单个数据文件中。我成功地导出到3个单独的数据文件,没有时间戳。

代码语言:javascript
复制
from altimu10v5.lsm6ds33 import LSM6DS33
from altimu10v5.lis3mdl import LIS3MDL
from altimu10v5.lps25h import LPS25H
from time import sleep
import numpy as np
import csv
import calendar
import time

lsm6ds33 = LSM6DS33()
lsm6ds33.enable()

lis3mdl = LIS3MDL()
lis3mdl.enable()

lps25h = LPS25H
lis3mdl.enable()

ts = calendar.timegm(time.gmtime())


while True:


    accel_raw=lsm6ds33.get_accelerometer_raw()
    accel_gforce=lsm6ds33.get_accelerometer_g_forces()
    accel_angle=lsm6ds33.get_accelerometer_angles()
    gyro_raw=lsm6ds33.get_gyroscope_raw()
    gyro_ang_vel=lsm6ds33.get_gyro_angular_velocity()
    magnet=lis3mdl.get_magnetometer_raw()


    aaa1=open('data_accele_f_force.dat','ab')
    np.savetxt(aaa1 ,np.expand_dims(accel_gforce, axis=0),  fmt='%4.2f %4.2f %4.2f') 

    aaa2=open('data_accele_raw.dat','ab')
    np.savetxt(aaa2 ,np.expand_dims(accel_raw, axis=0),  fmt='%4.2f %4.2f %4.2f') 

    aaa3=open('data_accele_angles.dat','ab')
    np.savetxt(aaa3 ,np.expand_dims(accel_angle, axis=0), fmt='%4.2f %4.2f') 

sleep(1)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-10 17:14:33

我在传感器读数中使用虚拟值,但是下面这个应该可以:

代码语言:javascript
复制
import calendar
import numpy as np
from time import sleep
import time

while True:
    # get time
    timestamp = ts = calendar.timegm(time.gmtime())
    # sensor readings
    timestamped_sensor_readings = np.ndarray((0,), np.float32)
    # get sensor placeholder values
    timestamped_sensor_readings = np.append(timestamped_sensor_readings, np.random.rand(3))
    timestamped_sensor_readings = np.append(timestamped_sensor_readings, np.random.rand(3))
    timestamped_sensor_readings = np.append(timestamped_sensor_readings, np.random.rand(2))

    # write format for readings
    write_fmt = " ".join("%4.2f" for _ in timestamped_sensor_readings)
    # append time
    timestamped_sensor_readings = np.append(timestamped_sensor_readings, float(timestamp))
    write_fmt += " %.0f"

    with open("mydatafile.txt", "ab") as f:
        np.savetxt(f, np.expand_dims(timestamped_sensor_readings, axis=0),  fmt=write_fmt)

    sleep(1)

产出如下:

代码语言:javascript
复制
$ tail -f mydatafile.txt 
0.72 0.90 0.77 0.37 0.51 0.46 0.41 0.76 1560186762
0.69 0.49 0.62 0.32 0.60 0.61 0.59 0.52 1560186763
0.17 0.42 0.97 0.07 0.83 0.67 0.48 0.43 1560186764
0.10 0.02 0.07 0.16 0.05 0.83 0.51 0.31 1560186765
0.64 0.78 0.29 0.96 0.04 0.19 0.11 0.43 1560186766
0.12 0.87 0.04 0.99 0.57 0.81 0.05 0.57 1560186767
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56499513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档