@SlyD: Ich habe den LSM303DLH und nicht den CMPS ^^
Also ich habe den Kompass wie in diesem beispiel Kalibriert:
Das Problem bei dieser Methode ist, dass ich zum Teil falsche Werte schon beim lesen der "raw" daten wirre Sachen wie 0 oder so bekomme. Daher bringt die Kalibrierung nicht wirklich etwas.Code:// Returns a set of acceleration and raw magnetic readings from the cmp01a. void read_data_raw(vector *a, vector *m) { // read accelerometer values i2c_start(); i2c_write_byte(0x30); // write acc i2c_write_byte(0xa8); // OUT_X_L_A, MSB set to enable auto-increment i2c_start(); // repeated start i2c_write_byte(0x31); // read acc unsigned char axl = i2c_read_byte(); unsigned char axh = i2c_read_byte(); unsigned char ayl = i2c_read_byte(); unsigned char ayh = i2c_read_byte(); unsigned char azl = i2c_read_byte(); unsigned char azh = i2c_read_last_byte(); i2c_stop(); // read magnetometer values i2c_start(); i2c_write_byte(0x3C); // write mag i2c_write_byte(0x03); // OUTXH_M i2c_start(); // repeated start i2c_write_byte(0x3D); // read mag unsigned char mxh = i2c_read_byte(); unsigned char mxl = i2c_read_byte(); unsigned char myh = i2c_read_byte(); unsigned char myl = i2c_read_byte(); unsigned char mzh = i2c_read_byte(); unsigned char mzl = i2c_read_last_byte(); i2c_stop(); a->x = axh << 8 | axl; a->y = ayh << 8 | ayl; a->z = azh << 8 | azl; m->x = mxh << 8 | mxl; m->y = myh << 8 | myl; m->z = mzh << 8 | mzl; } // Returns a set of acceleration and adjusted magnetic readings from the cmp01a. void read_data(vector *a, vector *m) { read_data_raw(a, m); // shift and scale m->x = (m->x - m_min.x) / (m_max.x - m_min.x) * 2 - 1.0; m->y = (m->y - m_min.y) / (m_max.y - m_min.y) * 2 - 1.0; m->z = (m->z - m_min.z) / (m_max.z - m_min.z) * 2 - 1.0; } ... read_data_raw(&a, &m); if (m.x < cal_m_min.x) cal_m_min.x = m.x if (m.x > cal_m_max.x) cal_m_max.x = m.x; if (m.y < cal_m_min.y) cal_m_min.y = m.y; if (m.y > cal_m_max.y) cal_m_max.y = m.y; if (m.z < cal_m_min.z) cal_m_min.z = m.z; if (m.z > cal_m_max.z) cal_m_max.z = m.z;
Nach dem Kalibrieren verwende ich natürlich die read_data Methode sonst würde das Kalibrieren nichts bringen.







Zitieren
Lesezeichen