Python 传感帽陀螺仪问题
我试图使用sense-hat陀螺仪和加速计来检查pi的俯仰和加速度,如果这种变化很大,我希望pi输出失败。但是,一旦我移动pi,然后将其放回静止位置,所有值都不会返回到静止位置 示例输出 下面是我正在使用的代码:Python 传感帽陀螺仪问题,python,raspberry-pi,gyroscope,Python,Raspberry Pi,Gyroscope,我试图使用sense-hat陀螺仪和加速计来检查pi的俯仰和加速度,如果这种变化很大,我希望pi输出失败。但是,一旦我移动pi,然后将其放回静止位置,所有值都不会返回到静止位置 示例输出 下面是我正在使用的代码: from sense_hat import SenseHat sense = SenseHat() sense.set_imu_config(False,True,True) # gyro and accel only mag turned off while True:
from sense_hat import SenseHat
sense = SenseHat()
sense.set_imu_config(False,True,True) # gyro and accel only mag turned off
while True:
orientation = sense.get_orientation ()
pitch = orientation['pitch']
roll = orientation['roll']
yaw = orientation['yaw']
pitch = round (pitch,0)
roll = round (roll,1)
yaw = round(yaw,2)
acceleration = sense.get_accelerometer_raw()
x = acceleration ['x']
y = acceleration ['y']
z = acceleration ['z']
x=round(x,3)
y=round(y,4)
z=round(z,5)
print("pitch={0}, roll={0}, yaw={0}".format(pitch,yaw,roll))
print("x={0}, y={0}, z{0}".format(x,y,z))
if 5 <= pitch <= 300 or x > 1 or y > 1 or z > 1.5:
sense.show_message("FAIL")
从sense\u hat导入SenseHat
sense=SenseHat()
感知。设置配置(假、真、真)#陀螺和仅加速度磁感应关闭
尽管如此:
方向=sense.get\u方向()
节距=方向[“节距”]
滚动=方向[“滚动”]
偏航=方向[“偏航”]
节距=圆形(节距,0)
滚动=圆形(滚动,1)
偏航=圆形(偏航,2)
加速度=感知。获取加速计原始值()
x=加速度['x']
y=加速度['y']
z=加速度['z']
x=圆形(x,3)
y=圆形(y,4)
z=圆形(z,5)
打印(“俯仰={0},滚动={0},偏航={0}”。格式(俯仰,偏航,滚动))
打印(“x={0},y={0},z{0}”。格式(x,y,z))
如果5 1或z>1.5:
感知。显示信息(“失败”)
由于Python中的缩进非常重要,而且您的代码似乎没有缩进,因此很难理解,请编辑您的问题以更正缩进。我已经编辑了缩进。您可能无法期望值完全返回到原始值。你校准过你的传感器吗(不确定这是否会影响噪声/漂移/重复性/稳定性)?我不希望得到完全相同的值,但它可能非常遥远,而且如果我将音高移动到100,例如,它将缓慢地漂移回4-5,但一次只移动1度或更小。