Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 9:fb19a93df88f
- Parent:
- 8:d41f5d7d2aa5
- Child:
- 10:280a25bcc8bb
--- a/main.cpp Wed Oct 24 09:08:53 2018 +0000 +++ b/main.cpp Fri Oct 26 07:04:55 2018 +0000 @@ -5,10 +5,13 @@ #include "HMC5883L.h" #include "MPU6050.h" -MPU6050 mpu(p9,p10);//(SDA,SCL)のピンをアサインしてね☆ 加速度センサー Serial pc(USBTX, USBRX); //地磁気センサー,GPS -HMC5883L compass(p28, p27); +GPS gps(p28, p27); //GPS +HMC5883L compass(p9, p10); //地磁気センサー + +MPU6050 mpu(p9,p10); //(SDA,SCL)のピンをアサインしてね☆ 加速度センサー + DigitalOut FET(p21); //FET @@ -18,7 +21,6 @@ //何もないつまりスリットの部分ではローの0を返す。それを変数testに代入している DigitalIn test2(p18); -GPS gps(p28, p27); //GPS Motor motor1(p22, p16, p17, 1); // pwm, fwd, rev, can brake モーター Motor motor2(p22, p19, p20, 1); // pwm, fwd, rev, can brake @@ -49,13 +51,13 @@ motor1.stop(0); motor2.stop(0); - + printf("GPS start\r\n"); FILE *fp = fopen("/local/gps.txt", "w"); // Open "gps.txt" on the local file system for writing fprintf(fp, "GPS Start\r\n"); int n; for(n=0;n<45;n++) //GPSの取得を45回行う(これで大体1分半) { - + printf("gps for\r\n"); if(gps.getgps()) //現在地取得 fprintf(fp,"(%lf, %lf)\r\n", gps.latitude, gps.longitude);//緯度と経度を出力 @@ -69,11 +71,18 @@ } fprintf(fp,"GPS finish\r\n"); fclose(fp); //GPSの測定終了 - + + - compass.init(); //地磁気センサー動作 - pc.printf("raw=%f\r\n",compass.getHeadingXYDeg()); /*度数法で表記*/ - + + compass.init(); //地磁気センサー動作 + + int i; + for(i=0;i<20;i++) //地磁気測定 + { + pc.printf("raw=%f\r\n",compass.getHeadingXYDeg()); //度数法で表記 + wait(0.5); + } mu.startUpdates();//start mesuring the distance(超音波センサー) int distance; @@ -85,13 +94,14 @@ float leftrun2; rightrun=0.0; leftrun2=0.0; + + float accel[3];//accelを3つの配列で定義。 加速度センサー while(1) { distance=mu.getCurrentDistance(); printf("%d\r\n",distance); - float accel[3];//accelを3つの配列で定義。 加速度センサー mpu.readAccelData(accel);//加速度の値をaccel[3]に代入 float x = accel[0]/16384;//x軸方向の加速度 float y = accel[1]/16384;//y軸方向の加速度 @@ -132,7 +142,7 @@ // mu.checkDistance(); //call checkDistance() as much as possible, as this is where //the class checks if dist needs to be called. - wait(0.2); + wait(0.01); if(100 < distance && distance < 500) //障害物発見❕ {