Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix position health flags on GPS loss #807

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/plugins/telemetry/telemetry_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,21 @@ void TelemetryImpl::init()

void TelemetryImpl::deinit()
{
_parent->unregister_timeout_handler(_timeout_cookie);
_parent->unregister_timeout_handler(_rc_channels_timeout_cookie);
_parent->unregister_timeout_handler(_gps_raw_timeout_cookie);
_parent->unregister_param_changed_handler(this);
_parent->unregister_all_mavlink_message_handlers(this);
}

void TelemetryImpl::enable()
{
_parent->register_timeout_handler(
std::bind(&TelemetryImpl::receive_rc_channels_timeout, this), 1.0, &_timeout_cookie);
std::bind(&TelemetryImpl::receive_rc_channels_timeout, this),
1.0,
&_rc_channels_timeout_cookie);

_parent->register_timeout_handler(
std::bind(&TelemetryImpl::receive_gps_raw_timeout, this), 2.0, &_gps_raw_timeout_cookie);

// FIXME: The calibration check should eventually be better than this.
// For now, we just do the same as QGC does.
Expand Down Expand Up @@ -494,6 +500,8 @@ void TelemetryImpl::process_gps_raw_int(const mavlink_message_t& message)
auto arg = get_gps_info();
_parent->call_user_callback([callback, arg]() { callback(arg); });
}

_parent->refresh_timeout_handler(_gps_raw_timeout_cookie);
}

void TelemetryImpl::process_extended_sys_state(const mavlink_message_t& message)
Expand Down Expand Up @@ -624,7 +632,7 @@ void TelemetryImpl::process_rc_channels(const mavlink_message_t& message)
_parent->call_user_callback([callback, arg]() { callback(arg); });
}

_parent->refresh_timeout_handler(_timeout_cookie);
_parent->refresh_timeout_handler(_rc_channels_timeout_cookie);
}

Telemetry::FlightMode TelemetryImpl::to_flight_mode_from_custom_mode(uint32_t custom_mode)
Expand Down Expand Up @@ -731,6 +739,13 @@ void TelemetryImpl::receive_rc_channels_timeout()
set_rc_status(rc_ok, 0.0f);
}

void TelemetryImpl::receive_gps_raw_timeout()
{
const bool position_ok = false;
set_health_local_position(position_ok);
set_health_global_position(position_ok);
}

Telemetry::PositionVelocityNED TelemetryImpl::get_position_velocity_ned() const
{
std::lock_guard<std::mutex> lock(_position_velocity_ned_mutex);
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/telemetry/telemetry_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class TelemetryImpl : public PluginImplBase {
void receive_param_hitl(MAVLinkParameters::Result result, int value);

void receive_rc_channels_timeout();
void receive_gps_raw_timeout();

static Telemetry::Result
telemetry_result_from_command_result(MAVLinkCommands::Result command_result);
Expand Down Expand Up @@ -222,6 +223,7 @@ class TelemetryImpl : public PluginImplBase {
double _ground_speed_ned_rate_hz{0.0};
double _position_rate_hz{-1.0};

void* _timeout_cookie{nullptr};
void* _rc_channels_timeout_cookie{nullptr};
void* _gps_raw_timeout_cookie{nullptr};
};
} // namespace mavsdk