s-240のTP(テストピース)用。機首方向の方位を取得することを目的とする。

Dependencies:   HMC5883L mbed

Fork of hmc5883l_test by Yoshitaka Takeuchi

Files at this revision

API Documentation at this revision

Comitter:
Joeatsumi
Date:
Sun Sep 03 12:33:36 2017 +0000
Parent:
0:e1b4cdf08086
Commit message:
???HMC5883?DIP?????????360?????????; ??????????TeraTeam???????????

Changed in this revision

HMC5883L.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e1b4cdf08086 -r f4dcabafa985 HMC5883L.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HMC5883L.lib	Sun Sep 03 12:33:36 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/Joeatsumi/code/HMC5883L/#52ffe160f17f
diff -r e1b4cdf08086 -r f4dcabafa985 main.cpp
--- a/main.cpp	Wed Dec 04 08:19:12 2013 +0000
+++ b/main.cpp	Sun Sep 03 12:33:36 2017 +0000
@@ -1,105 +1,20 @@
 #include "mbed.h"
-#define wt 0.1
-
-I2C i2c(p9, p10);        // sda, scl
-Serial pc(USBTX, USBRX); 
-
-
-#define addr 0x3c
-char cmd[2];
-
-
-
-void init_compass(){
-
-    cmd[0] = 0x02;
-    cmd[1] = 0x00;
-    i2c.write(addr, cmd, 2);
-}
+#include "HMC5883L.h"
 
-long int x_get() {
-    char data[1];
-    //char cmd[2];
-    int data_buff[2];
-    short int buff;
-    
-    
-    cmd[0] = 0x03;
-    i2c.write(addr, cmd, 1);
-    wait(wt);
-    i2c.read(addr, data,1);
-    data_buff[0] = data[0];
-    wait(wt);
-    
-    cmd[0] = 0x04;
-    i2c.write(addr, cmd, 1);
-    wait(wt);
-    i2c.read(addr, data, 1);
-    data_buff[1] = data[0];
-    
-    buff = data_buff[0] << 8;
-    buff = data_buff[1] | buff; 
-    /* if (buff & 0x00 == 0xff00){
-        buff = buff - 0x80;
-        buff = buff * -1;
-    }*/
-    return buff;
-}
+//秋葉原の秋月電子で買ったHMC5883LのDIP化センサー(600円くらい)をLPC1768で試した。
+//センサー裏を半田で結線(SDL,SDAをプルアップ)しないと動作しない。
+//これに気が付かないで芭蕉と2人で1日中悩んだ(笑)
+
+//琵琶湖で飛行している際、3kmを超えるとに目標物が見当たらないので、この方位センサーを用いて
+//パイロットに機首方向を教えることを想定している。
 
-long int z_get() {
-    char data[1];
-    int data_buff[2];
-    short int buff;
-    
-    
-    cmd[0] = 0x05;
-    i2c.write(addr, cmd, 1);
-    wait(wt);
-    i2c.read(addr, data,1);
-    data_buff[0] = data[0];
-    wait(wt);
-    
-    cmd[0] = 0x06;
-    i2c.write(addr, cmd, 1);
-    wait(wt);
-    i2c.read(addr, data, 1);
-    data_buff[1] = data[0];
-    
-    buff = data_buff[0] << 8;
-    buff = data_buff[1] | buff;
-
-    return buff;
-}
-
-long int y_get() {
-    char data[1];
-    char data_buff[2];
-    short int buff;
-    
-    
-    cmd[0] = 0x07;
-    i2c.write(addr, cmd, 1);
-    wait(wt);
-    i2c.read(addr, data,1);
-    data_buff[0] = data[0];
-    wait(wt);
-    
-    cmd[0] = 0x08;
-    i2c.write(addr, cmd, 1);
-    wait(wt);
-    i2c.read(addr, data, 1);
-    data_buff[1] = data[0];
-    
-    buff = data_buff[0] << 8;
-    buff = data_buff[1] | buff;    
-
-    return buff;
-}
-         
+Serial pc(USBTX, USBRX); 
+HMC5883L compass(p28, p27);
+ 
 int main() {
-init_compass();
+    compass.init();
     while(1) {
-        pc.printf("%d/ %d/ %d\r\n", x_get(), y_get(), z_get());
-        wait(0);
-    }
+        pc.printf("raw=%f\r\n",compass.getHeadingXYDeg());
+        wait(0.2);
+     }
 }
\ No newline at end of file