public float[] get_accel_prod_shift() throws RuntimeIOException { byte[] tmp = new byte[4]; tmp = i2cDevice.readBytes(0x0D, 4); //if (i2c_read(st.hw->addr, 0x0D, 4, tmp)) // return 0x07; float[] st_shift = new float[3]; byte[] shift_code = new byte[3]; shift_code[0] = (byte)(((tmp[0] & 0xE0) >> 3) | ((tmp[3] & 0x30) >> 4)); shift_code[1] = (byte)(((tmp[1] & 0xE0) >> 3) | ((tmp[3] & 0x0C) >> 2)); shift_code[2] = (byte)(((tmp[2] & 0xE0) >> 3) | (tmp[3] & 0x03)); for (int ii = 0; ii < 3; ii++) { if (shift_code[ii] == 0) { st_shift[ii] = 0.f; continue; } /* Equivalent to.. * st_shift[ii] = 0.34f * powf(0.92f/0.34f, (shift_code[ii]-1) / 30.f) */ st_shift[ii] = 0.34f; while (--shift_code[ii] != 0) { st_shift[ii] *= 1.034f; } } return st_shift; }
@Override public Vector3D getAccelerometerData() throws RuntimeIOException { ByteBuffer data = ByteBuffer.wrap(device.readBytes(AXES_DATA, 6)); short x = data.getShort(); short y = data.getShort(); short z = data.getShort(); return ImuDataFactory.createVector(new short[] {x, y, z}, SCALE_FACTOR); }
/** * Each 16-bit accelerometer measurement has a full scale defined in ACCEL_FS (Register 28). * For each full scale setting, the accelerometers' sensitivity per LSB in ACCEL_xOUT is shown in the table below. * AFS_SEL Full Scale Range LSB Sensitivity * 0 +/-2g 16384 LSB/mg * 1 +/-4g 8192 LSB/mg * 2 +/-8g 4096 LSB/mg * 3 +/-16g 2048 LSB/mg * @return Raw data in hardware units. * @throws RuntimeIOException if an I/O error occurs */ public short[] mpu_get_accel_reg() throws RuntimeIOException { if ((sensors & INV_XYZ_ACCEL) == 0) { return null; } // raw_accel == 0x3B == MPU9150_RA_ACCEL_XOUT_H ByteBuffer buffer = ByteBuffer.wrap(i2cDevice.readBytes(MPU9150_RA_ACCEL_XOUT_H, 6)); short x = buffer.getShort(); short y = buffer.getShort(); short z = buffer.getShort(); /* byte[] data = readBytes(MPU9150_RA_ACCEL_XOUT_H, 6); short x = (short)((data[0] << 8) | (data[1] & 0xff)); short y = (short)((data[2] << 8) | (data[3] & 0xff)); short z = (short)((data[4] << 8) | (data[5] & 0xff)); */ return new short[] {x, y, z}; }
@Override public float getPressure() { byte status = device.readByte(STATUS_REG); if ((status & SR_P_DA) == 0) { Logger.warn("Pressure data not available"); return -1; } byte[] raw_data = device.readBytes(PRESS_OUT_XL | READ, 3); int raw_pressure = raw_data[2] << 16 | (raw_data[1] & 0xff) << 8 | (raw_data[0] & 0xff); return (float) (raw_pressure / PRESSURE_SCALE); }
/** * Read raw gyro data directly from the registers. * @return Raw data in hardware units. * @throws RuntimeIOException if an I/O error occurs */ public short[] mpu_get_gyro_reg() throws RuntimeIOException { if ((sensors & INV_XYZ_GYRO) == 0) { return null; } // raw_gyro == 0x43 == MPU9150_RA_GYRO_XOUT_H ByteBuffer buffer = ByteBuffer.wrap(i2cDevice.readBytes(MPU9150_RA_GYRO_XOUT_H, 6)); short x = IOUtil.getShort(buffer); short y = IOUtil.getShort(buffer); short z = IOUtil.getShort(buffer); System.out.format("gyro reg values = (%d, %d, %d)%n", Short.valueOf(x), Short.valueOf(y), Short.valueOf(z)); /*byte[] data = readBytes(MPU9150_RA_GYRO_XOUT_H, 6) short x = (short)((data[0] << 8) | (data[1] & 0xff)); short y = (short)((data[2] << 8) | (data[3] & 0xff)); short z = (short)((data[4] << 8) | (data[5] & 0xff));*/ return new short[] {x, y, z}; }
/** * Read biases to the accel bias 6050 registers. * This function reads from the MPU6050 accel offset cancellations registers. * The format are G in +-8G format. The register is initialised with OTP * factory trim values. * @return accel_bias returned structure with the accel bias * @throws RuntimeIOException if an I/O error occurs */ public short[] mpu_read_6050_accel_bias() throws RuntimeIOException { short[] accel_bias = new short[3]; /* byte[] bias_x_bytes = readBytes(MPU9150_RA_XA_OFFS_H, 2); byte[] bias_y_bytes = readBytes(MPU9150_RA_YA_OFFS_H, 2); byte[] bias_z_bytes = readBytes(MPU9150_RA_ZA_OFFS_H, 2); accel_bias[0] = (bias_x_bytes[0] << 8) | (bias_x_bytes[1] & 0xff); accel_bias[1] = (bias_y_bytes[2] << 8) | (bias_y_bytes[3] & 0xff); accel_bias[2] = (bias_z_bytes[4] << 8) | (bias_z_bytes[5] & 0xff); */ ByteBuffer buffer = ByteBuffer.wrap(i2cDevice.readBytes(MPU9150_RA_XA_OFFS_H, 6)); accel_bias[0] = IOUtil.getShort(buffer); accel_bias[1] = IOUtil.getShort(buffer); accel_bias[2] = IOUtil.getShort(buffer); return accel_bias; }
return i2cDevice.readBytes(MPU9150_RA_MEM_R_W, length);
byte[] tmp = i2cDevice.readBytes(MPU9150_RA_EXT_SENS_DATA_00, 8);
public void init() throws RuntimeIOException { byte[] data = new byte[4]; data[0] = AKM_POWER_DOWN; i2cDevice.writeByte(AKM_REG_CNTL, data[0]); SleepUtil.sleepMillis(1); data[0] = AKM_FUSE_ROM_ACCESS; i2cDevice.writeByte(AKM_REG_CNTL, data[0]); SleepUtil.sleepMillis(1); /* Get sensitivity adjustment data from fuse ROM. */ data = i2cDevice.readBytes(AKM_REG_ASAX, 3); mag_sens_adj[0] = (short)(data[0] + 128); mag_sens_adj[1] = (short)(data[1] + 128); mag_sens_adj[2] = (short)(data[2] + 128); data[0] = AKM_POWER_DOWN; i2cDevice.writeByte(AKM_REG_CNTL, data[0]); SleepUtil.sleepMillis(1); }