回避行動用のプログラムです。
Dependencies: ATP3012 mbed a HMC US015_2 getGPS
Diff: main.cpp
- Revision:
- 1:f70beec382b6
- Parent:
- 0:99f4fe3e21c6
--- 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