From 49ca2ac5ad2d2fdfceff94af90c204fe1afe3692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atle=20H=2E=20Havs=C3=B8?= Date: Tue, 26 Aug 2014 17:41:25 +0200 Subject: Convert data from sensors. --- drivers/mpu6000.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'drivers/mpu6000.h') diff --git a/drivers/mpu6000.h b/drivers/mpu6000.h index 1297810..a667b00 100644 --- a/drivers/mpu6000.h +++ b/drivers/mpu6000.h @@ -45,9 +45,9 @@ class MPU6000 { Time::sleep(1); write_register(0x1A, (3 << 0)); // CONFIG - DLPF_CFG 42hz Time::sleep(1); - write_register(0x1B, 0); // GYRO_CFG + write_register(0x1B, (3 << 3)); // GYRO_CFG, 2000 deg/s Time::sleep(1); - write_register(0x1C, 0); // ACCEL_CFG + write_register(0x1C, (3 << 3)); // ACCEL_CFG, +-16g Time::sleep(1); write_register(0x6A, (1 << 4)); // USER_CTRL - I2C Off Time::sleep(1); @@ -59,7 +59,7 @@ class MPU6000 { void update() { - uint16_t temp; + int16_t temp; spi.reg.CR1 = (1 << 9) | (1 << 8) | (1 << 6) | (2 << 3) | (1 << 2) | (1 << 1) | (1 << 0); // SSM On | SSI 1 | SPE On | BR /8 | CPOL CK 1 Idle | CPHA Second clock data capture spi.reg.CR2 = (1 << 12) | ( 7 << 8); // FRXTH RXNE if FIFO >= 8bit | DS 8-bit @@ -67,23 +67,23 @@ class MPU6000 { temp = raw_data[0] << 8; temp |= raw_data[1]; - accel[0] = float(temp); + accel[0] = float(temp) * 2 / 32768.0f; temp = raw_data[2] << 8; temp |= raw_data[3]; - accel[1] = float(temp); + accel[1] = float(temp) * 2 / 32768.0f; temp = raw_data[4] << 8; temp |= raw_data[5]; - accel[2] = float(temp); + accel[2] = float(temp) * 2 / 32768.0f; temp = raw_data[8] << 8; temp |= raw_data[9]; - gyro[0] = float(temp); + gyro[0] = float(temp) * 2000 / 32768.0f; temp = raw_data[10] << 8; temp |= raw_data[11]; - gyro[1] = float(temp); + gyro[1] = float(temp) * 2000 / 32768.0f; temp = raw_data[12] << 8; temp |= raw_data[13]; - gyro[2] = float(temp); + gyro[2] = float(temp) * 2000 / 32768.0f; } }; -- cgit v1.2.3