2013-05-29 20:52:21 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2010-09-06 06:20:44 -03:00
|
|
|
|
|
|
|
/// @file GPS.h
|
|
|
|
/// @brief Interface definition for the various GPS drivers.
|
|
|
|
|
2012-09-27 02:18:44 -03:00
|
|
|
#ifndef __GPS_H__
|
|
|
|
#define __GPS_H__
|
|
|
|
|
|
|
|
#include <AP_HAL.h>
|
2010-08-29 19:58:22 -03:00
|
|
|
|
|
|
|
#include <inttypes.h>
|
2012-12-12 17:45:12 -04:00
|
|
|
#include <AP_Progmem.h>
|
2013-07-19 19:13:50 -03:00
|
|
|
#include <AP_Math.h>
|
2010-08-29 19:58:22 -03:00
|
|
|
|
2010-09-06 06:20:44 -03:00
|
|
|
/// @class GPS
|
|
|
|
/// @brief Abstract base class for GPS receiver drivers.
|
2010-08-29 19:58:22 -03:00
|
|
|
class GPS
|
|
|
|
{
|
2010-09-06 06:20:44 -03:00
|
|
|
public:
|
2013-02-19 20:32:15 -04:00
|
|
|
GPS();
|
2010-09-06 06:20:44 -03:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
/// Update GPS state based on possible bytes received from the module.
|
|
|
|
///
|
|
|
|
/// This routine must be called periodically to process incoming data.
|
|
|
|
///
|
|
|
|
/// GPS drivers should not override this function; they should implement
|
|
|
|
/// ::read instead.
|
|
|
|
///
|
2012-08-21 23:19:52 -03:00
|
|
|
void update(void);
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
/// GPS status codes
|
|
|
|
///
|
|
|
|
/// \note Non-intuitive ordering for legacy reasons
|
|
|
|
///
|
|
|
|
enum GPS_Status {
|
2012-08-21 23:19:52 -03:00
|
|
|
NO_GPS = 0, ///< No GPS connected/detected
|
|
|
|
NO_FIX = 1, ///< Receiving valid GPS messages but no lock
|
2013-03-25 04:24:14 -03:00
|
|
|
GPS_OK_FIX_2D = 2, ///< Receiving valid messages and 2D lock
|
|
|
|
GPS_OK_FIX_3D = 3 ///< Receiving valid messages and 3D lock
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Fix status codes
|
|
|
|
///
|
|
|
|
enum Fix_Status {
|
|
|
|
FIX_NONE = 0, ///< No fix
|
|
|
|
FIX_2D = 2, ///< 2d fix
|
|
|
|
FIX_3D = 3, ///< 3d fix
|
2011-10-28 15:52:50 -03:00
|
|
|
};
|
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
// GPS navigation engine settings. Not all GPS receivers support
|
|
|
|
// this
|
|
|
|
enum GPS_Engine_Setting {
|
|
|
|
GPS_ENGINE_NONE = -1,
|
2012-11-22 01:23:29 -04:00
|
|
|
GPS_ENGINE_PORTABLE = 0,
|
|
|
|
GPS_ENGINE_STATIONARY = 2,
|
2012-08-21 23:19:52 -03:00
|
|
|
GPS_ENGINE_PEDESTRIAN = 3,
|
|
|
|
GPS_ENGINE_AUTOMOTIVE = 4,
|
|
|
|
GPS_ENGINE_SEA = 5,
|
|
|
|
GPS_ENGINE_AIRBORNE_1G = 6,
|
|
|
|
GPS_ENGINE_AIRBORNE_2G = 7,
|
|
|
|
GPS_ENGINE_AIRBORNE_4G = 8
|
|
|
|
};
|
2012-06-10 03:34:53 -03:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
/// Query GPS status
|
|
|
|
///
|
|
|
|
/// The 'valid message' status indicates that a recognised message was
|
|
|
|
/// received from the GPS within the last 500ms.
|
|
|
|
///
|
|
|
|
/// @returns Current GPS status
|
|
|
|
///
|
2013-04-19 04:47:01 -03:00
|
|
|
GPS_Status status(void) const {
|
2011-10-28 15:52:50 -03:00
|
|
|
return _status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Startup initialisation.
|
|
|
|
///
|
|
|
|
/// This routine performs any one-off initialisation required to set the
|
|
|
|
/// GPS up for use.
|
|
|
|
///
|
|
|
|
/// Must be implemented by the GPS driver.
|
|
|
|
///
|
2012-12-17 22:31:05 -04:00
|
|
|
virtual void init(AP_HAL::UARTDriver *s, enum GPS_Engine_Setting engine_setting = GPS_ENGINE_NONE) = 0;
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
// Properties
|
2013-10-23 08:13:48 -03:00
|
|
|
uint32_t time_week_ms; ///< GPS time (milliseconds from start of GPS week)
|
|
|
|
uint16_t time_week; ///< GPS week number
|
2012-08-21 23:19:52 -03:00
|
|
|
int32_t latitude; ///< latitude in degrees * 10,000,000
|
|
|
|
int32_t longitude; ///< longitude in degrees * 10,000,000
|
2013-07-10 01:01:53 -03:00
|
|
|
int32_t altitude_cm; ///< altitude in cm
|
|
|
|
uint32_t ground_speed_cm; ///< ground speed in cm/sec
|
|
|
|
int32_t ground_course_cd; ///< ground course in 100ths of a degree
|
|
|
|
int32_t speed_3d_cm; ///< 3D speed in cm/sec (not always available)
|
2012-08-21 23:19:52 -03:00
|
|
|
int16_t hdop; ///< horizontal dilution of precision in cm
|
|
|
|
uint8_t num_sats; ///< Number of visible satelites
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
/// Set to true when new data arrives. A client may set this
|
|
|
|
/// to false in order to avoid processing data they have
|
|
|
|
/// already seen.
|
2012-08-21 23:19:52 -03:00
|
|
|
bool new_data;
|
2011-10-28 15:52:50 -03:00
|
|
|
|
2013-03-25 04:24:14 -03:00
|
|
|
Fix_Status fix; ///< 0 if we have no fix, 2 for 2D fix, 3 for 3D fix
|
2012-08-21 23:19:52 -03:00
|
|
|
bool valid_read; ///< true if we have seen data from the GPS (use ::status instead)
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
// Debug support
|
2012-08-21 23:19:52 -03:00
|
|
|
bool print_errors; ///< deprecated
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
// HIL support
|
2013-10-23 08:13:48 -03:00
|
|
|
virtual void setHIL(uint64_t time_epoch_ms, float latitude, float longitude, float altitude,
|
2011-10-28 15:52:50 -03:00
|
|
|
float ground_speed, float ground_course, float speed_3d, uint8_t num_sats);
|
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
// components of velocity in 2D, in m/s
|
2013-07-19 19:13:50 -03:00
|
|
|
float velocity_north(void) const {
|
2013-03-25 04:24:14 -03:00
|
|
|
return _status >= GPS_OK_FIX_2D ? _velocity_north : 0;
|
2012-08-21 23:19:52 -03:00
|
|
|
}
|
2013-07-19 19:13:50 -03:00
|
|
|
float velocity_east(void) const {
|
2013-03-25 04:24:14 -03:00
|
|
|
return _status >= GPS_OK_FIX_2D ? _velocity_east : 0;
|
2012-08-21 23:19:52 -03:00
|
|
|
}
|
2013-07-19 19:13:50 -03:00
|
|
|
float velocity_down(void) const {
|
2013-03-25 07:08:47 -03:00
|
|
|
return _status >= GPS_OK_FIX_3D ? _velocity_down : 0;
|
2012-10-30 23:56:04 -03:00
|
|
|
}
|
2012-03-04 05:33:12 -04:00
|
|
|
|
2013-07-19 19:13:50 -03:00
|
|
|
// GPS velocity vector as NED in m/s
|
|
|
|
Vector3f velocity_vector(void) const {
|
|
|
|
return Vector3f(_velocity_north, _velocity_east, _velocity_down);
|
|
|
|
}
|
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
// last ground speed in m/s. This can be used when we have no GPS
|
|
|
|
// lock to return the last ground speed we had with lock
|
|
|
|
float last_ground_speed(void) {
|
2013-12-10 19:22:22 -04:00
|
|
|
return static_cast<float>(_last_ground_speed_cm) * 0.01f;
|
2012-08-21 23:19:52 -03:00
|
|
|
}
|
2012-03-23 02:23:23 -03:00
|
|
|
|
2012-09-20 03:48:22 -03:00
|
|
|
// the expected lag (in seconds) in the position and velocity readings from the gps
|
2013-12-10 19:22:22 -04:00
|
|
|
virtual float get_lag() { return 1.0f; }
|
2012-08-10 22:59:47 -03:00
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
// the time we got our last fix in system milliseconds
|
|
|
|
uint32_t last_fix_time;
|
2012-03-07 00:15:13 -04:00
|
|
|
|
2013-04-28 01:53:02 -03:00
|
|
|
// the time we last processed a message in milliseconds
|
2013-12-29 03:36:52 -04:00
|
|
|
uint32_t last_message_time_ms(void) const { return _idleTimer; }
|
2013-04-28 01:53:02 -03:00
|
|
|
|
2013-10-23 08:13:48 -03:00
|
|
|
// return last fix time since the 1/1/1970 in microseconds
|
|
|
|
uint64_t time_epoch_usec(void);
|
|
|
|
|
2012-10-30 23:56:04 -03:00
|
|
|
// return true if the GPS supports raw velocity values
|
|
|
|
|
|
|
|
|
2010-09-06 06:20:44 -03:00
|
|
|
protected:
|
2012-09-27 02:18:44 -03:00
|
|
|
AP_HAL::UARTDriver *_port; ///< port the GPS is attached to
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
/// read from the GPS stream and update properties
|
|
|
|
///
|
|
|
|
/// Must be implemented by the GPS driver.
|
|
|
|
///
|
|
|
|
/// @returns true if a valid message was received from the GPS
|
|
|
|
///
|
2012-08-21 23:19:52 -03:00
|
|
|
virtual bool read(void) = 0;
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
/// perform an endian swap on a long
|
|
|
|
///
|
|
|
|
/// @param bytes pointer to a buffer containing bytes representing a
|
|
|
|
/// long in the wrong byte order
|
|
|
|
/// @returns endian-swapped value
|
|
|
|
///
|
2013-04-28 01:51:37 -03:00
|
|
|
int32_t _swapl(const void *bytes) const;
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
/// perform an endian swap on an int
|
|
|
|
///
|
|
|
|
/// @param bytes pointer to a buffer containing bytes representing an
|
|
|
|
/// int in the wrong byte order
|
|
|
|
/// @returns endian-swapped value
|
2013-04-28 01:51:37 -03:00
|
|
|
int16_t _swapi(const void *bytes) const;
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
|
|
/// emit an error message
|
|
|
|
///
|
|
|
|
/// based on the value of print_errors, emits the printf-formatted message
|
|
|
|
/// in msg,... to stderr
|
|
|
|
///
|
|
|
|
/// @param fmt printf-like format string
|
|
|
|
///
|
|
|
|
/// @note deprecated as-is due to the difficulty of hooking up to a working
|
|
|
|
/// printf vs. the potential benefits
|
|
|
|
///
|
2012-08-21 23:19:52 -03:00
|
|
|
void _error(const char *msg);
|
2011-10-28 15:52:50 -03:00
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
enum GPS_Engine_Setting _nav_setting;
|
2012-06-10 03:34:53 -03:00
|
|
|
|
2012-09-27 02:18:44 -03:00
|
|
|
void _write_progstr_block(AP_HAL::UARTDriver *_fs, const prog_char *pstr, uint8_t size);
|
|
|
|
void _send_progstr(AP_HAL::UARTDriver *_fs, const prog_char *pstr, uint8_t size);
|
2012-10-18 02:18:12 -03:00
|
|
|
void _update_progstr(void);
|
2012-06-15 02:53:14 -03:00
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
// velocities in cm/s if available from the GPS
|
|
|
|
int32_t _vel_north;
|
|
|
|
int32_t _vel_east;
|
|
|
|
int32_t _vel_down;
|
2012-08-14 05:32:46 -03:00
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
// does this GPS support raw velocity numbers?
|
|
|
|
bool _have_raw_velocity;
|
2012-08-14 05:32:46 -03:00
|
|
|
|
2013-03-17 03:52:29 -03:00
|
|
|
// detected baudrate
|
|
|
|
uint16_t _baudrate;
|
|
|
|
|
2013-10-23 08:13:48 -03:00
|
|
|
// the time we got the last GPS timestamp
|
|
|
|
uint32_t _last_gps_time;
|
|
|
|
|
|
|
|
// return time in seconds since GPS epoch given time components
|
|
|
|
void _make_gps_time(uint32_t bcd_date, uint32_t bcd_milliseconds);
|
|
|
|
|
2010-12-24 02:35:09 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
/// Last time that the GPS driver got a good packet from the GPS
|
|
|
|
///
|
2012-08-21 23:19:52 -03:00
|
|
|
uint32_t _idleTimer;
|
2010-12-24 02:35:09 -04:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
/// Our current status
|
2012-08-21 23:19:52 -03:00
|
|
|
GPS_Status _status;
|
2011-06-16 13:33:08 -03:00
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
// previous ground speed in cm/s
|
2012-08-10 22:59:47 -03:00
|
|
|
uint32_t _last_ground_speed_cm;
|
2012-03-04 05:33:12 -04:00
|
|
|
|
2012-08-21 23:19:52 -03:00
|
|
|
// components of the velocity, in m/s
|
|
|
|
float _velocity_north;
|
|
|
|
float _velocity_east;
|
2012-10-30 23:56:04 -03:00
|
|
|
float _velocity_down;
|
2010-08-29 19:58:22 -03:00
|
|
|
};
|
|
|
|
|
2012-09-27 02:18:44 -03:00
|
|
|
#endif // __GPS_H__
|