adafruit / Adafruit_CircuitPython_BNO055

CircuitPython driver for BNO055 absolute orientation sensor
MIT License
85 stars 51 forks source link

How to use euler as a compass heading #99

Closed KingFuGitHub closed 2 years ago

KingFuGitHub commented 2 years ago

Currently the euler acts like a heading when it's turned on facing north. I wonder how I could make it so the sensor.euler[0] acts like a compass heading when not facing north originally when the IMU turned on. Thank you in advance.

tekktrik commented 2 years ago

A brief look at the data sheet doesn't show a way to tell the sensor to compensate for the difference. But you could always do it yourself if you know the angle!

import time
import board
import adafruit_bno055

i2c = board.I2C()
sensor = adafruit_bno055.BNO055_I2C(i2c)

heading_offset = 22.1  # offset of 22.1 degrees

while True:
    print("Heading based on power on: {}".format(sensor.euler[0]))
    print("Compass heading (offset based): {}".format(sensor.euler[0] + heading_offset))
    time.sleep(1)
KingFuGitHub commented 2 years ago

That would be hard coding it because the offset isn't always the same due to the initial boot up orientation being different every time the IMU is powered on.

tekktrik commented 2 years ago

Duplicate of #100