調整中
Dependencies: mbed HMC6352 US015 TB6612FNG2 getGPS ATP3011
AngleGet.h@13:38c5ffe5873a, 2021-10-27 (annotated)
- Committer:
- user_
- Date:
- Wed Oct 27 06:47:49 2021 +0000
- Revision:
- 13:38c5ffe5873a
- Parent:
- 9:9221ef8d36a8
test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ushiroji | 3:74d0faefdd78 | 1 | #include "HMC6352.h" |
ushiroji | 3:74d0faefdd78 | 2 | #include "math.h" |
ushiroji | 3:74d0faefdd78 | 3 | #include "getGPS.h" |
user_ | 9:9221ef8d36a8 | 4 | //#include <math.h> |
ushiroji | 3:74d0faefdd78 | 5 | |
user_ | 9:9221ef8d36a8 | 6 | #define M_PI 3.14 // とりあえず円周率を定義 |
user_ | 9:9221ef8d36a8 | 7 | |
user_ | 9:9221ef8d36a8 | 8 | Serial pc(USBTX, USBRX); |
ushiroji | 3:74d0faefdd78 | 9 | HMC6352 compass(D4, D5); |
ushiroji | 3:74d0faefdd78 | 10 | GPS gps(D1, D0); |
ushiroji | 3:74d0faefdd78 | 11 | |
ushiroji | 3:74d0faefdd78 | 12 | int AngleGet() { |
ushiroji | 3:74d0faefdd78 | 13 | while(1) { |
ushiroji | 3:74d0faefdd78 | 14 | double angle; |
ushiroji | 3:74d0faefdd78 | 15 | compass.setOpMode(HMC6352_CONTINUOUS, 1, 20); |
ushiroji | 3:74d0faefdd78 | 16 | angle = compass.sample() / 10; |
ushiroji | 3:74d0faefdd78 | 17 | |
ushiroji | 3:74d0faefdd78 | 18 | double next_x; |
ushiroji | 3:74d0faefdd78 | 19 | double next_y; |
ushiroji | 3:74d0faefdd78 | 20 | double theta; |
ushiroji | 3:74d0faefdd78 | 21 | double delta; |
ushiroji | 3:74d0faefdd78 | 22 | //if(gps.getgps()) { |
ushiroji | 3:74d0faefdd78 | 23 | pc.printf("%lf %lf\r\n", 0, 0); //gps.latitude=0, gps.longitude=0 |
ushiroji | 3:74d0faefdd78 | 24 | next_x = 30; |
ushiroji | 3:74d0faefdd78 | 25 | next_y = 30; |
ushiroji | 3:74d0faefdd78 | 26 | theta = atan(next_x - 0 / next_y - 0) * 180 / M_PI; |
ushiroji | 3:74d0faefdd78 | 27 | printf("%f", theta); |
ushiroji | 3:74d0faefdd78 | 28 | delta = theta - angle; |
ushiroji | 3:74d0faefdd78 | 29 | printf("%f-%f=%f\r\n", theta, angle, delta); |
ushiroji | 3:74d0faefdd78 | 30 | //} |
ushiroji | 3:74d0faefdd78 | 31 | /* |
ushiroji | 3:74d0faefdd78 | 32 | else { |
ushiroji | 3:74d0faefdd78 | 33 | pc.printf("No data\r\n");//データ取得に失敗した場合 |
ushiroji | 3:74d0faefdd78 | 34 | wait(1); |
ushiroji | 3:74d0faefdd78 | 35 | } |
ushiroji | 3:74d0faefdd78 | 36 | */ |
ushiroji | 3:74d0faefdd78 | 37 | wait(2); |
ushiroji | 3:74d0faefdd78 | 38 | } |
ushiroji | 3:74d0faefdd78 | 39 | } |