回避行動用のプログラムです。
Dependencies: ATP3012 mbed a HMC US015_2 getGPS
Revision 1:f70beec382b6, committed 2021-12-03
- Comitter:
- ushiroji
- Date:
- Fri Dec 03 08:22:57 2021 +0000
- Parent:
- 0:99f4fe3e21c6
- Commit message:
- first version
Changed in this revision
Function.h | 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 99f4fe3e21c6 -r f70beec382b6 Function.h --- a/Function.h Wed Dec 01 08:14:01 2021 +0000 +++ b/Function.h Fri Dec 03 08:22:57 2021 +0000 @@ -116,7 +116,6 @@ delta = angle - theta; } printf("delta=%f-%f=%f\r\n", angle, theta, delta); - wait(2); return delta; } @@ -124,13 +123,14 @@ { xbee.printf("calibration start\r\n"); compass.setCalibrationMode(0x43); - Move('4', 0.1); + Move('4', 0.15); xbee.printf("mortor mode:4 speed:0.1\n\r"); - wait(6); + wait(180); Move('1', 0); xbee.printf("mortor mode:1 speed:0\n\r"); compass.setCalibrationMode(0x45); xbee.printf("calibration end\r\n"); +/* while(1) { if(gps.getgps()) { //現在地取得 GPS_x = gps.latitude; @@ -142,7 +142,7 @@ break; } } - +*/ return; }
diff -r 99f4fe3e21c6 -r f70beec382b6 main.cpp --- a/main.cpp Wed Dec 01 08:14:01 2021 +0000 +++ b/main.cpp Fri Dec 03 08:22:57 2021 +0000 @@ -3,17 +3,29 @@ #include "Function.h" int main() { - while(1) { - Move('2', 0.3); - while(FrontGet()) { - xbee.printf("front get\n\r"); - Move('1', 0); //停止 - xbee.printf("mortor mode:1 speed:0\n\r"); - Move('4', 0.3); //時計回り回転 - xbee.printf("mortor mode:4 speed:0.5\n\r"); - wait(1); - Move('1', 0); //回転停止 - xbee.printf("mortor mode:1 speed:0\n\r"); + double angle = 0; + + Calibration(); + + compass.setOpMode(HMC6352_CONTINUOUS, 1, 20); + angle = compass.sample() / 10; + xbee.printf("%f\r\n", angle); + + //角度調節 + while(1) { + if(angle < 20 || angle > 340) { //角度判定 + xbee.printf("direction finish\n\r"); + Move('1', 0); //停止 + wait(5); + compass.setOpMode(HMC6352_CONTINUOUS, 1, 20); + angle = compass.sample() / 10; + xbee.printf("%f\r\n", angle); + } + else { + Move('4', 0.15);//時計回りに回転 + compass.setOpMode(HMC6352_CONTINUOUS, 1, 20); + angle = compass.sample() / 10; + xbee.printf("%f\r\n", angle); + } } - } -} +} \ No newline at end of file