1

我找不到有关如何从连接到我的树莓派的 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, )
4

1 回答 1

0

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

你必须设置sense.set_imu_config(True,True,True) #compass/gyroscope/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, )
于 2019-01-28T11:07:52.040 回答