From 1db7551f8b8d4782dabf44a8f1d373059e12bca6 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Thu, 19 Jun 2014 19:32:11 +0200 Subject: [PATCH] Prevent the system from sending a stop HIL command if HIL is not actually active --- src/uas/UAS.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index bb6e3c2..03f0837 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -2867,16 +2867,19 @@ void UAS::toggleArmedState() void UAS::goAutonomous() { setMode((base_mode & ~(MAV_MODE_FLAG_MANUAL_INPUT_ENABLED)) | (MAV_MODE_FLAG_AUTO_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED), 0); + qDebug() << __FILE__ << __LINE__ << "Going autonomous"; } void UAS::goManual() { setMode((base_mode & ~(MAV_MODE_FLAG_AUTO_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED)) | MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, 0); + qDebug() << __FILE__ << __LINE__ << "Going manual"; } void UAS::toggleAutonomy() { setMode(base_mode ^ MAV_MODE_FLAG_AUTO_ENABLED ^ MAV_MODE_FLAG_MANUAL_INPUT_ENABLED ^ MAV_MODE_FLAG_GUIDED_ENABLED ^ MAV_MODE_FLAG_STABILIZE_ENABLED, 0); + qDebug() << __FILE__ << __LINE__ << "Toggling autonomy"; } /** @@ -3330,6 +3333,7 @@ void UAS::startHil() hilEnabled = true; sensorHil = false; setMode(base_mode | MAV_MODE_FLAG_HIL_ENABLED, custom_mode); + qDebug() << __FILE__ << __LINE__ << "HIL is onboard not enabled, trying to enable."; // Connect HIL simulation link simulation->connectSimulation(); } @@ -3339,8 +3343,11 @@ void UAS::startHil() */ void UAS::stopHil() { - if (simulation) simulation->disconnectSimulation(); - setMode(base_mode & ~MAV_MODE_FLAG_HIL_ENABLED, custom_mode); + if (simulation && simulation->isConnected()) { + simulation->disconnectSimulation(); + setMode(base_mode & ~MAV_MODE_FLAG_HIL_ENABLED, custom_mode); + qDebug() << __FILE__ << __LINE__ << "HIL is onboard not enabled, trying to disable."; + } hilEnabled = false; sensorHil = false; }