我编写了一个在Raspberry Pi Zero W上运行的 Python3 脚本,该脚本从 IMU 传感器 (MPU9250) 收集数据并创建 3 个不同的角度值;滚动、俯仰、偏航。看起来像这样:
def main():
while True:
dataAcc = mpu.readAccelerometerMaster()
dataGyro = mpu.readGyroscopeMaster()
dataMag = mpu.readMagnetometerMaster()
[ax, ay, az] = [round(dataAcc[0], 5), round(dataAcc[1], 5), round(dataAcc[2], 5)]
[gx, gy, gz] = [round(dataGyro[0], 5), round(dataGyro[1], 5), round(dataGyro[2], 5)]
[mx, my, mz] = [round(dataMag[0], 5), round(dataMag[1], 5), round(dataMag[2], 5)]
update(gx, gy, gz, ax, ay, az, mx, my, mz)
roll = getRoll()
pitch = getPitch()
yaw = getYaw()
print(f"Roll: {round(roll, 2)}\tPitch: {round(pitch, 2)}\tYaw: …
Run Code Online (Sandbox Code Playgroud)