Skip to content

Commit

Permalink
Minor update to compass code
Browse files Browse the repository at this point in the history
  • Loading branch information
slabua committed Feb 18, 2024
1 parent 95664d5 commit 7015f77
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions OLED/picomotodash_oled.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
labels = ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"]


def calculate_heading(x, y):
global HEADING
def calculate_heading():
x, y, _ = read_mpu()

# Calculate heading in radians
heading_rad = math.atan2(y, x)
Expand All @@ -74,7 +74,7 @@ def calculate_heading(x, y):
heading_deg = 90 - heading_deg

# Adjust for negative values
HEADING = (heading_deg + 360) % 360
return (heading_deg + 360) % 360


def moving_avg(n):
Expand Down Expand Up @@ -577,9 +577,7 @@ def thread1(PWM2RPM_FACTOR):
# sleep(0.1)
# read_gps()

xx, yy, zz = read_mpu()
# print("Scaled: X = %d , Y = %d" %(xx,yy))
calculate_heading(xx, yy)
HEADING = calculate_heading()
HEADING = moving_avg(9)

# print(key0.value(), key1.value())
Expand Down

0 comments on commit 7015f77

Please sign in to comment.