我找不到有关如何从连接到我的树莓派的感应帽上的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/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, )
关于python - 在感官式IMU上从magentometer收集数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54388558/