Example #1
0
def mpu_raw_acc_to_ug(rawval, abs_fullscale):
    """
        mpu9150 acceleration is stored as a 16 bit signed value
        
        abs_fullscale: The RM-MPU manual is not clear on this.
        The full scale ranges are (+/- 2, 4, 8 16g) in 16 bits.
        'abs_fullscale' is one half of the total +/- range.
        for +/- 2 g the total range is [-2,2] which is 4g. 
        
        This should mean:
        abs_fullscale                  LSB Sensitivity
            2                               61ug/bit  (16384bits/g)
            4                              122ug/bit
            8                              244ug/bit
            16                             488ug/bit
        
    """
    rawval        = int(rawval)
    rawval        = u.twos_comp(rawval&0xffff,16)
    accdata       = 0.0
    
    if(abs_fullscale==2):
        accdata   = rawval * 61e-6
    elif(abs_fullscale==4):
        accdata   = rawval * 122e-6
    elif(abs_fullscale==8):
        accdata   = rawval * 244e-6
    elif(abs_fullscale==16):
        accdata   = rawval * 488.3e-6
    else:
        raise TypeError("abs_fullscale must be 2, 4, 8 or 16")

    return accdata
Example #2
0
def mpu_raw_gyro_to_dps(rawval, abs_fullscale):
    """
        mpu9150 gyro rate is stored as a 16 bit twos compliment value
        
        abs_fullscale: 
        The full scale ranges are (+/- 250, 500, 1000, 2000 dps) in 16 bits.
        'abs_fullscale' is one half of the total +/- range.
        for +/- 250 g the total range is [-250,250] which is 500dps. 
        
        This should mean:
        abs_fullscale                  LSB Sensitivity
            250                            0.00764(degrees/bit)/s ((131 LSB/degree)/s)
            500                            0.01527(degrees/bit)/s ((65.5 LSB/degree)/s)
            1000                           0.03049(degrees/bit)/s ((32.8 LSB/degree)/s)
            2000                           0.06098(degrees/bit)/s ((16.4 LSB/degree)/s)
        
    """
    rawval = int(rawval)
    rawval = u.twos_comp(rawval & 0xffff, 16)
    gyrodata = 0.0

    if (abs_fullscale == 250):
        gyrodata = rawval * 0.00764
    elif (abs_fullscale == 500):
        gyrodata = rawval * 0.01527
    elif (abs_fullscale == 1000):
        gyrodata = rawval * 0.03049
    elif (abs_fullscale == 2000):
        gyrodata = rawval * 0.06098
    else:
        raise TypeError("abs_fullscale must be 250, 500, 1000 or 2000")

    return gyrodata
Example #3
0
def mpu_raw_gyro_to_dps(rawval, abs_fullscale):
    """
        mpu9150 gyro rate is stored as a 16 bit twos compliment value
        
        abs_fullscale: 
        The full scale ranges are (+/- 250, 500, 1000, 2000 dps) in 16 bits.
        'abs_fullscale' is one half of the total +/- range.
        for +/- 250 g the total range is [-250,250] which is 500dps. 
        
        This should mean:
        abs_fullscale                  LSB Sensitivity
            250                            0.00764(degrees/bit)/s ((131 LSB/degree)/s)
            500                            0.01527(degrees/bit)/s ((65.5 LSB/degree)/s)
            1000                           0.03049(degrees/bit)/s ((32.8 LSB/degree)/s)
            2000                           0.06098(degrees/bit)/s ((16.4 LSB/degree)/s)
        
    """
    rawval        = int(rawval)
    rawval        = u.twos_comp(rawval&0xffff,16)
    gyrodata       = 0.0
    
    if(abs_fullscale==250):
        gyrodata   = rawval * 0.00764
    elif(abs_fullscale==500):
        gyrodata   = rawval * 0.01527
    elif(abs_fullscale==1000):
        gyrodata   = rawval * 0.03049
    elif(abs_fullscale==2000):
        gyrodata   = rawval * 0.06098
    else:
        raise TypeError("abs_fullscale must be 250, 500, 1000 or 2000")

    return gyrodata
Example #4
0
def mpu_raw_acc_to_ug(rawval, abs_fullscale):
    """
        mpu9150 acceleration is stored as a 16 bit signed value
        
        abs_fullscale: The RM-MPU manual is not clear on this.
        The full scale ranges are (+/- 2, 4, 8 16g) in 16 bits.
        'abs_fullscale' is one half of the total +/- range.
        for +/- 2 g the total range is [-2,2] which is 4g. 
        
        This should mean:
        abs_fullscale                  LSB Sensitivity
            2                               61ug/bit  (16384bits/g)
            4                              122ug/bit
            8                              244ug/bit
            16                             488ug/bit
        
    """
    rawval = int(rawval)
    rawval = u.twos_comp(rawval & 0xffff, 16)
    accdata = 0.0

    if (abs_fullscale == 2):
        accdata = rawval * 61e-6
    elif (abs_fullscale == 4):
        accdata = rawval * 122e-6
    elif (abs_fullscale == 8):
        accdata = rawval * 244e-6
    elif (abs_fullscale == 16):
        accdata = rawval * 488.3e-6
    else:
        raise TypeError("abs_fullscale must be 2, 4, 8 or 16")

    return accdata
Example #5
0
def adis_raw_gyro_to_dps(rawval):
    """
        adis gyro is 14 bit twos complement
        
        0.05 dps per bit
        
    """
    rawval        = int(rawval)
    rawval        = u.twos_comp(rawval&0x3fff,14)
    gyrodata_dps  = rawval * 0.05
    return gyrodata_dps
Example #6
0
def adis_raw_magn_to_ugauss(rawval):
    """
        adis gyro is 14 bit twos complement
       
        0.5 mgauss per bit 500ugauss per bit
        
    """
    rawval           = int(rawval)
    rawval           = u.twos_comp(rawval&0x3fff,14)
    magndata_ugauss  = rawval * 500
    return magndata_ugauss
Example #7
0
def adis_raw_gyro_to_dps(rawval):
    """
        adis gyro is 14 bit twos complement
        
        0.05 dps per bit
        
    """
    rawval = int(rawval)
    rawval = u.twos_comp(rawval & 0x3fff, 14)
    gyrodata_dps = rawval * 0.05
    return gyrodata_dps
Example #8
0
def adis_raw_magn_to_ugauss(rawval):
    """
        adis gyro is 14 bit twos complement
       
        0.5 mgauss per bit 500ugauss per bit
        
    """
    rawval = int(rawval)
    rawval = u.twos_comp(rawval & 0x3fff, 14)
    magndata_ugauss = rawval * 500
    return magndata_ugauss
Example #9
0
def mpu_raw_temp_to_dC(rawval):
    """
        mpu9150 temperature is stored as a 16 bit signed value
        The conversion to temperature in C is in RM-MPU9150.pdf
    """
    rawval      = int(rawval)
    tdata_twos  = u.twos_comp(rawval&0xffff,16)
    tdata       = float(tdata_twos)
    
    tdata       = (tdata/340.0) + 35.0
   
    return tdata
Example #10
0
def mpu_raw_temp_to_dC(rawval):
    """
        mpu9150 temperature is stored as a 16 bit signed value
        The conversion to temperature in C is in RM-MPU9150.pdf
    """
    rawval = int(rawval)
    tdata_twos = u.twos_comp(rawval & 0xffff, 16)
    tdata = float(tdata_twos)

    tdata = (tdata / 340.0) + 35.0

    return tdata
Example #11
0
def adis_raw_acc_to_ug(rawval):
    """
        adis accel data is 14 bit twos complement.
        
        3.3mg per bit or 3330ug per bit
        return value in  ug  (micro-g)
        
    """
    rawval        = int(rawval)
    rawval        = u.twos_comp(rawval&0x3fff,14)
    accdata_ug    = rawval * 3330
   
    return accdata_ug
Example #12
0
def adis_raw_acc_to_ug(rawval):
    """
        adis accel data is 14 bit twos complement.
        
        3.3mg per bit or 3330ug per bit
        return value in  ug  (micro-g)
        
    """
    rawval = int(rawval)
    rawval = u.twos_comp(rawval & 0x3fff, 14)
    accdata_ug = rawval * 3330

    return accdata_ug
Example #13
0
def mpl_raw_temp_to_dC(rawval):
    """
        mpl3115a2 temperature is represented as a
        signed 8 bit integer and a fractional 4 bit
        component.
    """
    if not isinstance(rawval, np.int64):
        print(type(rawval))
        raise TypeError("rawval must be an numpy.int64")
    tdata_8       = 0.0
    tdata_8_twos  = u.twos_comp((rawval>>8)&0xff, 8)
    tdata_frac    = (rawval&0xf0)  >> 4
    tdata_8       = float(tdata_8_twos)
    if((tdata_frac & 0b1000)!=0):
        tdata_8 += 0.5
    if((tdata_frac & 0b0100)!=0):
        tdata_8 += 0.25
    if((tdata_frac & 0b0010)!=0):
        tdata_8 += 0.125
    if((tdata_frac & 0b0001)!=0):
        tdata_8 += 0.0625
    
    return tdata_8
Example #14
0
def mpl_raw_temp_to_dC(rawval):
    """
        mpl3115a2 temperature is represented as a
        signed 8 bit integer and a fractional 4 bit
        component.
    """
    if not isinstance(rawval, np.int64):
        print(type(rawval))
        raise TypeError("rawval must be an numpy.int64")
    tdata_8 = 0.0
    tdata_8_twos = u.twos_comp((rawval >> 8) & 0xff, 8)
    tdata_frac = (rawval & 0xf0) >> 4
    tdata_8 = float(tdata_8_twos)
    if ((tdata_frac & 0b1000) != 0):
        tdata_8 += 0.5
    if ((tdata_frac & 0b0100) != 0):
        tdata_8 += 0.25
    if ((tdata_frac & 0b0010) != 0):
        tdata_8 += 0.125
    if ((tdata_frac & 0b0001) != 0):
        tdata_8 += 0.0625

    return tdata_8