Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, i2cBus, gaussScale):
self.bus = SMBus(i2cBus)
self.bus.write_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.CTRL_REG1_A, LSM303Accelerometer.POWER_ON)
self.bus.write_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.CTRL_REG4_A, gaussScale)
if gaussScale == LSM303Accelerometer.SCALE_A_2G:
self.scale = (-2.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_4G:
self.scale = (-4.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_8G:
self.scale = (-8.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_16G:
self.scale = (-16.0 / 32768.0)
def get_raw_data(self):
x = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_X_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_X_L_A)
if x >= 32768:
x = BitArray(bin(x)).int
y = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Y_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Y_L_A)
if y >= 32768:
y = BitArray(bin(y)).int
z = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Z_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Z_L_A)
if z >= 32768:
z = BitArray(bin(z)).int
return self.scale * (x + self.ZERO_X), self.scale * (y + self.ZERO_Y), self.scale * (z - self.ZERO_Z)
def get_raw_data(self):
x = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_X_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_X_L_A)
if x >= 32768:
x = BitArray(bin(x)).int
y = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Y_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Y_L_A)
if y >= 32768:
y = BitArray(bin(y)).int
z = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Z_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Z_L_A)
if z >= 32768:
z = BitArray(bin(z)).int
return self.scale * (x + self.ZERO_X), self.scale * (y + self.ZERO_Y), self.scale * (z - self.ZERO_Z)
def __init__(self, i2cBus=1):
self.gyro = L3GD20Gyroscope(i2cBus, L3GD20Gyroscope.DPS2000)
self.accel = LSM303Accelerometer(i2cBus, LSM303Accelerometer.SCALE_A_8G)
initOrientation = self.accel.get_orientation()
self.roll = initOrientation.roll
self.pitch = initOrientation.pitch
self.yaw = initOrientation.yaw
self.kalmanFilter = KalmanFilter(
IMU.GYRO_NOISE, IMU.BIAS_NOISE, IMU.ACCEL_NOISE)
self.thread = threading.Thread(target=self.updateOrientation)
self.thread.daemon = True
self.thread.start()
def get_raw_data(self):
x = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_X_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_X_L_A)
if x >= 32768:
x = BitArray(bin(x)).int
y = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Y_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Y_L_A)
if y >= 32768:
y = BitArray(bin(y)).int
z = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Z_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Z_L_A)
if z >= 32768:
z = BitArray(bin(z)).int
def __init__(self, i2cBus, gaussScale):
self.bus = SMBus(i2cBus)
self.bus.write_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.CTRL_REG1_A, LSM303Accelerometer.POWER_ON)
self.bus.write_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.CTRL_REG4_A, gaussScale)
if gaussScale == LSM303Accelerometer.SCALE_A_2G:
self.scale = (-2.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_4G:
self.scale = (-4.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_8G:
self.scale = (-8.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_16G:
self.scale = (-16.0 / 32768.0)
def get_raw_data(self):
x = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_X_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_X_L_A)
if x >= 32768:
x = BitArray(bin(x)).int
y = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Y_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Y_L_A)
if y >= 32768:
y = BitArray(bin(y)).int
z = 256 * self.bus.read_byte_data(LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Z_H_A) + \
self.bus.read_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.OUT_Z_L_A)
if z >= 32768:
z = BitArray(bin(z)).int
return self.scale * (x + self.ZERO_X), self.scale * (y + self.ZERO_Y), self.scale * (z - self.ZERO_Z)
def __init__(self, i2cBus, gaussScale):
self.bus = SMBus(i2cBus)
self.bus.write_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.CTRL_REG1_A, LSM303Accelerometer.POWER_ON)
self.bus.write_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.CTRL_REG4_A, gaussScale)
if gaussScale == LSM303Accelerometer.SCALE_A_2G:
self.scale = (-2.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_4G:
self.scale = (-4.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_8G:
self.scale = (-8.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_16G:
self.scale = (-16.0 / 32768.0)
def __init__(self, i2cBus, gaussScale):
self.bus = SMBus(i2cBus)
self.bus.write_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.CTRL_REG1_A, LSM303Accelerometer.POWER_ON)
self.bus.write_byte_data(
LSM303Accelerometer.LSM_ACC_ADDR, LSM303Accelerometer.CTRL_REG4_A, gaussScale)
if gaussScale == LSM303Accelerometer.SCALE_A_2G:
self.scale = (-2.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_4G:
self.scale = (-4.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_8G:
self.scale = (-8.0 / 32768.0)
if gaussScale == LSM303Accelerometer.SCALE_A_16G:
self.scale = (-16.0 / 32768.0)