受信割り込みバージョン
Dependents: a_team_R1370 ashimawari_sample_test 2022NHK_A_ashimawari 2022A_NHK_kikou
Revision 5:553c02009ad0, committed 2020-12-16
- Comitter:
- highfieldsnj
- Date:
- Wed Dec 16 08:31:38 2020 +0000
- Parent:
- 4:ffc2a55269f9
- Commit message:
- add functions reset
Changed in this revision
R1370.cpp | Show annotated file Show diff for this revision Revisions of this file |
R1370.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r ffc2a55269f9 -r 553c02009ad0 R1370.cpp --- a/R1370.cpp Sat May 18 08:42:05 2019 +0000 +++ b/R1370.cpp Wed Dec 16 08:31:38 2020 +0000 @@ -2,6 +2,7 @@ R1370::R1370(PinName tx, PinName rx) : RawSerial(tx, rx, 115200) { + zeroPoint = 0; attach(callback(this, &R1370::receiveByte)); } @@ -61,6 +62,17 @@ return (float)(angle / 100.0); } +float R1370::getRelativeAngle() +{ + relativeAngle = (float)((angle - zeroPoint) / 100.0); + if(relativeAngle > 180.0){ + return relativeAngle - 360.0; + }else if(relativeAngle < -180.0){ + return relativeAngle + 360.0; + } + return relativeAngle; +} + float R1370::getRate() { return (float)(rate / 100.0); @@ -71,6 +83,11 @@ return (float)(angle / 100.0 / 180.0 * 3.141592653589793); } +float R1370::getRelativeRadian() +{ + return getRelativeAngle() / 180.0 * 3.141592653589793; +} + int16_t R1370::getAcc(char l) { if(l == 'x' || l == 'X') { @@ -116,4 +133,9 @@ unsigned char R1370::downbit() { return downbit_; +} + +void R1370::reset() +{ + zeroPoint = angle; } \ No newline at end of file
diff -r ffc2a55269f9 -r 553c02009ad0 R1370.h --- a/R1370.h Sat May 18 08:42:05 2019 +0000 +++ b/R1370.h Wed Dec 16 08:31:38 2020 +0000 @@ -14,13 +14,16 @@ R1370(PinName tx, PinName rx); float getAngle(); + float getRelativeAngle(); float getRate(); float getRadian(); + float getRelativeRadian(); int16_t getAcc(char l); int16_t getAcc(int i); int16_t getAccX(); int16_t getAccY(); int16_t getAccZ(); + void reset(); unsigned char upbit(); unsigned char downbit(); @@ -41,6 +44,8 @@ uint8_t data[R1370_BUFFER_SIZE-3]; uint8_t bufferPoint; uint8_t receivedBytes; + int16_t zeroPoint; + float relativeAngle; unsigned char upbit_, downbit_; };