Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_GPS/AP_GPS_ERB.h
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415//16// Emlid Reach Binary (ERB) GPS driver for ArduPilot.17// ERB protocol: http://files.emlid.com/ERB.pdf1819#pragma once2021#include "AP_GPS.h"22#include "GPS_Backend.h"2324#if AP_GPS_ERB_ENABLED25class AP_GPS_ERB : public AP_GPS_Backend26{27public:2829using AP_GPS_Backend::AP_GPS_Backend;3031// Methods32bool read() override;3334AP_GPS::GPS_Status highest_supported_status(void) override { return AP_GPS::GPS_OK_FIX_3D_RTK_FIXED; }3536#if HAL_GCS_ENABLED37bool supports_mavlink_gps_rtk_message() const override { return true; }38#endif3940static bool _detect(struct ERB_detect_state &state, uint8_t data);4142const char *name() const override { return "ERB"; }4344private:45struct PACKED erb_header {46uint8_t preamble1;47uint8_t preamble2;48uint8_t msg_id;49uint16_t length;50};51struct PACKED erb_ver {52uint32_t time; ///< GPS time of week of the navigation epoch [ms]53uint8_t ver_high;54uint8_t ver_medium;55uint8_t ver_low;56};57struct PACKED erb_pos {58uint32_t time; ///< GPS time of week of the navigation epoch [ms]59double longitude;60double latitude;61double altitude_ellipsoid; ///< Height above ellipsoid [m]62double altitude_msl; ///< Height above mean sea level [m]63uint32_t horizontal_accuracy; ///< Horizontal accuracy estimate [mm]64uint32_t vertical_accuracy; ///< Vertical accuracy estimate [mm]65};66struct PACKED erb_stat {67uint32_t time; ///< GPS time of week of the navigation epoch [ms]68uint16_t week;69uint8_t fix_type; ///< see erb_fix_type enum70uint8_t fix_status;71uint8_t satellites;72};73struct PACKED erb_dops {74uint32_t time; ///< GPS time of week of the navigation epoch [ms]75uint16_t gDOP; ///< Geometric DOP76uint16_t pDOP; ///< Position DOP77uint16_t vDOP; ///< Vertical DOP78uint16_t hDOP; ///< Horizontal DOP79};80struct PACKED erb_vel {81uint32_t time; ///< GPS time of week of the navigation epoch [ms]82int32_t vel_north; ///< North velocity component [cm/s]83int32_t vel_east; ///< East velocity component [cm/s]84int32_t vel_down; ///< Down velocity component [cm/s]85uint32_t speed_2d; ///< Ground speed (2-D) [cm/s]86int32_t heading_2d; ///< Heading of motion 2-D [1e5 deg]87uint32_t speed_accuracy; ///< Speed accuracy Estimate [cm/s]88};89struct PACKED erb_rtk {90uint8_t base_num_sats; ///< Current number of satellites used for RTK calculation91uint16_t age_cs; ///< Age of the corrections in centiseconds (0 when no corrections, 0xFFFF indicates overflow)92int32_t baseline_N_mm; ///< distance between base and rover along the north axis in millimeters93int32_t baseline_E_mm; ///< distance between base and rover along the east axis in millimeters94int32_t baseline_D_mm; ///< distance between base and rover along the down axis in millimeters95uint16_t ar_ratio; ///< AR ratio multiplied by 1096uint16_t base_week_number; ///< GPS Week Number of last baseline97uint32_t base_time_week_ms; ///< GPS Time of Week of last baseline in milliseconds98};99100// Receive buffer101union PACKED {102DEFINE_BYTE_ARRAY_METHODS103erb_ver ver;104erb_pos pos;105erb_stat stat;106erb_dops dops;107erb_vel vel;108erb_rtk rtk;109} _buffer;110111enum erb_protocol_bytes {112PREAMBLE1 = 0x45,113PREAMBLE2 = 0x52,114MSG_VER = 0x01,115MSG_POS = 0x02,116MSG_STAT = 0x03,117MSG_DOPS = 0x04,118MSG_VEL = 0x05,119MSG_RTK = 0x07,120};121122enum erb_fix_type {123FIX_NONE = 0x00,124FIX_SINGLE = 0x01,125FIX_FLOAT = 0x02,126FIX_FIX = 0x03,127};128129// Packet checksum accumulators130uint8_t _ck_a;131uint8_t _ck_b;132133// State machine state134uint8_t _step;135uint8_t _msg_id;136uint16_t _payload_length;137uint16_t _payload_counter;138139// 8 bit count of fix messages processed, used for periodic processing140uint8_t _fix_count;141142uint32_t _last_pos_time;143uint32_t _last_vel_time;144145// do we have new position information?146bool _new_position:1;147// do we have new speed information?148bool _new_speed:1;149150// Buffer parse & GPS state update151bool _parse_gps();152153// used to update fix between status and position packets154AP_GPS::GPS_Status next_fix = AP_GPS::NO_FIX;155};156#endif157158159