2018/3/9 s240メインプログラム用
Fork of HMC5883L by
Revision 5:17a459680d5f, committed 2018-03-09
- Comitter:
- basyo38
- Date:
- Fri Mar 09 11:12:47 2018 +0000
- Parent:
- 4:bc4e1201e092
- Commit message:
- 2018/3/9
Changed in this revision
HMC5883L.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HMC5883L.cpp Tue Nov 06 17:35:51 2012 +0000 +++ b/HMC5883L.cpp Fri Mar 09 11:12:47 2018 +0000 @@ -85,7 +85,7 @@ char HMC5883L::getConfigurationB() { char cmd[2]; - cmd[0] = CONFIG_A_REG; // register b address + cmd[0] = CONFIG_B_REG; // register b address i2c_.write(I2C_ADDRESS, cmd, 1, true); i2c_.read(I2C_ADDRESS, &cmd[1], 1, false); return cmd[1]; @@ -126,14 +126,14 @@ i2c_.read(I2C_ADDRESS, data, 6, false); for(int i = 0; i < 3; i++) // fill the output variables - output[i] = int16_t(((unsigned char)data[i*2] << 8) | (unsigned char)data[i*2+1]); + output[i] = int16_t(((unsigned char)data[i*2] << 8) | (unsigned char)data[i*2+1]);//最上位ビットMSB|最下位ビットLSB } double HMC5883L::getHeadingXY() { int16_t raw_data[3]; getXYZ(raw_data); - double heading = atan2(static_cast<double>(raw_data[1]), static_cast<double>(raw_data[0])); // heading = arctan(Y/X) + double heading = atan2(static_cast<double>(raw_data[2]), static_cast<double>(raw_data[0])); // heading = arctan(Y/X) // TODO: declenation angle compensation