I changed the code : libraries/SITL/SIM_GPS_NMEA.cpp as belows(with nano) :
/*
send a new GPS NMEA packet
*/
void GPS_NMEA::publish(const GPS_Data *d)
{
struct timeval tv;
struct tm *tm;
char tstring[20];
char dstring[20];
char lat_string[20];
char lng_string[20];
double yj_seconds = tv.tv_sec + tv.tv_usec * 1e-6; // seconds
double yj_t = fmod(yj_seconds, 20.0);
float yj_hdop;
if(yj_t < 10.0f)
{
yj_hdop = 1.2f;
}
else
{
yj_hdop = 2.1f;
}
simulation_timeval(&tv);
struct tm tvd {};
tm = gmtime_r(&tv.tv_sec, &tvd);
// format time string
hal.util->snprintf(tstring, sizeof(tstring), "%02u%02u%06.3f", tm->tm_hour, tm->tm_>
// format date string
hal.util->snprintf(dstring, sizeof(dstring), "%02u%02u%02u", tm->tm_mday, tm->tm_mo>
// format latitude
double deg = fabs(d->latitude);
hal.util->snprintf(lat_string, sizeof(lat_string), "%02u%08.5f,%c",
(unsigned)deg,
(deg - int(deg))*60,
d->latitude<0?'S':'N');
// format longitude
deg = fabs(d->longitude);
hal.util->snprintf(lng_string, sizeof(lng_string), "%03u%08.5f,%c",
(unsigned)deg,
(deg - int(deg))*60,
d->longitude<0?'W':'E');
nmea_printf("$GPGGA,%s,%s,%s,%01d,%02d,%04.1f,%07.2f,M,0.0,M,,",
tstring,
lat_string,
lng_string,
d->have_lock?1:0,
d->have_lock?d->num_sats:3,
yj_hdop,
d->altitude);
I built the code with waf and it detected my code changes.
but above didn’t work.
I changed GPS_UBlox::publish() in SIM_GPS_UBLOX.cpp like below and it worked :
dop.time = gps_tow.ms;
dop.gDOP = 65535;
dop.pDOP = 65535;
dop.tDOP = 65535;
dop.vDOP = 200;
dop.hDOP = 221; // modified from 121
dop.nDOP = 65535;
dop.eDOP = 65535;
I added code like below and it worked great :
static uint32_t yj_next_switch_ms = 0;
static uint16_t yj_current_hdop = 121;
uint32_t yj_now_ms = AP_HAL::millis();
if(yj_now_ms >= yj_next_switch_ms)
{
if(yj_current_hdop == 121)
{
yj_current_hdop = 221;
}
else
{
yj_current_hdop = 121;
}
yj_next_switch_ms = yj_now_ms + 10000; // 10 seconds
}
dop.hDOP = yj_current_hdop;
I could change value of hdop with above code.