Copter: added support for 2nd GPS

This commit is contained in:
Andrew Tridgell 2014-02-26 09:40:29 +11:00
parent 82ffc0ff2b
commit 37394b30ee
4 changed files with 62 additions and 0 deletions

View File

@ -238,6 +238,9 @@ static const AP_InertialSensor::Sample_rate ins_sample_rate = AP_InertialSensor:
// All GPS access should be through this pointer.
static GPS *g_gps;
#if GPS2_ENABLE
static GPS *g_gps2;
#endif
static GPS_Glitch gps_glitch(g_gps);
// flight modes convenience array
@ -294,6 +297,9 @@ static AP_Compass_HMC5843 compass;
// real GPS selection
#if GPS_PROTOCOL == GPS_PROTOCOL_AUTO
AP_GPS_Auto g_gps_driver(&g_gps);
#if GPS2_ENABLE
AP_GPS_UBLOX g_gps2_driver;
#endif
#elif GPS_PROTOCOL == GPS_PROTOCOL_NMEA
AP_GPS_NMEA g_gps_driver;
@ -1281,6 +1287,19 @@ static void update_GPS(void)
// check for loss of gps
failsafe_gps_check();
#if GPS2_ENABLE
static uint32_t last_gps2_reading;
if (g_gps2 != NULL) {
g_gps2->update();
if (g_gps2->last_message_time_ms() != last_gps2_reading) {
last_gps2_reading = g_gps2->last_message_time_ms();
if (g.log_bitmask & MASK_LOG_GPS) {
DataFlash.Log_Write_GPS2(g_gps2);
}
}
}
#endif
}
static void

View File

@ -305,6 +305,27 @@ static void NOINLINE send_gps_raw(mavlink_channel_t chan)
g_gps->ground_course_cd, // 1/100 degrees,
g_gps->num_sats);
#if GPS2_ENABLE
if (g_gps2 != NULL) {
int16_t payload_space = comm_get_txspace(chan) - MAVLINK_NUM_NON_PAYLOAD_BYTES;
if (payload_space >= MAVLINK_MSG_ID_GPS2_RAW_LEN) {
mavlink_msg_gps2_raw_send(
chan,
g_gps2->last_fix_time*(uint64_t)1000,
g_gps2->status(),
g_gps2->latitude, // in 1E7 degrees
g_gps2->longitude, // in 1E7 degrees
g_gps2->altitude_cm * 10, // in mm
g_gps2->hdop,
65535,
g_gps2->ground_speed_cm, // cm/s
g_gps2->ground_course_cd, // 1/100 degrees,
g_gps2->num_sats,
0,
0);
}
}
#endif
}
static void NOINLINE send_system_time(mavlink_channel_t chan)

View File

@ -106,6 +106,15 @@
# define MAIN_LOOP_SECONDS 0.01
# define MAIN_LOOP_MICROS 10000
#endif
// 2nd GPS support
#if HAL_CPU_CLASS >= HAL_CPU_CLASS_150
#define GPS2_ENABLE 1
#else
#define GPS2_ENABLE 0
#endif
//////////////////////////////////////////////////////////////////////////////
// FRAME_CONFIG
//

View File

@ -103,6 +103,12 @@ static void init_ardupilot()
hal.uartB->begin(38400, 256, 16);
#endif
#if GPS2_ENABLE
if (hal.uartE != NULL) {
hal.uartE->begin(38400, 256, 16);
}
#endif
cliSerial->printf_P(PSTR("\n\nInit " FIRMWARE_STRING
"\n\nFree RAM: %u\n"),
hal.util->available_memory());
@ -225,6 +231,13 @@ static void init_ardupilot()
// GPS Initialization
g_gps->init(hal.uartB, GPS::GPS_ENGINE_AIRBORNE_4G);
#if GPS2_ENABLE
if (hal.uartE != NULL) {
g_gps2 = &g_gps2_driver;
g_gps2->init(hal.uartE, GPS::GPS_ENGINE_AIRBORNE_4G);
}
#endif
if(g.compass_enabled)
init_compass();