From d216e68e1e478be65e518dd7c2f1c411613d2ed1 Mon Sep 17 00:00:00 2001 From: janbar Date: Sat, 14 Sep 2024 16:58:46 +0200 Subject: [PATCH] disable check of flag valid position returned by the sensor My old device (Sony XA2) seems to not update the status as expected, so disable the check to process data. --- src/tracker.cpp | 154 +++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 81 deletions(-) diff --git a/src/tracker.cpp b/src/tracker.cpp index b8ef825f..55172618 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -283,112 +283,104 @@ void TrackerModule::onLocationChanged(bool positionValid, double lat, double lon osmscout::Timestamp now = std::chrono::system_clock::now(); osmscout::Bearing bearing; - if (positionValid) + // compute data for the last interval, + // starting with the last known position and up to now + if (!m_lastPosition) { - // compute data for the last interval, - // starting with the last known position and up to now - if (!m_lastPosition) - { // On the first run, initialize the starting data m_currentAlt = alt; m_currentSpeed = 0.0; bearing = osmscout::Bearing::Degrees(m_azimuth); - } - else - { + } + else + { // the duration should be non zero auto sec = std::chrono::duration_cast >(now - m_lastPosition.time); if (sec.count() > 0) { - // i use accel to validate the new interval - // the new data won't be used when value is excessive - // the horizontal distance - double dh = osmin::Utils::sphericalDistance(m_lastPosition.coord.GetLat(), m_lastPosition.coord.GetLon(), lat, lon); - double dv = 0.0; - if (!std::isnan(alt) && !std::isnan(m_currentAlt)) - dv = alt - m_currentAlt; - double s0 = std::sqrt(std::pow(dh, 2) + std::pow(dv, 2)) / sec.count(); - double accel = std::fabs((s0 - (m_currentSpeed / 3.6)) / sec.count()); - if (accel > MAX_ACCEL) - { - // reset elevation for the next run - m_currentAlt = alt; - } - else - { - // the vertical accuracy isn't good enough, therefore i estimate the speed using - // horizontal data only - double kmh = 3.6 * dh / sec.count(); - // update tracking data when moving - if (kmh > MOVING_SPEED) + // i use accel to validate the new interval + // the new data won't be used when value is excessive + // the horizontal distance + double dh = osmin::Utils::sphericalDistance(m_lastPosition.coord.GetLat(), m_lastPosition.coord.GetLon(), lat, lon); + double dv = 0.0; + if (!std::isnan(alt) && !std::isnan(m_currentAlt)) + dv = alt - m_currentAlt; + double s0 = std::sqrt(std::pow(dh, 2) + std::pow(dv, 2)) / sec.count(); + double accel = std::fabs((s0 - (m_currentSpeed / 3.6)) / sec.count()); + if (accel > MAX_ACCEL) { - m_distance += dh; - m_duration += sec.count(); - if (kmh > m_maxSpeed) - m_maxSpeed = kmh; - if (dv > ASC_THRESHOLD) - { - m_ascent += dv; - m_currentAlt = alt; - } - else if (dv < DES_THRESHOLD) - { - m_descent -= dv; + // reset elevation for the next run m_currentAlt = alt; - } } - m_currentSpeed = kmh; - emit dataChanged(m_currentSpeed, m_distance, m_duration, m_ascent, m_descent, m_maxSpeed); - } + else + { + // the vertical accuracy isn't good enough, therefore i estimate the speed using + // horizontal data only + double kmh = 3.6 * dh / sec.count(); + // update tracking data when moving + if (kmh > MOVING_SPEED) + { + m_distance += dh; + m_duration += sec.count(); + if (kmh > m_maxSpeed) + m_maxSpeed = kmh; + if (dv > ASC_THRESHOLD) + { + m_ascent += dv; + m_currentAlt = alt; + } + else if (dv < DES_THRESHOLD) + { + m_descent -= dv; + m_currentAlt = alt; + } + } + m_currentSpeed = kmh; + emit dataChanged(m_currentSpeed, m_distance, m_duration, m_ascent, m_descent, m_maxSpeed); + } } // when we are stationary the direction is calculated according to the azimuth of the device // otherwise it is estimated according to the progress compared to the previous position if (m_currentSpeed < COURSE_SPEED) - bearing = osmscout::Bearing::Degrees(m_azimuth); + bearing = osmscout::Bearing::Degrees(m_azimuth); else - bearing = osmscout::Bearing::Radians(osmin::Utils::sphericalBearingFinal(m_lastPosition.coord.GetLat(), m_lastPosition.coord.GetLon(), lat, lon)); + bearing = osmscout::Bearing::Radians(osmin::Utils::sphericalBearingFinal(m_lastPosition.coord.GetLat(), m_lastPosition.coord.GetLon(), lat, lon)); if (m_recording) { - if (!m_lastRecord) - { - record(); - m_lastRecord.time = m_lastPosition.time; - m_lastRecord.coord = m_lastPosition.coord; - m_lastRecord.bearing = m_lastPosition.bearing; - emit positionRecorded(m_lastRecord.coord); - } - else - { - double dh = osmin::Utils::sphericalDistance(m_lastRecord.coord.GetLat(), m_lastRecord.coord.GetLon(), lat, lon); - double da = std::fabs(bearing.AsRadians() - m_lastRecord.bearing.AsRadians()); - if (da > M_PI_2) - da = std::fabs(da - M_PI); - // 0.17rad ~ 20deg - if (dh >= RECORD_INTERVAL || (da > 0.17 && dh > 5.0)) + if (!m_lastRecord) { - record(); - m_lastRecord.time = m_lastPosition.time; - m_lastRecord.coord = m_lastPosition.coord; - m_lastRecord.bearing = m_lastPosition.bearing; - emit positionRecorded(m_lastRecord.coord); + record(); + m_lastRecord.time = m_lastPosition.time; + m_lastRecord.coord = m_lastPosition.coord; + m_lastRecord.bearing = m_lastPosition.bearing; + emit positionRecorded(m_lastRecord.coord); + } + else + { + double dh = osmin::Utils::sphericalDistance(m_lastRecord.coord.GetLat(), m_lastRecord.coord.GetLon(), lat, lon); + double da = std::fabs(bearing.AsRadians() - m_lastRecord.bearing.AsRadians()); + if (da > M_PI_2) + da = std::fabs(da - M_PI); + // 0.17rad ~ 20deg + if (dh >= RECORD_INTERVAL || (da > 0.17 && dh > 5.0)) + { + record(); + m_lastRecord.time = m_lastPosition.time; + m_lastRecord.coord = m_lastPosition.coord; + m_lastRecord.bearing = m_lastPosition.bearing; + emit positionRecorded(m_lastRecord.coord); + } } - } } - } - - // save last position - m_lastPosition.bearing = bearing; - m_lastPosition.coord.Set(lat, lon); - m_lastPosition.elevation = alt; - m_lastPosition.time = now; - } - else - { - // update azimuth only - m_lastPosition.bearing = osmscout::Bearing::Degrees(m_azimuth); } + // save last position + m_lastPosition.bearing = bearing; + m_lastPosition.coord.Set(lat, lon); + m_lastPosition.elevation = alt; + m_lastPosition.time = now; + emit positionChanged(m_state, m_lastPosition.coord, std::optional(m_lastPosition.bearing)); }