PX4 Firmware
PX4 Autopilot Software http://px4.io
emlid_reach.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file emlid_reach.h
36  *
37  * @author Bastien Auneau <bastien.auneau@while-true.fr>
38  */
39 
40 #pragma once
41 
42 #include "gps_helper.h"
43 #include "../../definitions.h"
44 
45 // Emlid documentation
46 // https://docs.emlid.com/reachm-plus/
47 // https://files.emlid.com/ERB.pdf
48 
49 #define ERB_HEADER_LEN 5
50 // Not using ERB_ID_SPACE_INFO, so use a smaller buff length
51 #define ERB_SENTENCE_MAX_LEN (sizeof(erb_message_t))
52 
53 #define MAX_CONST(a, b) ((a>b) ? a : b)
54 
55 // Emlid ERB message definition
56 #pragma pack(push, 1)
57 
58 typedef struct {
59  uint8_t sync1;
60  uint8_t sync2;
61  uint8_t id;
62  uint16_t length;
63 } erb_header_t;
64 
65 typedef struct {
66  uint8_t ck_a;
67  uint8_t ck_b;
69 
70 typedef struct {
71  uint32_t timeGPS;
72  uint8_t verH;
73  uint8_t verM;
74  uint8_t verL;
77 
78 typedef struct {
79  uint32_t timeGPS;
80  double longitude;
81  double latitude;
82  double altElipsoid;
84  uint32_t accHorizontal;
85  uint32_t accVertical;
88 
89 typedef struct {
90  uint32_t timeGPS;
91  uint16_t weekGPS;
92  uint8_t fixType;
93  uint8_t fixStatus;
94  uint8_t numSatUsed;
97 
98 typedef struct {
99  uint32_t timeGPS;
100  uint16_t dopGeometric;
101  uint16_t dopPosition;
102  uint16_t dopVertical;
103  uint16_t dopHorizontal;
105 } erb_dop_t;
106 
107 typedef struct {
108  uint32_t timeGPS;
109  int32_t velN;
110  int32_t velE;
111  int32_t velD;
112  uint32_t speed;
113  int32_t heading;
114  uint32_t speedAccuracy;
117 
118 typedef union {
124 } erb_payload_t;
125 
126 typedef struct {
129 } erb_message_t;
130 
131 #pragma pack(pop)
132 
133 
134 /**
135  * Driver class for Emlid Reach
136  * Populates caller provided vehicle_gps_position_s
137  * Some ERB messages are cached and correlated by timestamp before publishing it
138  */
140 {
141 public:
142  GPSDriverEmlidReach(GPSCallbackPtr callback, void *callback_user,
143  struct vehicle_gps_position_s *gps_position,
144  struct satellite_info_s *satellite_info
145  );
146 
147  virtual ~GPSDriverEmlidReach() = default;
148 
149  int receive(unsigned timeout) override;
150  int configure(unsigned &baudrate, OutputMode output_mode) override;
151 
152 private:
153 
154  enum class ERB_State {
155  init = 0,
156  got_sync_1, // E
157  got_sync_2, // R
158  got_id,
159  got_len_1,
160  got_len_2,
161  got_payload,
162  got_CK_A
163  };
164 
165 
166  /** NMEA parser state machine */
168 
169  /** Buffer used by parser to build ERB sentences */
171  uint16_t _erb_buff_cnt{};
172 
173  /** Buffer used by parser to build ERB checksum */
175  uint8_t _erb_checksum_cnt{};
176 
177  /** Pointer provided by caller, ie gps.cpp */
179  /** Pointer provided by caller, gps.cpp */
181 
182  bool _testing_connection{false};
183  /** counts decoded sentence when testing connection */
184  unsigned _sentence_cnt{0};
185 
186  uint16_t _erb_payload_len{0};
187 
188  uint32_t _last_POS_timeGPS{0};
189  uint32_t _last_VEL_timeGPS{0};
190  bool _POS_received{false};
191  bool _VEL_received{false};
192 
193 
194  ///// ERB messages caches /////
195  uint8_t _fix_type{0};
196  uint8_t _fix_status{0};
197  uint8_t _satellites_used{0};
198  float _hdop{0};
199  float _vdop{0};
200 
201 
202  /** Feed ERB parser with received bytes from serial
203  * @return len of decoded message, 0 if not completed, -1 if error
204  */
205  int erbParseChar(uint8_t b);
206 
207  /** ERB sentence into vehicle_gps_position_s or satellite_info_s, to be used by GPSHelper
208  * @return 1 if gps_position updated, 2 for satellite_info_s (can be bit OR), 0 for nothing
209  */
210  int handleErbSentence();
211 
212  void computeNedVelocity();
213 
214  bool testConnection();
215 
216 };
217 
erb_navigation_status_t navigation_status
Definition: emlid_reach.h:121
uint8_t id
Definition: emlid_reach.h:61
uint16_t _erb_payload_len
Definition: emlid_reach.h:186
unsigned _sentence_cnt
counts decoded sentence when testing connection
Definition: emlid_reach.h:184
uint32_t timeGPS
Definition: emlid_reach.h:99
uint16_t dopHorizontal
Definition: emlid_reach.h:103
GPSDriverEmlidReach(GPSCallbackPtr callback, void *callback_user, struct vehicle_gps_position_s *gps_position, struct satellite_info_s *satellite_info)
Definition: emlid_reach.cpp:73
struct vehicle_gps_position_s * _gps_position
Pointer provided by caller, ie gps.cpp.
Definition: emlid_reach.h:178
uint16_t length
Definition: emlid_reach.h:62
uint16_t dopVertical
Definition: emlid_reach.h:102
erb_checksum_t checksum
Definition: emlid_reach.h:104
erb_geodic_position_t geodic_position
Definition: emlid_reach.h:120
ERB_State _erb_decode_state
NMEA parser state machine.
Definition: emlid_reach.h:167
uint8_t _satellites_used
Definition: emlid_reach.h:197
erb_checksum_t _erb_checksum
Buffer used by parser to build ERB checksum.
Definition: emlid_reach.h:174
uint8_t ck_a
Definition: emlid_reach.h:66
erb_checksum_t checksum
Definition: emlid_reach.h:115
uint8_t sync2
Definition: emlid_reach.h:60
erb_message_t _erb_buff
Buffer used by parser to build ERB sentences.
Definition: emlid_reach.h:170
uint32_t _last_VEL_timeGPS
Definition: emlid_reach.h:189
uint32_t speedAccuracy
Definition: emlid_reach.h:114
int erbParseChar(uint8_t b)
Feed ERB parser with received bytes from serial.
uint16_t _erb_buff_cnt
Definition: emlid_reach.h:171
int(* GPSCallbackPtr)(GPSCallbackType type, void *data1, int data2, void *user)
Callback function for platform-specific stuff.
Definition: gps_helper.h:132
erb_checksum_t checksum
Definition: emlid_reach.h:86
uint8_t sync1
Definition: emlid_reach.h:59
erb_header_t header
Definition: emlid_reach.h:127
virtual ~GPSDriverEmlidReach()=default
uint32_t _last_POS_timeGPS
Definition: emlid_reach.h:188
uint8_t verH
Definition: emlid_reach.h:72
erb_dop_t dop
Definition: emlid_reach.h:122
erb_checksum_t checksum
Definition: emlid_reach.h:75
erb_payload_t payload
Definition: emlid_reach.h:128
int handleErbSentence()
ERB sentence into vehicle_gps_position_s or satellite_info_s, to be used by GPSHelper.
uint8_t ck_b
Definition: emlid_reach.h:67
struct satellite_info_s * _satellite_info
Pointer provided by caller, gps.cpp.
Definition: emlid_reach.h:180
uint16_t dopPosition
Definition: emlid_reach.h:101
erb_version_t version
Definition: emlid_reach.h:119
uint32_t timeGPS
Definition: emlid_reach.h:71
erb_checksum_t checksum
Definition: emlid_reach.h:95
uint8_t _erb_checksum_cnt
Definition: emlid_reach.h:175
uint8_t verL
Definition: emlid_reach.h:74
erb_ned_velocity_t ned_velocity
Definition: emlid_reach.h:123
Driver class for Emlid Reach Populates caller provided vehicle_gps_position_s Some ERB messages are c...
Definition: emlid_reach.h:139
int configure(unsigned &baudrate, OutputMode output_mode) override
configure the device
Definition: emlid_reach.cpp:81
int receive(unsigned timeout) override
receive & handle new data from the device
uint16_t dopGeometric
Definition: emlid_reach.h:100
uint8_t verM
Definition: emlid_reach.h:73