![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
四轴
Dependencies: BufferedSerial SoftPWM mbed send
Fork of send_copy by
JY901.h@5:683542d82dd7, 2017-12-10 (annotated)
- Committer:
- accelerator225
- Date:
- Sun Dec 10 02:19:41 2017 +0000
- Revision:
- 5:683542d82dd7
- Parent:
- 4:876bfa91934c
??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
accelerator225 | 4:876bfa91934c | 1 | #include "mbed.h" |
accelerator225 | 5:683542d82dd7 | 2 | #include "BufferedSerial.h"//波特率在这个头文件中改 |
accelerator225 | 4:876bfa91934c | 3 | class JY901 |
accelerator225 | 4:876bfa91934c | 4 | { |
accelerator225 | 4:876bfa91934c | 5 | int state, token, payloadLen, recvLen; |
accelerator225 | 4:876bfa91934c | 6 | unsigned char payloadBuf[16]; |
accelerator225 | 4:876bfa91934c | 7 | protected: |
accelerator225 | 5:683542d82dd7 | 8 | BufferedSerial mod; |
accelerator225 | 4:876bfa91934c | 9 | float acc[3], gyo[3], mag[3], att[3]; |
accelerator225 | 4:876bfa91934c | 10 | void parseCmpt(int token, unsigned char* payloadBuf, int payloadLen); |
accelerator225 | 4:876bfa91934c | 11 | void parseInput(const char* data, int len); |
accelerator225 | 4:876bfa91934c | 12 | public: |
accelerator225 | 5:683542d82dd7 | 13 | JY901(PinName TX, PinName RX) : mod(TX, RX){} |
accelerator225 | 4:876bfa91934c | 14 | ~JY901() {} |
accelerator225 | 4:876bfa91934c | 15 | void receiveData(); |
accelerator225 | 4:876bfa91934c | 16 | void getAcc(float &x, float &y, float &z){ |
accelerator225 | 4:876bfa91934c | 17 | x = acc[0]; |
accelerator225 | 4:876bfa91934c | 18 | y = acc[1]; |
accelerator225 | 4:876bfa91934c | 19 | z = acc[2]; |
accelerator225 | 4:876bfa91934c | 20 | } |
accelerator225 | 4:876bfa91934c | 21 | void getGyo(float &x, float &y, float &z){ |
accelerator225 | 4:876bfa91934c | 22 | x = gyo[0]; |
accelerator225 | 4:876bfa91934c | 23 | y = gyo[1]; |
accelerator225 | 4:876bfa91934c | 24 | z = gyo[2]; |
accelerator225 | 4:876bfa91934c | 25 | } |
accelerator225 | 4:876bfa91934c | 26 | void getMag(float &x, float &y, float &z){ |
accelerator225 | 4:876bfa91934c | 27 | x = mag[0]; |
accelerator225 | 4:876bfa91934c | 28 | y = mag[1]; |
accelerator225 | 4:876bfa91934c | 29 | z = mag[2]; |
accelerator225 | 4:876bfa91934c | 30 | } |
accelerator225 | 4:876bfa91934c | 31 | void getAttitude(float &roll, float &pitch, float &yaw){ |
accelerator225 | 4:876bfa91934c | 32 | roll = att[0]; |
accelerator225 | 4:876bfa91934c | 33 | pitch = att[1]; |
accelerator225 | 4:876bfa91934c | 34 | yaw = att[2]; |
accelerator225 | 4:876bfa91934c | 35 | } |
accelerator225 | 4:876bfa91934c | 36 | }; |