diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 2df938b..75abcc3 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -173,7 +173,7 @@ class Rate: # pylint: disable=too-few-public-methods CYCLE_40_HZ = 3 # 40 Hz -class MPU6050: +class MPU6050: # pylint: disable=too-many-instance-attributes """Driver for the MPU6050 6-DoF accelerometer and gyroscope. :param ~busio.I2C i2c_bus: The I2C bus the device is connected to @@ -218,7 +218,7 @@ def __init__(self, i2c_bus: I2C, address: int = _MPU6050_DEFAULT_ADDRESS) -> Non self._filter_bandwidth = Bandwidth.BAND_260_HZ self._gyro_range = GyroRange.RANGE_500_DPS self._accel_range = Range.RANGE_2_G - self._accel_scale = 1.0/[16384,8192,4096,2048][self._accel_range] + self._accel_scale = 1.0 / [16384,8192,4096,2048][self._accel_range] sleep(0.100) self.clock_source = ( ClockSource.CLKSEL_INTERNAL_X @@ -277,10 +277,10 @@ def temperature(self) -> float: def acceleration(self) -> Tuple[float, float, float]: """Acceleration X, Y, and Z axis data in :math:`m/s^2`""" raw_data = self._raw_accel_data - return self.scale_accel([raw_data[0][0],raw_data[1][0],raw_data[2][0]]) + return self.scale_accel([raw_data[0][0], raw_data[1][0], raw_data[2][0]]) def scale_accel(self, raw_data) -> Tuple[float, float, float]: - # setup range dependent scaling + """Scale raw X, Y, and Z axis data to :math:`m/s^2`""" accel_x = (raw_data[0] * self._accel_scale) * STANDARD_GRAVITY accel_y = (raw_data[1] * self._accel_scale) * STANDARD_GRAVITY accel_z = (raw_data[2] * self._accel_scale) * STANDARD_GRAVITY @@ -293,6 +293,7 @@ def gyro(self) -> Tuple[float, float, float]: return self.scale_gyro((raw_data[0][0], raw_data[1][0], raw_data[2][0])) def scale_gyro(self, raw_data) -> Tuple[float, float, float]: + """Scale raw gyro data to :math:`ยบ/s`""" raw_x = raw_data[0] raw_y = raw_data[1] raw_z = raw_data[2] @@ -348,7 +349,7 @@ def accelerometer_range(self, value: int) -> None: if (value < 0) or (value > 3): raise ValueError("accelerometer_range must be a Range") self._accel_range = value - self._accel_scale = 1.0/[16384,8192,4096,2048][value] + self._accel_scale = 1.0 / [16384,8192,4096,2048][value] sleep(0.01) @property @@ -392,8 +393,8 @@ def clock_source(self, value: int) -> None: def read_whole_fifo(self): """Return raw FIFO bytes""" # This code must be fast to ensure samples are contiguous - c = self.fifo_count - buf = bytearray(c) + count = self.fifo_count + buf = bytearray(count) buf[0] = _MPU6050_FIFO_R_W with self.i2c_device: self.i2c_device.write_then_readinto(buf, buf, out_end=1, in_start=0)