示例#1
0
    def read_raw_data(self):
        '''
        Read the raw data from the sensor, scale it appropriately and store for later use
        '''
        self.raw_gyro_data = I2CUtils.i2c_read_block(self.bus, self.address,
                                                     MPU6050.GYRO_START_BLOCK,
                                                     6)
        self.raw_accel_data = I2CUtils.i2c_read_block(
            self.bus, self.address, MPU6050.ACCEL_START_BLOCK, 6)
        self.raw_temp_data = I2CUtils.i2c_read_block(self.bus, self.address,
                                                     MPU6050.TEMP_START_BLOCK,
                                                     2)

        self.gyro_raw_x = I2CUtils.twos_compliment(
            self.raw_gyro_data[MPU6050.GYRO_XOUT_H],
            self.raw_gyro_data[MPU6050.GYRO_XOUT_L])
        self.gyro_raw_y = I2CUtils.twos_compliment(
            self.raw_gyro_data[MPU6050.GYRO_YOUT_H],
            self.raw_gyro_data[MPU6050.GYRO_YOUT_L])
        self.gyro_raw_z = I2CUtils.twos_compliment(
            self.raw_gyro_data[MPU6050.GYRO_ZOUT_H],
            self.raw_gyro_data[MPU6050.GYRO_ZOUT_L])

        self.accel_raw_x = I2CUtils.twos_compliment(
            self.raw_accel_data[MPU6050.ACCEL_XOUT_H],
            self.raw_accel_data[MPU6050.ACCEL_XOUT_L])
        self.accel_raw_y = I2CUtils.twos_compliment(
            self.raw_accel_data[MPU6050.ACCEL_YOUT_H],
            self.raw_accel_data[MPU6050.ACCEL_YOUT_L])
        self.accel_raw_z = I2CUtils.twos_compliment(
            self.raw_accel_data[MPU6050.ACCEL_ZOUT_H],
            self.raw_accel_data[MPU6050.ACCEL_ZOUT_L])

        self.raw_temp = I2CUtils.twos_compliment(
            self.raw_temp_data[MPU6050.TEMP_OUT_H],
            self.raw_temp_data[MPU6050.TEMP_OUT_L])

        # We convert these to radians for consistency and so we can easily combine later in the filter
        self.gyro_scaled_x = math.radians(self.gyro_raw_x /
                                          MPU6050.GYRO_SCALE[self.fs_scale][1])
        self.gyro_scaled_y = math.radians(self.gyro_raw_y /
                                          MPU6050.GYRO_SCALE[self.fs_scale][1])
        self.gyro_scaled_z = math.radians(self.gyro_raw_z /
                                          MPU6050.GYRO_SCALE[self.fs_scale][1])

        self.scaled_temp = self.raw_temp / 340 + 36.53

        self.accel_scaled_x = self.accel_raw_x / MPU6050.ACCEL_SCALE[
            self.afs_scale][1]
        self.accel_scaled_y = self.accel_raw_y / MPU6050.ACCEL_SCALE[
            self.afs_scale][1]
        self.accel_scaled_z = self.accel_raw_z / MPU6050.ACCEL_SCALE[
            self.afs_scale][1]

        self.pitch = self.read_x_rotation(self.read_scaled_accel_x(),
                                          self.read_scaled_accel_y(),
                                          self.read_scaled_accel_z())
        self.roll = self.read_y_rotation(self.read_scaled_accel_x(),
                                         self.read_scaled_accel_y(),
                                         self.read_scaled_accel_z())
示例#2
0
文件: mpu6050.py 项目: bitify/raspi
    def read_raw_data(self):
        '''
        Read the raw data from the sensor, scale it appropriately and store for later use
        '''
        self.raw_gyro_data = I2CUtils.i2c_read_block(self.bus, self.address, MPU6050.GYRO_START_BLOCK, 6)
        self.raw_accel_data = I2CUtils.i2c_read_block(self.bus, self.address, MPU6050.ACCEL_START_BLOCK, 6)
        self.raw_temp_data = I2CUtils.i2c_read_block(self.bus, self.address, MPU6050.TEMP_START_BLOCK, 2)
        
        self.gyro_raw_x = I2CUtils.twos_compliment(self.raw_gyro_data[MPU6050.GYRO_XOUT_H], self.raw_gyro_data[MPU6050.GYRO_XOUT_L])
        self.gyro_raw_y = I2CUtils.twos_compliment(self.raw_gyro_data[MPU6050.GYRO_YOUT_H], self.raw_gyro_data[MPU6050.GYRO_YOUT_L])
        self.gyro_raw_z = I2CUtils.twos_compliment(self.raw_gyro_data[MPU6050.GYRO_ZOUT_H], self.raw_gyro_data[MPU6050.GYRO_ZOUT_L])
        
        self.accel_raw_x = I2CUtils.twos_compliment(self.raw_accel_data[MPU6050.ACCEL_XOUT_H], self.raw_accel_data[MPU6050.ACCEL_XOUT_L])
        self.accel_raw_y = I2CUtils.twos_compliment(self.raw_accel_data[MPU6050.ACCEL_YOUT_H], self.raw_accel_data[MPU6050.ACCEL_YOUT_L])
        self.accel_raw_z = I2CUtils.twos_compliment(self.raw_accel_data[MPU6050.ACCEL_ZOUT_H], self.raw_accel_data[MPU6050.ACCEL_ZOUT_L])
        
        self.raw_temp = I2CUtils.twos_compliment(self.raw_temp_data[MPU6050.TEMP_OUT_H], self.raw_temp_data[MPU6050.TEMP_OUT_L])

        # We convert these to radians for consistency and so we can easily combine later in the filter
        self.gyro_scaled_x = math.radians(self.gyro_raw_x / MPU6050.GYRO_SCALE[self.fs_scale][1]) 
        self.gyro_scaled_y = math.radians(self.gyro_raw_y / MPU6050.GYRO_SCALE[self.fs_scale][1]) 
        self.gyro_scaled_z = math.radians(self.gyro_raw_z / MPU6050.GYRO_SCALE[self.fs_scale][1]) 

        self.scaled_temp = self.raw_temp / 340 + 36.53

        self.accel_scaled_x = self.accel_raw_x / MPU6050.ACCEL_SCALE[self.afs_scale][1]
        self.accel_scaled_y = self.accel_raw_y / MPU6050.ACCEL_SCALE[self.afs_scale][1]
        self.accel_scaled_z = self.accel_raw_z / MPU6050.ACCEL_SCALE[self.afs_scale][1]
        
        self.pitch = self.read_x_rotation(self.read_scaled_accel_x(),self.read_scaled_accel_y(),self.read_scaled_accel_z())
        self.roll =  self.read_y_rotation(self.read_scaled_accel_x(),self.read_scaled_accel_y(),self.read_scaled_accel_z())
示例#3
0
    def read_raw_data(self):
        self.raw_accel_data = I2CUtils.i2c_read_block(self.bus, self.address, ADXL345.ACCEL_START_BLOCK, 6)
        
        self.accel_raw_x = I2CUtils.twos_compliment(self.raw_accel_data[ADXL345.ACCEL_XOUT_H], self.raw_accel_data[ADXL345.ACCEL_XOUT_L])
        self.accel_raw_y = I2CUtils.twos_compliment(self.raw_accel_data[ADXL345.ACCEL_YOUT_H], self.raw_accel_data[ADXL345.ACCEL_YOUT_L])
        self.accel_raw_z = I2CUtils.twos_compliment(self.raw_accel_data[ADXL345.ACCEL_ZOUT_H], self.raw_accel_data[ADXL345.ACCEL_ZOUT_L])

        self.accel_scaled_x = self.accel_raw_x * ADXL345.ACCEL_SCALE
        self.accel_scaled_y = self.accel_raw_y * ADXL345.ACCEL_SCALE
        self.accel_scaled_z = self.accel_raw_z * ADXL345.ACCEL_SCALE
示例#4
0
文件: hmc5883l.py 项目: quhezheng/ros
 def read_raw_data(self):
     '''
     Read the raw data from the sensor, scale it appropriately and store for later use
     '''
     self.raw_data = I2CUtils.i2c_read_block(self.bus, self.address, HMC5883L.DATA_START_BLOCK, 6)
     self.raw_x = I2CUtils.twos_compliment(self.raw_data[HMC5883L.DATA_XOUT_H], self.raw_data[HMC5883L.DATA_XOUT_L]) + self.x_offset
     self.raw_y = I2CUtils.twos_compliment(self.raw_data[HMC5883L.DATA_YOUT_H], self.raw_data[HMC5883L.DATA_YOUT_L]) + self.y_offset
     self.raw_z = I2CUtils.twos_compliment(self.raw_data[HMC5883L.DATA_ZOUT_H], self.raw_data[HMC5883L.DATA_ZOUT_L]) + self.z_offset
 
     self.scaled_x = self.raw_x * HMC5883L.GAIN_SCALE[self.gain][2]
     self.scaled_y = self.raw_y * HMC5883L.GAIN_SCALE[self.gain][2]
     self.scaled_z = self.raw_z * HMC5883L.GAIN_SCALE[self.gain][2]
示例#5
0
 def __init__(self, bus, address, name, oss=3):
     '''
     Constructor
     '''
     self.bus = bus
     self.address = address
     self.name = name
     
     self.calibration = I2CUtils.i2c_read_block(bus, address, BMP085.CALIB_BLOCK_ADDRESS, BMP085.CALIB_BLOCK_SIZE)
     self.oss = oss
     self.temp_wait_period = 0.004
     self.pressure_wait_period = 0.0255  # Conversion time
示例#6
0
    def __init__(self, bus, address, name, oss=3):
        '''
        Constructor
        '''
        self.bus = bus
        self.address = address
        self.name = name

        self.calibration = I2CUtils.i2c_read_block(bus, address,
                                                   BMP085.CALIB_BLOCK_ADDRESS,
                                                   BMP085.CALIB_BLOCK_SIZE)
        self.oss = oss
        self.temp_wait_period = 0.004
        self.pressure_wait_period = 0.0255  # Conversion time
示例#7
0
    def read_raw_data(self):
        self.raw_accel_data = I2CUtils.i2c_read_block(
            self.bus, self.address, ADXL345.ACCEL_START_BLOCK, 6)

        self.accel_raw_x = I2CUtils.twos_compliment(
            self.raw_accel_data[ADXL345.ACCEL_XOUT_H],
            self.raw_accel_data[ADXL345.ACCEL_XOUT_L])
        self.accel_raw_y = I2CUtils.twos_compliment(
            self.raw_accel_data[ADXL345.ACCEL_YOUT_H],
            self.raw_accel_data[ADXL345.ACCEL_YOUT_L])
        self.accel_raw_z = I2CUtils.twos_compliment(
            self.raw_accel_data[ADXL345.ACCEL_ZOUT_H],
            self.raw_accel_data[ADXL345.ACCEL_ZOUT_L])

        self.accel_scaled_x = self.accel_raw_x * ADXL345.ACCEL_SCALE
        self.accel_scaled_y = self.accel_raw_y * ADXL345.ACCEL_SCALE
        self.accel_scaled_z = self.accel_raw_z * ADXL345.ACCEL_SCALE
示例#8
0
    def read_raw_data(self):
        '''
        Read the raw data from the sensor, scale it appropriately and store for later use
        '''
        self.raw_data = I2CUtils.i2c_read_block(self.bus, self.address,
                                                HMC5883L.DATA_START_BLOCK, 6)
        self.raw_x = I2CUtils.twos_compliment(
            self.raw_data[HMC5883L.DATA_XOUT_H],
            self.raw_data[HMC5883L.DATA_XOUT_L]) - self.x_offset
        self.raw_y = I2CUtils.twos_compliment(
            self.raw_data[HMC5883L.DATA_YOUT_H],
            self.raw_data[HMC5883L.DATA_YOUT_L]) - self.y_offset
        self.raw_z = I2CUtils.twos_compliment(
            self.raw_data[HMC5883L.DATA_ZOUT_H],
            self.raw_data[HMC5883L.DATA_ZOUT_L]) - self.z_offset

        self.scaled_x = self.raw_x * HMC5883L.GAIN_SCALE[self.gain][2]
        self.scaled_y = self.raw_y * HMC5883L.GAIN_SCALE[self.gain][2]
        self.scaled_z = self.raw_z * HMC5883L.GAIN_SCALE[self.gain][2]