Michael Ernst Peter / Mbed OS Test_GPS

Dependencies:   Eigen

Revision:
71:4bc51407bff0
Parent:
69:2cda20c51989
--- a/NEOM9N_thread.h	Thu Jun 16 14:03:22 2022 +0200
+++ b/NEOM9N_thread.h	Sat Jun 18 18:36:19 2022 +0200
@@ -5,6 +5,7 @@
 
 #include "Eigen/Dense.h"
 #include "ThreadFlag.h"
+//#include "data_structs.h"
 
 /**
  * notes:
@@ -42,76 +43,77 @@
 #define UBX_PVT_CLASS     0x01
 #define UBX_PVT_ID        0x07
 
+//extern DATA_Xchange data;
+//extern Timer global_timer;
+
 class NEOM9N
-{   
-    public:
-        NEOM9N(PinName TX, PinName RX);
-        virtual ~NEOM9N();
+{
+public:
+    NEOM9N(PinName TX, PinName RX);
+    virtual ~NEOM9N();
 
-        typedef struct ubxNavPVT_s {
-            uint32_t iTOW;    //  0  -   ms   GPS time of week of the navigation epoch
-            uint16_t year;    //  4  -    -   Year (UTC)
-            uint8_t month;    //  6  -    -   Month, range 1..12 (UTC)
-            uint8_t day;      //  7  -    -   Day of month, range 1..31 (UTC)
-            uint8_t hour;     //  8  -    -   Hour of day, range 0..23 (UTC)
-            uint8_t min;      //  9  -    -   Minute of hour, range 0..59 (UTC)
-            uint8_t sec;      // 10  -    -   Seconds of minute, range 0..60 (UTC)
-            uint8_t fixType;  // 20  -    -   GNSSfix Type
-            uint8_t numSV;    // 23  -    -   Number of satellites used in Nav Solution
-            int32_t lon;      // 24 1e-7 deg  Longitude
-            int32_t lat;      // 28 1e-7 deg  Latitude
-            int32_t height;   // 32  -   mm   Height above ellipsoid
-            uint32_t hAcc;    // 40  -   mm   Horizontal accuracy estimate
-            uint32_t vAcc;    // 44  -   mm   Vertical accuracy estimate
-            int32_t velN;     // 48  -   mm/s NED north velocity
-            int32_t velE;     // 52  -   mm/s NED east velocity
-            int32_t velD;     // 56  -   mm/s NED down velocity
-            int32_t gSpeed;   // 60  -   mm/s Ground Speed (2-D)
-            int32_t headMot;  // 64 1e-5 deg  Heading of motion (2-D)
-            uint32_t sAcc;    // 68 -    mm/s Speed accuracy estimate
-            uint32_t headAcc; // 72 1e-5 deg  Heading accuracy estimate (both motion and vehicle)
-            //int16_t magDec;   // 88 1e-2 deg  Magnetic declination.
-            //uint16_t magAcc;  // 90 1e-2 deg  Magnetic declination accuracy
-        } ubxNavPVT_t;
+    typedef struct ubxNavPVT_s {
+        uint32_t iTOW;    //  0  -   ms   GPS time of week of the navigation epoch
+        uint16_t year;    //  4  -    -   Year (UTC)
+        uint8_t month;    //  6  -    -   Month, range 1..12 (UTC)
+        uint8_t day;      //  7  -    -   Day of month, range 1..31 (UTC)
+        uint8_t hour;     //  8  -    -   Hour of day, range 0..23 (UTC)
+        uint8_t min;      //  9  -    -   Minute of hour, range 0..59 (UTC)
+        uint8_t sec;      // 10  -    -   Seconds of minute, range 0..60 (UTC)
+        uint8_t fixType;  // 20  -    -   GNSSfix Type
+        uint8_t numSV;    // 23  -    -   Number of satellites used in Nav Solution
+        int32_t lon;      // 24 1e-7 deg  Longitude
+        int32_t lat;      // 28 1e-7 deg  Latitude
+        int32_t height;   // 32  -   mm   Height above ellipsoid
+        uint32_t hAcc;    // 40  -   mm   Horizontal accuracy estimate
+        uint32_t vAcc;    // 44  -   mm   Vertical accuracy estimate
+        int32_t velN;     // 48  -   mm/s NED north velocity
+        int32_t velE;     // 52  -   mm/s NED east velocity
+        int32_t velD;     // 56  -   mm/s NED down velocity
+        int32_t gSpeed;   // 60  -   mm/s Ground Speed (2-D)
+        int32_t headMot;  // 64 1e-5 deg  Heading of motion (2-D)
+        uint32_t sAcc;    // 68 -    mm/s Speed accuracy estimate
+        uint32_t headAcc; // 72 1e-5 deg  Heading accuracy estimate (both motion and vehicle)
+        //int16_t magDec;   // 88 1e-2 deg  Magnetic declination.
+        //uint16_t magAcc;  // 90 1e-2 deg  Magnetic declination accuracy
+    } ubxNavPVT_t;
 
-        void StartThread();
-        void ZeroLocal();
-        ubxNavPVT_t GetUbxNavPVT();
-        bool CheckAndToggleHasNewData();
-        Eigen::Vector3f GetPosECEF();
-        Eigen::Vector3f GetPosENU();
-        Eigen::Vector3f GetVelENU();
-        uint8_t GetFixType();
-        uint8_t GetNumSV();
-        uint8_t GetGPSTimeOfWeek();
-        float GetHeadMot();
-        float GetHeadAcc();
-        float GethAcc();
-        float GetvAcc();
-        float GetsAcc();
+    void start_loop();
+    void reset_local();
+    ubxNavPVT_t GetUbxNavPVT();
+    Eigen::Vector3f GetPosECEF();
+    Eigen::Vector3f GetPosENU();
+    Eigen::Vector3f GetVelENU();
+    uint8_t GetFixType();
+    uint8_t GetNumSV();
+    uint8_t GetGPSTimeOfWeek();
+    float GetHeadMot();
+    float GetHeadAcc();
+    float GethAcc();
+    float GetvAcc();
+    float GetsAcc();
 
-    private:
-        float m_Ts;
-        BufferedSerial m_bufferedSerial;
-        bool m_has_new_data = false;
-        ubxNavPVT_t m_ubxNavPVT;
+private:
+    float m_Ts = 0.005f; // GNSS runs at 25 Hz := 0.04 sec, make sure that modulo(0.04 / m_Ts) = 0 e.g. m_Ts = 0.02, 0.01, 0.005
+    BufferedSerial m_bufferedSerial;
+    ubxNavPVT_t m_ubxNavPVT;
 #if PRINT_FOR_DEBUG
-        Timer m_run_timer;
+    Timer m_run_timer;
 #endif
-        Eigen::Vector3d m_pos_ecef_0;
-        Eigen::Vector3d m_pos_ecef;
-        Eigen::Vector3d m_pos_enu;
-        Eigen::Matrix3d m_R_ecefToLocal_0;
+    Eigen::Vector3d m_pos_ecef_0;
+    Eigen::Vector3d m_pos_ecef;
+    Eigen::Vector3d m_pos_enu;
+    Eigen::Matrix3d m_R_ecefToLocal_0;
 
-        ThreadFlag threadFlag;
-        Thread thread;
-        Ticker ticker;
+    ThreadFlag threadFlag;
+    Thread thread;
+    Ticker ticker;
 
-        void update();
-        Eigen::Vector3d transformWGS84ToECEF(const ubxNavPVT_t& ubxNavPVT);
-        Eigen::Matrix3d getR_ECEFToLocal(const ubxNavPVT_t& ubxNavPVT);
-        ubxNavPVT_t decodeUbxNavPVTmsg(const char *buf);
-        void sendThreadFlag();
+    void update();
+    Eigen::Vector3d transformWGS84ToECEF(const ubxNavPVT_t& ubxNavPVT);
+    Eigen::Matrix3d getR_ECEFToLocal(const ubxNavPVT_t& ubxNavPVT);
+    ubxNavPVT_t decodeUbxNavPVTmsg(const char *buf);
+    void sendThreadFlag();
 };
 
 #endif /* NEOM9N_THREAD_H */