From cd6387d0a6dfe9df45018bfa8507620489e6faf3 Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Sat, 23 Jun 2012 17:14:59 +0300 Subject: [PATCH 1/9] Add support for more than 3-pos FlightMode switches It is now possible to have 1 to 6 flight mode switch positions (usefull for guidance, position hold and similar use). The input channel range is divided into N (1 to 6) zones and each zone represents a flight mode. Default is 3 zones (backward compatible), but more can be chosen. How to use: configure Tx mixers in a way they provide required number of different values for the same FlightMode channel. For instance, using Turnigy 9X radio with ER9X firmware, one can create a mixer like this: -100 MAX ID0 Manual R -50 MAX ID1 Stabilized1 (Rate) R 0 MAX ID2 Stabilized2 (Attitude) R 50 MAX RUD PositionHold R 100 MAX ELE ReturnToBase And set number of flight mode positions to 5. As a result, the 3-pos switch (ID0, ID1, ID2) will provide first three flight modes, the rudder D/R switch will override those and enable the 4th flight mode, and elevator D/R switch will have highest precedence and activate the 5th flight mode. This will change the ManualControlSettings objectID. --- flight/Modules/ManualControl/manualcontrol.c | 33 +- .../src/plugins/config/configinputwidget.cpp | 84 ++++- .../src/plugins/config/configinputwidget.h | 1 + .../openpilotgcs/src/plugins/config/input.ui | 354 ++++++++++++------ .../manualcontrolsettings.xml | 3 +- 5 files changed, 350 insertions(+), 125 deletions(-) diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index cc188e602..7d4ab2f8f 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -58,7 +58,6 @@ #define TASK_PRIORITY (tskIDLE_PRIORITY+4) #define UPDATE_PERIOD_MS 20 #define THROTTLE_FAILSAFE -0.1f -#define FLIGHT_MODE_LIMIT 1.0f/3.0f #define ARMED_TIME_MS 1000 #define ARMED_THRESHOLD 0.50f //safe band to allow a bit of calibration error or trim offset (in microseconds) @@ -847,30 +846,38 @@ static void processArm(ManualControlCommandData * cmd, ManualControlSettingsData } /** - * @brief Determine which of three positions the flight mode switch is in and set flight mode accordingly + * @brief Determine which of N positions the flight mode switch is in and set flight mode accordingly * @param[out] cmd Pointer to the command structure to set the flight mode in * @param[in] settings The settings which indicate which position is which mode * @param[in] flightMode the value of the switch position */ -static void processFlightMode(ManualControlSettingsData * settings, float flightMode) +static void processFlightMode(ManualControlSettingsData *settings, float flightMode) { FlightStatusData flightStatus; FlightStatusGet(&flightStatus); - uint8_t newMode; - // Note here the code is ass - if (flightMode < -FLIGHT_MODE_LIMIT) - newMode = settings->FlightModePosition[0]; - else if (flightMode > FLIGHT_MODE_LIMIT) - newMode = settings->FlightModePosition[2]; - else - newMode = settings->FlightModePosition[1]; + // Check the FlightModeNumber: it shouldn't be set higher than number of FlightModePosition elements + if ((settings->FlightModeNumber < 1) || (settings->FlightModeNumber > MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_NUMELEM)) { + AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL); + return; + } - if(flightStatus.FlightMode != newMode) { + // Scale flightMode from [-1..+1] to [0..1] range and calculate a delta + float scaledFlightMode = (flightMode + 1.0) / 2.0; + float delta = 1.0 / (float)(settings->FlightModeNumber); + float bound = delta; + + uint8_t i; + for (i = 1; i < settings->FlightModeNumber; i++, bound += delta) { + if (scaledFlightMode < bound) + break; + } + uint8_t newMode = settings->FlightModePosition[i - 1]; + + if (flightStatus.FlightMode != newMode) { flightStatus.FlightMode = newMode; FlightStatusSet(&flightStatus); } - } /** diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index ba1dbb74e..5d44a374f 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -85,6 +85,10 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent) addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos1,0); addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos2,1); addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos3,2); + addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos4,3); + addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos5,4); + addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos6,5); + addUAVObjectToWidgetRelation("ManualControlSettings","FlightModeNumber",m_config->fmsPosNum); addUAVObjectToWidgetRelation("ManualControlSettings","Stabilization1Settings",m_config->fmsSsPos1Roll,"Roll"); addUAVObjectToWidgetRelation("ManualControlSettings","Stabilization2Settings",m_config->fmsSsPos2Roll,"Roll"); @@ -99,6 +103,7 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent) addUAVObjectToWidgetRelation("ManualControlSettings","Arming",m_config->armControl); addUAVObjectToWidgetRelation("ManualControlSettings","ArmedTimeout",m_config->armTimeout,0,1000); connect( ManualControlCommand::GetInstance(getObjectManager()),SIGNAL(objectUpdated(UAVObject*)),this,SLOT(moveFMSlider())); + connect( ManualControlSettings::GetInstance(getObjectManager()),SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updatePositionSlider())); enableControls(false); populateWidgets(); @@ -1113,6 +1118,7 @@ void ConfigInputWidget::invertControls() } manualSettingsObj->setData(manualSettingsData); } + void ConfigInputWidget::moveFMSlider() { ManualControlSettings::DataFields manualSettingsDataPriv = manualSettingsObj->getData(); @@ -1139,12 +1145,78 @@ void ConfigInputWidget::moveFMSlider() valueScaled = 0; } - if(valueScaled < -(1.0 / 3.0)) - m_config->fmsSlider->setValue(-100); - else if (valueScaled > (1.0/3.0)) - m_config->fmsSlider->setValue(100); - else - m_config->fmsSlider->setValue(0); + // Bound and scale FlightMode from [-1..+1] to [0..1] range + if (valueScaled < -1.0) + valueScaled = -1.0; + if (valueScaled > 1.0) + valueScaled = 1.0; + float scaledFlightMode = (valueScaled + 1.0) / 2.0; + + // Display current channel value for tuning (in percents) + m_config->fmsValue->setText(QString::number(scaledFlightMode * 100.0, 'f', 0)); + + // Find and display the current FlightMode using the same logic as in a flight code + float delta = 1.0 / (float)(manualSettingsDataPriv.FlightModeNumber); + float bound = delta; + int i; + for (i = 1; i < manualSettingsDataPriv.FlightModeNumber; i++, bound += delta) { + if (scaledFlightMode < bound) + break; + } + m_config->fmsSlider->setValue(i - 1); +} + +void ConfigInputWidget::updatePositionSlider() +{ + ManualControlSettings::DataFields manualSettingsDataPriv = manualSettingsObj->getData(); + + switch(manualSettingsDataPriv.FlightModeNumber) { + default: + case 6: + m_config->fmsModePos6->setEnabled(true); + // pass through + case 5: + m_config->fmsModePos5->setEnabled(true); + // pass through + case 4: + m_config->fmsModePos4->setEnabled(true); + // pass through + case 3: + m_config->fmsModePos3->setEnabled(true); + // pass through + case 2: + m_config->fmsModePos2->setEnabled(true); + // pass through + case 1: + m_config->fmsModePos1->setEnabled(true); + // pass through + case 0: + break; + } + + switch(manualSettingsDataPriv.FlightModeNumber) { + case 0: + m_config->fmsModePos1->setEnabled(false); + // pass through + case 1: + m_config->fmsModePos2->setEnabled(false); + // pass through + case 2: + m_config->fmsModePos3->setEnabled(false); + // pass through + case 3: + m_config->fmsModePos4->setEnabled(false); + // pass through + case 4: + m_config->fmsModePos5->setEnabled(false); + // pass through + case 5: + m_config->fmsModePos6->setEnabled(false); + // pass through + case 6: + default: + break; + } } void ConfigInputWidget::updateCalibration() diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.h b/ground/openpilotgcs/src/plugins/config/configinputwidget.h index eeb6178fc..418fbdfee 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.h @@ -146,6 +146,7 @@ private slots: void moveSticks(); void dimOtherControls(bool value); void moveFMSlider(); + void updatePositionSlider(); void invertControls(); void simpleCalibration(bool state); void updateCalibration(); diff --git a/ground/openpilotgcs/src/plugins/config/input.ui b/ground/openpilotgcs/src/plugins/config/input.ui index 422904bb5..650219a92 100644 --- a/ground/openpilotgcs/src/plugins/config/input.ui +++ b/ground/openpilotgcs/src/plugins/config/input.ui @@ -17,7 +17,7 @@ - 0 + 1 @@ -204,31 +204,12 @@ Flight Mode Switch Settings - - - - 310 - 30 - 201 - 17 - - - - - 75 - true - - - - for multirotors! - - 30 - 160 - 451 + 260 + 541 161 @@ -384,19 +365,6 @@ margin:1px; - - - - Qt::Vertical - - - - 20 - 20 - - - - @@ -414,25 +382,167 @@ margin:1px; + + + + Qt::Vertical + + + + 20 + 20 + + + + 30 - 30 - 451 - 121 + 20 + 541 + 211 FlightMode Switch Positions + + + + 100 + 140 + 151 + 26 + + + + Qt::StrongFocus + + + + + + 100 + 110 + 151 + 26 + + + + Qt::StrongFocus + + + Select the stabilization mode on this position (manual/stabilized/auto) + + + + + + 10 + 115 + 62 + 17 + + + + Pos. 4 + + + + + + 100 + 170 + 151 + 26 + + + + Qt::StrongFocus + + + + + + 10 + 145 + 62 + 17 + + + + Pos. 5 + + + + + + 10 + 175 + 62 + 17 + + + + Pos. 6 + + + + + false + + + + 70 + 28 + 20 + 160 + + + + Qt::StrongFocus + + + This slider moves when you move the flight mode switch +on your remote. Setup the flightmode channel on the RC Input tab +if you have not done so already. + + + 0 + + + 5 + + + 10 + + + 0 + + + 0 + + + Qt::Vertical + + + true + + + QSlider::TicksBelow + + + 1 + + 100 - 55 + 50 151 26 @@ -445,7 +555,20 @@ margin:1px; 100 - 25 + 80 + 151 + 26 + + + + Qt::StrongFocus + + + + + + 100 + 20 151 26 @@ -457,37 +580,11 @@ margin:1px; Select the stabilization mode on this position (manual/stabilized/auto) - + - 10 - 30 - 62 - 17 - - - - Pos. 3 - - - - - - 100 - 85 - 151 - 26 - - - - Qt::StrongFocus - - - - - - 10 - 60 + 11 + 55 62 17 @@ -496,11 +593,11 @@ margin:1px; Pos. 2 - + - 10 - 90 + 11 + 25 62 17 @@ -509,55 +606,81 @@ margin:1px; Pos. 1 - - - false - + - 70 - 30 - 20 - 81 + 11 + 85 + 62 + 17 - - Qt::StrongFocus + + Pos. 3 + + + + + + 410 + 20 + 61 + 20 + - This slider moves when you move the flight mode switch -on your remote. Setup the flightmode channel on the RC Input tab -if you have not done so already. + Number of positions your FlightMode switch has. + +Default is 3. + +It will be 2 or 3 for most of setups, but it also can be up to 6. +In that case you have to configure your radio mixers so the whole range +from min to max is split into N equal intervals, and you may set arbitrary +channel value for each flight mode. - -100 + 1 - 100 + 6 - - 10 + + 3 - - -100 + + + + + 270 + 20 + 141 + 16 + - - Qt::Vertical + + Number of switch positions: - - QSlider::TicksBelow + + + + + 270 + 50 + 141 + 16 + - - 100 + + Channel value (0..100): - 270 - 30 - 141 - 31 + 300 + 130 + 191 + 30 @@ -567,13 +690,37 @@ if you have not done so already. - Warning: avoid "Manual" + Avoid "Manual" for multirotors! true + + + + 410 + 51 + 46 + 13 + + + + FlightMode channel value is shown here for reference. + +Whole range [0..100] in spit into number of intervals - one per +FlightMode (switch position). + +Hint: make sure that you have the FlightMode channel neutral +value defined. + + + 0 + + + groupBox_2 + groupBox @@ -763,9 +910,6 @@ Applies and Saves all settings to SD fmsSlider - fmsModePos3 - fmsModePos2 - fmsModePos1 fmsSsPos1Roll fmsSsPos1Pitch fmsSsPos1Yaw diff --git a/shared/uavobjectdefinition/manualcontrolsettings.xml b/shared/uavobjectdefinition/manualcontrolsettings.xml index c2c8ec715..09d4ca618 100644 --- a/shared/uavobjectdefinition/manualcontrolsettings.xml +++ b/shared/uavobjectdefinition/manualcontrolsettings.xml @@ -23,7 +23,8 @@ - + + From 02fa6fde094149b76ef4ae4f480896bf3cc784ad Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Mon, 25 Jun 2012 00:30:42 +0300 Subject: [PATCH 2/9] Optimize FlightMode switch position calculation --- flight/Modules/ManualControl/manualcontrol.c | 15 +++++---------- .../src/plugins/config/configinputwidget.cpp | 18 ++++++++---------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index 7d4ab2f8f..f9afe75b0 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -862,17 +862,12 @@ static void processFlightMode(ManualControlSettingsData *settings, float flightM return; } - // Scale flightMode from [-1..+1] to [0..1] range and calculate a delta - float scaledFlightMode = (flightMode + 1.0) / 2.0; - float delta = 1.0 / (float)(settings->FlightModeNumber); - float bound = delta; + // Convert flightMode value into the switch position in the range [0..N-1] + uint8_t pos = (uint8_t)((flightMode + 1.0f) * settings->FlightModeNumber) >> 1; + if (pos >= settings->FlightModeNumber) + pos = settings->FlightModeNumber - 1; - uint8_t i; - for (i = 1; i < settings->FlightModeNumber; i++, bound += delta) { - if (scaledFlightMode < bound) - break; - } - uint8_t newMode = settings->FlightModePosition[i - 1]; + uint8_t newMode = settings->FlightModePosition[pos]; if (flightStatus.FlightMode != newMode) { flightStatus.FlightMode = newMode; diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index 5d44a374f..b06a750f1 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -1148,22 +1148,20 @@ void ConfigInputWidget::moveFMSlider() // Bound and scale FlightMode from [-1..+1] to [0..1] range if (valueScaled < -1.0) valueScaled = -1.0; + else if (valueScaled > 1.0) valueScaled = 1.0; - float scaledFlightMode = (valueScaled + 1.0) / 2.0; // Display current channel value for tuning (in percents) + float scaledFlightMode = (valueScaled + 1.0) / 2.0; m_config->fmsValue->setText(QString::number(scaledFlightMode * 100.0, 'f', 0)); - // Find and display the current FlightMode using the same logic as in a flight code - float delta = 1.0 / (float)(manualSettingsDataPriv.FlightModeNumber); - float bound = delta; - int i; - for (i = 1; i < manualSettingsDataPriv.FlightModeNumber; i++, bound += delta) { - if (scaledFlightMode < bound) - break; - } - m_config->fmsSlider->setValue(i - 1); + // Convert flightMode value into the switch position in the range [0..N-1] + // This should use the same logic as flight code to be consistent + uint8_t pos = (uint8_t)((valueScaled + 1.0) * manualSettingsDataPriv.FlightModeNumber) >> 1; + if (pos >= manualSettingsDataPriv.FlightModeNumber) + pos = manualSettingsDataPriv.FlightModeNumber - 1; + m_config->fmsSlider->setValue(pos); } void ConfigInputWidget::updatePositionSlider() From 2c896c9e912af81f07b81ab94a61357ddf0872f4 Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Mon, 25 Jun 2012 01:52:06 +0300 Subject: [PATCH 3/9] Do not care about FlightMode channel if only one flight mode configured --- flight/Modules/ManualControl/manualcontrol.c | 19 ++++++++----------- .../src/plugins/config/configinputwidget.cpp | 3 ++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index f9afe75b0..911d96e7d 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -235,19 +235,23 @@ static void manualControlTask(void *parameters) settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE || settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE || settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE || - settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE || // Check all channel mappings are valid cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL] == (uint16_t) PIOS_RCVR_INVALID || cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH] == (uint16_t) PIOS_RCVR_INVALID || cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW] == (uint16_t) PIOS_RCVR_INVALID || cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE] == (uint16_t) PIOS_RCVR_INVALID || - cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] == (uint16_t) PIOS_RCVR_INVALID || - // Check the driver is exists + // Check the driver exists cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_ROLL] == (uint16_t) PIOS_RCVR_NODRIVER || cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_PITCH] == (uint16_t) PIOS_RCVR_NODRIVER || cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_YAW] == (uint16_t) PIOS_RCVR_NODRIVER || cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_THROTTLE] == (uint16_t) PIOS_RCVR_NODRIVER || - cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] == (uint16_t) PIOS_RCVR_NODRIVER) { + // Check the FlightModeNumber is valid + settings.FlightModeNumber < 1 || settings.FlightModeNumber > MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_NUMELEM || + // Similar checks for FlightMode channel but only if more than one flight mode has been set. Otherwise don't care + ((settings.FlightModeNumber > 1) && ( + settings.ChannelGroups[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE || + cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] == (uint16_t) PIOS_RCVR_INVALID || + cmd.Channel[MANUALCONTROLSETTINGS_CHANNELGROUPS_FLIGHTMODE] == (uint16_t) PIOS_RCVR_NODRIVER))) { AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL); cmd.Connected = MANUALCONTROLCOMMAND_CONNECTED_FALSE; @@ -356,7 +360,6 @@ static void manualControlTask(void *parameters) AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_WARNING); } - processFlightMode(&settings, flightMode); } @@ -856,12 +859,6 @@ static void processFlightMode(ManualControlSettingsData *settings, float flightM FlightStatusData flightStatus; FlightStatusGet(&flightStatus); - // Check the FlightModeNumber: it shouldn't be set higher than number of FlightModePosition elements - if ((settings->FlightModeNumber < 1) || (settings->FlightModeNumber > MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_NUMELEM)) { - AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL); - return; - } - // Convert flightMode value into the switch position in the range [0..N-1] uint8_t pos = (uint8_t)((flightMode + 1.0f) * settings->FlightModeNumber) >> 1; if (pos >= settings->FlightModeNumber) diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index b06a750f1..550e55129 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -637,7 +637,8 @@ void ConfigInputWidget::setChannel(int newChan) m_config->wzText->setText(QString(tr("Please move each control once at a time according to the instructions and picture below.\n\n" "Move the %1 stick")).arg(manualSettingsObj->getField("ChannelGroups")->getElementNames().at(newChan))); - if(manualSettingsObj->getField("ChannelGroups")->getElementNames().at(newChan).contains("Accessory")) { + if(manualSettingsObj->getField("ChannelGroups")->getElementNames().at(newChan).contains("Accessory") || + manualSettingsObj->getField("ChannelGroups")->getElementNames().at(newChan).contains("FlightMode")) { m_config->wzNext->setEnabled(true); m_config->wzText->setText(m_config->wzText->text() + tr(" or click next to skip this channel.")); } else From 727e67d7fde695c8c4befd2a14d3ac9d64362de9 Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Mon, 25 Jun 2012 11:41:42 +0300 Subject: [PATCH 4/9] Even more optimize FlightMode switch position calculation This runs in a high frequency loop and should use as little of floating point as possible. Thanks to Kenn for the idea. --- flight/Modules/ManualControl/manualcontrol.c | 2 +- ground/openpilotgcs/src/plugins/config/configinputwidget.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index 911d96e7d..cad5d065d 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -860,7 +860,7 @@ static void processFlightMode(ManualControlSettingsData *settings, float flightM FlightStatusGet(&flightStatus); // Convert flightMode value into the switch position in the range [0..N-1] - uint8_t pos = (uint8_t)((flightMode + 1.0f) * settings->FlightModeNumber) >> 1; + uint8_t pos = ((int16_t)(flightMode * 256.0f) + 256) * settings->FlightModeNumber >> 9; if (pos >= settings->FlightModeNumber) pos = settings->FlightModeNumber - 1; diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index 550e55129..75c390643 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -1158,8 +1158,8 @@ void ConfigInputWidget::moveFMSlider() m_config->fmsValue->setText(QString::number(scaledFlightMode * 100.0, 'f', 0)); // Convert flightMode value into the switch position in the range [0..N-1] - // This should use the same logic as flight code to be consistent - uint8_t pos = (uint8_t)((valueScaled + 1.0) * manualSettingsDataPriv.FlightModeNumber) >> 1; + // This uses the same optimized computation as flight code to be consistent + uint8_t pos = ((int16_t)(valueScaled * 256) + 256) * manualSettingsDataPriv.FlightModeNumber >> 9; if (pos >= manualSettingsDataPriv.FlightModeNumber) pos = manualSettingsDataPriv.FlightModeNumber - 1; m_config->fmsSlider->setValue(pos); From 3cd293a5e623f4ce9bc30b85e9b6928d48c2efbb Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Tue, 3 Jul 2012 11:04:18 +0300 Subject: [PATCH 5/9] Cosmetic FlightMode GUI fix (OPReview-228) --- ground/openpilotgcs/src/plugins/config/input.ui | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ground/openpilotgcs/src/plugins/config/input.ui b/ground/openpilotgcs/src/plugins/config/input.ui index 650219a92..4e022c021 100644 --- a/ground/openpilotgcs/src/plugins/config/input.ui +++ b/ground/openpilotgcs/src/plugins/config/input.ui @@ -410,6 +410,9 @@ margin:1px; FlightMode Switch Positions + + false + 100 @@ -423,6 +426,9 @@ margin:1px; + + false + 100 @@ -452,6 +458,9 @@ margin:1px; + + false + 100 From 12106c55492f0295e106b7aeda587ea5e16bd2df Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Tue, 3 Jul 2012 17:20:10 +0300 Subject: [PATCH 6/9] FlightMode GUI: replace numeric value by slider --- .../src/plugins/config/configinputwidget.cpp | 7 +- .../openpilotgcs/src/plugins/config/input.ui | 88 +++++++++++-------- 2 files changed, 58 insertions(+), 37 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index 75c390643..0c952ca67 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -1123,7 +1123,7 @@ void ConfigInputWidget::invertControls() void ConfigInputWidget::moveFMSlider() { ManualControlSettings::DataFields manualSettingsDataPriv = manualSettingsObj->getData(); - ManualControlCommand::DataFields manualCommandDataPriv=manualCommandObj->getData(); + ManualControlCommand::DataFields manualCommandDataPriv = manualCommandObj->getData(); float valueScaled; int chMin = manualSettingsDataPriv.ChannelMin[ManualControlSettings::CHANNELMIN_FLIGHTMODE]; @@ -1155,7 +1155,10 @@ void ConfigInputWidget::moveFMSlider() // Display current channel value for tuning (in percents) float scaledFlightMode = (valueScaled + 1.0) / 2.0; - m_config->fmsValue->setText(QString::number(scaledFlightMode * 100.0, 'f', 0)); + m_config->fmsChannelSlider->setValue(scaledFlightMode * 100.0 + / ManualControlSettings::FLIGHTMODEPOSITION_NUMELEM * manualSettingsDataPriv.FlightModeNumber); + m_config->fmsChannelSlider->setToolTip( + "Current flight mode channel value: " + QString::number(scaledFlightMode * 100.0, 'f', 0) + '%'); // Convert flightMode value into the switch position in the range [0..N-1] // This uses the same optimized computation as flight code to be consistent diff --git a/ground/openpilotgcs/src/plugins/config/input.ui b/ground/openpilotgcs/src/plugins/config/input.ui index 4e022c021..f219d77c9 100644 --- a/ground/openpilotgcs/src/plugins/config/input.ui +++ b/ground/openpilotgcs/src/plugins/config/input.ui @@ -516,8 +516,9 @@ margin:1px; This slider moves when you move the flight mode switch -on your remote. Setup the flightmode channel on the RC Input tab -if you have not done so already. +on your remote. It shows currently active flight mode. + +Setup the flight mode channel on the RC Input tab if you have not done so already. 0 @@ -631,7 +632,7 @@ if you have not done so already. - 410 + 464 20 61 20 @@ -660,8 +661,8 @@ channel value for each flight mode. - 270 - 20 + 305 + 22 141 16 @@ -670,24 +671,11 @@ channel value for each flight mode. Number of switch positions: - - - - 270 - 50 - 141 - 16 - - - - Channel value (0..100): - - - 300 - 130 + 310 + 90 191 30 @@ -705,26 +693,56 @@ channel value for each flight mode. true - + + + false + - 410 - 51 - 46 - 13 + 265 + 16 + 20 + 181 - - FlightMode channel value is shown here for reference. - -Whole range [0..100] in spit into number of intervals - one per -FlightMode (switch position). - -Hint: make sure that you have the FlightMode channel neutral -value defined. + + Qt::StrongFocus - - 0 + + This slider shows the real value of your remote channel. + + + 0 + + + 100 + + + 1 + + + 10 + + + 0 + + + 0 + + + Qt::Vertical + + + true + + + false + + + QSlider::NoTicks + + + 1 From 4a75e226eb1c3bf8c4c31e385d8752eb27d9a7e1 Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Wed, 4 Jul 2012 00:06:55 +0300 Subject: [PATCH 7/9] FlightMode GUI: attempt to fix label overlap on linux and OSX --- ground/openpilotgcs/src/plugins/config/input.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/input.ui b/ground/openpilotgcs/src/plugins/config/input.ui index f219d77c9..b62ae11c4 100644 --- a/ground/openpilotgcs/src/plugins/config/input.ui +++ b/ground/openpilotgcs/src/plugins/config/input.ui @@ -632,7 +632,7 @@ Setup the flight mode channel on the RC Input tab if you have not done so alread - 464 + 440 20 61 20 @@ -668,7 +668,7 @@ channel value for each flight mode. - Number of switch positions: + Number of modes: From dd398e9bd5ee3a8de13836cc48dfdf8c0f9793e4 Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Wed, 4 Jul 2012 00:13:20 +0300 Subject: [PATCH 8/9] FlightMode GUI: update right slider on settings change --- ground/openpilotgcs/src/plugins/config/configinputwidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index 0c952ca67..d63f113de 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -103,6 +103,7 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent) addUAVObjectToWidgetRelation("ManualControlSettings","Arming",m_config->armControl); addUAVObjectToWidgetRelation("ManualControlSettings","ArmedTimeout",m_config->armTimeout,0,1000); connect( ManualControlCommand::GetInstance(getObjectManager()),SIGNAL(objectUpdated(UAVObject*)),this,SLOT(moveFMSlider())); + connect( ManualControlSettings::GetInstance(getObjectManager()),SIGNAL(objectUpdated(UAVObject*)),this,SLOT(moveFMSlider())); connect( ManualControlSettings::GetInstance(getObjectManager()),SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updatePositionSlider())); enableControls(false); From 954cd9febc06a433deed421df7f6d180cc38fa6c Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Wed, 4 Jul 2012 07:46:38 +0300 Subject: [PATCH 9/9] FlightMode GUI: remove ugly right slider --- .../src/plugins/config/configinputwidget.cpp | 8 --- .../openpilotgcs/src/plugins/config/input.ui | 60 ++----------------- 2 files changed, 4 insertions(+), 64 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index d63f113de..7952b3d70 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -103,7 +103,6 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent) addUAVObjectToWidgetRelation("ManualControlSettings","Arming",m_config->armControl); addUAVObjectToWidgetRelation("ManualControlSettings","ArmedTimeout",m_config->armTimeout,0,1000); connect( ManualControlCommand::GetInstance(getObjectManager()),SIGNAL(objectUpdated(UAVObject*)),this,SLOT(moveFMSlider())); - connect( ManualControlSettings::GetInstance(getObjectManager()),SIGNAL(objectUpdated(UAVObject*)),this,SLOT(moveFMSlider())); connect( ManualControlSettings::GetInstance(getObjectManager()),SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updatePositionSlider())); enableControls(false); @@ -1154,13 +1153,6 @@ void ConfigInputWidget::moveFMSlider() if (valueScaled > 1.0) valueScaled = 1.0; - // Display current channel value for tuning (in percents) - float scaledFlightMode = (valueScaled + 1.0) / 2.0; - m_config->fmsChannelSlider->setValue(scaledFlightMode * 100.0 - / ManualControlSettings::FLIGHTMODEPOSITION_NUMELEM * manualSettingsDataPriv.FlightModeNumber); - m_config->fmsChannelSlider->setToolTip( - "Current flight mode channel value: " + QString::number(scaledFlightMode * 100.0, 'f', 0) + '%'); - // Convert flightMode value into the switch position in the range [0..N-1] // This uses the same optimized computation as flight code to be consistent uint8_t pos = ((int16_t)(valueScaled * 256) + 256) * manualSettingsDataPriv.FlightModeNumber >> 9; diff --git a/ground/openpilotgcs/src/plugins/config/input.ui b/ground/openpilotgcs/src/plugins/config/input.ui index b62ae11c4..c116a812f 100644 --- a/ground/openpilotgcs/src/plugins/config/input.ui +++ b/ground/openpilotgcs/src/plugins/config/input.ui @@ -632,7 +632,7 @@ Setup the flight mode channel on the RC Input tab if you have not done so alread - 440 + 458 20 61 20 @@ -661,21 +661,21 @@ channel value for each flight mode. - 305 + 277 22 141 16 - Number of modes: + Number of flight modes: 310 - 90 + 120 191 30 @@ -693,58 +693,6 @@ channel value for each flight mode. true - - - false - - - - 265 - 16 - 20 - 181 - - - - Qt::StrongFocus - - - This slider shows the real value of your remote channel. - - - 0 - - - 100 - - - 1 - - - 10 - - - 0 - - - 0 - - - Qt::Vertical - - - true - - - false - - - QSlider::NoTicks - - - 1 - - groupBox_2 groupBox