diff --git a/port/boards/mpython/modules/mpython.py b/port/boards/mpython/modules/mpython.py index 9a13e8d0..a43f5a09 100755 --- a/port/boards/mpython/modules/mpython.py +++ b/port/boards/mpython/modules/mpython.py @@ -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) @@ -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): @@ -830,8 +830,8 @@ 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): @@ -839,9 +839,9 @@ def get_z(self): 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): @@ -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