Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
lijutsang committed Apr 22, 2022
1 parent ccc8251 commit 9f4e728
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions port/boards/mpython/modules/mpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def __init__(self):
self._writeReg(0x1B, 0b10100001)
self._writeReg(0x1C, 0b00000011)
self._writeReg(0x1D, 0b10010000)
sleep_ms(100)
time.sleep_ms(100)

def _readReg(self, reg, nbytes=1):
return i2c.readfrom_mem(self.addr, reg, nbytes)
Expand Down Expand Up @@ -819,9 +819,9 @@ def get_x(self):
return self.raw_x * 0.25
if (self.chip == 2):
self._get_raw()
return -0.0625 * (self.raw_x - 524288)
# return -0.0625 * (self.raw_x - 524288)
# return -0.0625 * (self.raw_x - self.cali_offset_x - 524288)
# return (self.raw_x - 524288)/16384
return -(self.raw_x - 524288)/16384

def get_y(self):
if (self.chip == 1):
Expand All @@ -830,18 +830,18 @@ def get_y(self):
if (self.chip == 2):
self._get_raw()
# return -0.0625 * (self.raw_y - self.cali_offset_y - 524288)
return -0.0625 * (self.raw_y - 524288)
# return (self.raw_y - 524288)/16384
# return -0.0625 * (self.raw_y - 524288)
return -(self.raw_y - 524288)/16384

def get_z(self):
if (self.chip == 1):
self._get_raw()
return self.raw_z * 0.25
if (self.chip == 2):
self._get_raw()
return 0.0625 * (self.raw_z - 524288)
# return 0.0625 * (self.raw_z - 524288)
# return 0.0625 * (self.raw_z - self.cali_offset_z - 524288)
# return (self.raw_z - 524288)/16384
return (self.raw_z - 524288)/16384

def get_field_strength(self):
if(self.chip==1):
Expand Down Expand Up @@ -904,13 +904,14 @@ def get_heading(self):
temp_x = self.raw_x - self.cali_offset_x
temp_y = self.raw_y - self.cali_offset_y
# temp_z = self.raw_z - self.cali_offset_z
heading = math.atan2(temp_y, -temp_x) * (180 / 3.14159265) + 180
heading = math.atan2(temp_y, -temp_x) * (180 / 3.14159265) + 180 + 3
return heading
else:
self._get_raw()
# temp_x = self.raw_x - self.cali_offset_x
# temp_y = self.raw_y - self.cali_offset_y
# heading = math.atan2(temp_y, -temp_x) * (180 / 3.14159265) + 180 + 3
if(self.cali_offset_x):
self._get_raw()
temp_x = self.raw_x - self.cali_offset_x
temp_y = self.raw_y - self.cali_offset_y
heading = math.atan2(temp_y, -temp_x) * (180 / 3.14159265) + 180 + 3
heading = math.atan2(self.get_y(), -self.get_x()) * (180 / 3.14159265) + 180 + 3
return heading

Expand Down

0 comments on commit 9f4e728

Please sign in to comment.