gpt4 book ai didi

python - 从 sensehas IMU 上的磁力计收集数据

转载 作者:太空宇宙 更新时间:2023-11-03 21:19:46 24 4
gpt4 key购买 nike

我找不到有关如何从连接到我的树莓派的 sensehat 上的 IMU 导入和收集数据的信息。我应该写什么来导入它并保存数据?

我编写了具有相同功能的代码,但是对于加速度计:

import logging
import logzero
from logzero import logger
from sense_hat import SenseHat
import os
dir_path = os.path.dirname(os.path.realpath(__file__))

sh = SenseHat()

logzero.logfile(dir_path+"/accel.csv")

formatter = logging.Formatter('%(name)s - %(asctime)-15s - %(levelname)s: %(message)s');
logzero.formatter(formatter)

acceleration = sense.get_accelerometer_raw()
x = acceleration['x']
y = acceleration['y']
z = acceleration['z']

x=round(x, 0)
y=round(y, 0)
z=round(z, 0)

logger.info("%s,%s,%s", x, y, z, )

最佳答案

来自 Sense HAT 文档页面 ( https://pythonhosted.org/sense-hat/api/#imu-sensor )

您必须设置sense.set_imu_config(True,True,True)#compass/gyrscope/accelerometer

import logging
import logzero
from logzero import logger
from sense_hat import SenseHat
import os
dir_path = os.path.dirname(os.path.realpath(__file__))

sh = SenseHat()
sh.set_imu_config(True, True, True)

logzero.logfile(dir_path+"/accel.csv")

formatter = logging.Formatter('%(name)s - %(asctime)-15s - %(levelname)s: %(message)s');
logzero.formatter(formatter)

acceleration = sh.get_accelerometer_raw()
x = acceleration['x']
y = acceleration['y']
z = acceleration['z']

x=round(x, 0)
y=round(y, 0)
z=round(z, 0)

north = sh.get_compass()
print("North: %s" % north) #prints direction of North in degrees

logger.info("%s,%s,%s", x, y, z, )

关于python - 从 sensehas IMU 上的磁力计收集数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54388558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com