Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
NEOM9N_thread.h@66:4057e8e5c248, 2022-06-09 (annotated)
- Committer:
- pmic
- Date:
- Thu Jun 09 13:14:26 2022 +0200
- Revision:
- 66:4057e8e5c248
- Parent:
- 62:c9571e4d9005
- Child:
- 67:1cac5dca9045
Final checks before testing, did not manage to use checksum, just leave it for now
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 62:c9571e4d9005 | 1 | #ifndef NEOM9N_THREAD_H |
pmic | 62:c9571e4d9005 | 2 | #define NEOM9N_THREAD_H |
pmic | 62:c9571e4d9005 | 3 | |
pmic | 62:c9571e4d9005 | 4 | #include <mbed.h> |
pmic | 62:c9571e4d9005 | 5 | |
pmic | 62:c9571e4d9005 | 6 | #include "Eigen/Dense.h" |
pmic | 62:c9571e4d9005 | 7 | #include "ThreadFlag.h" |
pmic | 62:c9571e4d9005 | 8 | |
pmic | 62:c9571e4d9005 | 9 | /** |
pmic | 62:c9571e4d9005 | 10 | * notes: |
pmic | 62:c9571e4d9005 | 11 | * - you need to configure neo-m9n unit according to one note notes. basically flash 20220602_M9N_config_00.txt via u-center and save |
pmic | 62:c9571e4d9005 | 12 | * - unit runs at 25 Hz, do not readout faster than the set update rate (config above) |
pmic | 62:c9571e4d9005 | 13 | */ |
pmic | 62:c9571e4d9005 | 14 | |
pmic | 62:c9571e4d9005 | 15 | #define PRINT_FOR_DEBUG false |
pmic | 62:c9571e4d9005 | 16 | |
pmic | 62:c9571e4d9005 | 17 | #define M_PI 3.14159265358979323846 |
pmic | 62:c9571e4d9005 | 18 | |
pmic | 62:c9571e4d9005 | 19 | #define UBX_PAYLOAD_INDEX 2 |
pmic | 62:c9571e4d9005 | 20 | #define UBX_PVT_HEADER_0 0xb5 |
pmic | 62:c9571e4d9005 | 21 | #define UBX_PVT_HEADER_1 0x62 |
pmic | 62:c9571e4d9005 | 22 | #define UBX_PVT_CLASS 0x01 |
pmic | 62:c9571e4d9005 | 23 | #define UBX_PVT_ID 0x07 |
pmic | 62:c9571e4d9005 | 24 | |
pmic | 62:c9571e4d9005 | 25 | class NEOM9N |
pmic | 62:c9571e4d9005 | 26 | { |
pmic | 62:c9571e4d9005 | 27 | public: |
pmic | 66:4057e8e5c248 | 28 | NEOM9N(PinName TX, PinName RX); |
pmic | 62:c9571e4d9005 | 29 | virtual ~NEOM9N(); |
pmic | 62:c9571e4d9005 | 30 | |
pmic | 62:c9571e4d9005 | 31 | typedef struct ubxNavPVT_s { |
pmic | 62:c9571e4d9005 | 32 | uint8_t fixType; // 20 - - GNSSfix Type |
pmic | 62:c9571e4d9005 | 33 | uint8_t numSV; // 23 - - Number of satellites used in Nav Solution |
pmic | 62:c9571e4d9005 | 34 | int32_t lon; // 24 1e-7 deg Longitude |
pmic | 62:c9571e4d9005 | 35 | int32_t lat; // 28 1e-7 deg Latitude |
pmic | 62:c9571e4d9005 | 36 | int32_t height; // 32 - mm Height above ellipsoid |
pmic | 62:c9571e4d9005 | 37 | uint32_t hAcc; // 40 - mm Horizontal accuracy estimate |
pmic | 62:c9571e4d9005 | 38 | uint32_t vAcc; // 44 - mm Vertical accuracy estimate |
pmic | 62:c9571e4d9005 | 39 | int32_t velN; // 48 - mm/s NED north velocity |
pmic | 62:c9571e4d9005 | 40 | int32_t velE; // 52 - mm/s NED east velocity |
pmic | 62:c9571e4d9005 | 41 | int32_t velD; // 56 - mm/s NED down velocity |
pmic | 62:c9571e4d9005 | 42 | int32_t gSpeed; // 60 - mm/s Ground Speed (2-D) |
pmic | 62:c9571e4d9005 | 43 | int32_t headMot; // 64 1e-5 deg Heading of motion (2-D) |
pmic | 62:c9571e4d9005 | 44 | uint32_t sAcc; // 68 - mm/s Speed accuracy estimate |
pmic | 62:c9571e4d9005 | 45 | uint32_t headAcc; // 72 1e-5 deg Heading accuracy estimate (both motion and vehicle) |
pmic | 66:4057e8e5c248 | 46 | //int16_t magDec; // 88 1e-2 deg Magnetic declination. |
pmic | 66:4057e8e5c248 | 47 | //uint16_t magAcc; // 90 1e-2 deg Magnetic declination accuracy |
pmic | 62:c9571e4d9005 | 48 | } ubxNavPVT_t; |
pmic | 62:c9571e4d9005 | 49 | |
pmic | 62:c9571e4d9005 | 50 | void StartThread(); |
pmic | 62:c9571e4d9005 | 51 | void ZeroLocal(); |
pmic | 62:c9571e4d9005 | 52 | ubxNavPVT_t GetUbxNavPVT(); |
pmic | 66:4057e8e5c248 | 53 | bool CheckAndToggleHasNewData(); |
pmic | 62:c9571e4d9005 | 54 | Eigen::Vector3f GetPosECEF(); |
pmic | 62:c9571e4d9005 | 55 | Eigen::Vector3f GetPosENU(); |
pmic | 62:c9571e4d9005 | 56 | Eigen::Vector3f GetVelENU(); |
pmic | 62:c9571e4d9005 | 57 | uint8_t GetFixType(); |
pmic | 62:c9571e4d9005 | 58 | uint8_t GetNumSV(); |
pmic | 62:c9571e4d9005 | 59 | |
pmic | 62:c9571e4d9005 | 60 | private: |
pmic | 62:c9571e4d9005 | 61 | float m_Ts; |
pmic | 62:c9571e4d9005 | 62 | BufferedSerial m_bufferedSerial; |
pmic | 62:c9571e4d9005 | 63 | bool m_has_fix = false; |
pmic | 66:4057e8e5c248 | 64 | bool m_has_new_data = false; |
pmic | 62:c9571e4d9005 | 65 | ubxNavPVT_t m_ubxNavPVT; |
pmic | 62:c9571e4d9005 | 66 | #if PRINT_FOR_DEBUG |
pmic | 62:c9571e4d9005 | 67 | Timer m_run_timer; |
pmic | 62:c9571e4d9005 | 68 | #endif |
pmic | 62:c9571e4d9005 | 69 | Eigen::Vector3d m_pos_ecef_0; |
pmic | 62:c9571e4d9005 | 70 | Eigen::Matrix3d m_R_ecefToLocal_0; |
pmic | 62:c9571e4d9005 | 71 | |
pmic | 62:c9571e4d9005 | 72 | ThreadFlag threadFlag; |
pmic | 62:c9571e4d9005 | 73 | Thread thread; |
pmic | 62:c9571e4d9005 | 74 | Ticker ticker; |
pmic | 62:c9571e4d9005 | 75 | |
pmic | 62:c9571e4d9005 | 76 | void update(); |
pmic | 62:c9571e4d9005 | 77 | Eigen::Vector3d transformWGS84ToECEF(const ubxNavPVT_t& ubxNavPVT); |
pmic | 62:c9571e4d9005 | 78 | Eigen::Matrix3d getR_ECEFToLocal(const ubxNavPVT_t& ubxNavPVT); |
pmic | 62:c9571e4d9005 | 79 | ubxNavPVT_t decodeUbxNavPVTmsg(const char *buf); |
pmic | 62:c9571e4d9005 | 80 | void sendThreadFlag(); |
pmic | 62:c9571e4d9005 | 81 | }; |
pmic | 62:c9571e4d9005 | 82 | |
pmic | 62:c9571e4d9005 | 83 | #endif /* NEOM9N_THREAD_H */ |
pmic | 62:c9571e4d9005 | 84 |