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

telemetry: assume sensor calibration ok in HITL #471

Merged
merged 1 commit into from
Jul 25, 2018
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
30 changes: 26 additions & 4 deletions plugins/telemetry/telemetry_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ void TelemetryImpl::enable()
// If not available, just hardcode it to true.
set_health_level_calibration(true);
#endif

_parent->get_param_int_async(std::string("SYS_HITL"),
std::bind(&TelemetryImpl::receive_param_hitl,
this,
std::placeholders::_1,
std::placeholders::_2));
}

void TelemetryImpl::disable()
Expand Down Expand Up @@ -604,6 +610,22 @@ void TelemetryImpl::receive_param_cal_level(bool success, float value)
}
#endif

void TelemetryImpl::receive_param_hitl(bool success, int value)
{
if (!success) {
LogErr() << "Error: Param to determine hitl failed.";
return;
}

_hitl_enabled = (value == 1);
set_health_accelerometer_calibration(_hitl_enabled);
set_health_gyrometer_calibration(_hitl_enabled);
set_health_magnetometer_calibration(_hitl_enabled);
#ifdef LEVEL_CALIBRATION
set_health_level_calibration(ok);
#endif
}

void TelemetryImpl::receive_rc_channels_timeout()
{
const bool rc_ok = false;
Expand Down Expand Up @@ -800,25 +822,25 @@ void TelemetryImpl::set_health_home_position(bool ok)
void TelemetryImpl::set_health_gyrometer_calibration(bool ok)
{
std::lock_guard<std::mutex> lock(_health_mutex);
_health.gyrometer_calibration_ok = ok;
_health.gyrometer_calibration_ok = (ok || _hitl_enabled);
}

void TelemetryImpl::set_health_accelerometer_calibration(bool ok)
{
std::lock_guard<std::mutex> lock(_health_mutex);
_health.accelerometer_calibration_ok = ok;
_health.accelerometer_calibration_ok = (ok || _hitl_enabled);
}

void TelemetryImpl::set_health_magnetometer_calibration(bool ok)
{
std::lock_guard<std::mutex> lock(_health_mutex);
_health.magnetometer_calibration_ok = ok;
_health.magnetometer_calibration_ok = (ok || _hitl_enabled);
}

void TelemetryImpl::set_health_level_calibration(bool ok)
{
std::lock_guard<std::mutex> lock(_health_mutex);
_health.level_calibration_ok = ok;
_health.level_calibration_ok = (ok || _hitl_enabled);
}

void TelemetryImpl::set_rc_status(bool available, float signal_strength_percent)
Expand Down
3 changes: 3 additions & 0 deletions plugins/telemetry/telemetry_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class TelemetryImpl : public PluginImplBase {
#ifdef LEVEL_CALIBRATION
void receive_param_cal_level(bool success, float value);
#endif
void receive_param_hitl(bool success, int value);

void receive_rc_channels_timeout();

Expand Down Expand Up @@ -172,6 +173,8 @@ class TelemetryImpl : public PluginImplBase {
mutable std::mutex _rc_status_mutex;
Telemetry::RCStatus _rc_status;

std::atomic<bool> _hitl_enabled{false};

Telemetry::position_velocity_ned_callback_t _position_velocity_ned_subscription;
Telemetry::position_callback_t _position_subscription;
Telemetry::position_callback_t _home_position_subscription;
Expand Down