diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 0d0dc90088402aae90657867c7d72d6b43b55ff0..0dbda9bdc13eb2104cd5a67951d26e7a4829bd2a 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -1770,8 +1770,31 @@ void UAS::executeCommand(MAV_CMD command) { mavlink_message_t msg; mavlink_command_t cmd; - //mavlink_msg_action_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), 0, action); - // Send message twice to increase chance that it reaches its goal + cmd.command = (uint8_t)command; + cmd.confirmation = 0; + cmd.param1 = 0.0f; + cmd.param2 = 0.0f; + cmd.param3 = 0.0f; + cmd.param4 = 0.0f; + cmd.target_system = uasId; + cmd.target_component = 0; + mavlink_msg_command_encode(mavlink->getSystemId(), mavlink->getComponentId(), &msg, &cmd); + sendMessage(msg); +} + +void UAS::executeCommand(MAV_CMD command, int confirmation, float param1, float param2, float param3, float param4, int component) +{ + mavlink_message_t msg; + mavlink_command_t cmd; + cmd.command = (uint8_t)command; + cmd.confirmation = confirmation; + cmd.param1 = param1; + cmd.param2 = param2; + cmd.param3 = param3; + cmd.param4 = param4; + cmd.target_system = uasId; + cmd.target_component = component; + mavlink_msg_command_encode(mavlink->getSystemId(), mavlink->getComponentId(), &msg, &cmd); sendMessage(msg); } diff --git a/src/uas/UAS.h b/src/uas/UAS.h index b38db988d7d6a7e4e3f2e1d09b57e101a5cfd970..37cc722a89418cd0adc1752c8690fa2d8bde46f5 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -216,6 +216,8 @@ public slots: void setAction(MAV_ACTION action); /** @brief Executes a command **/ void executeCommand(MAV_CMD command); + /** @brief Executes a command **/ + void executeCommand(MAV_CMD command, int confirmation, float param1, float param2, float param3, float param4, int component); /** @brief Set the current battery type and voltages */ void setBatterySpecs(const QString& specs); /** @brief Get the current battery type and specs */ diff --git a/src/uas/UASInterface.h b/src/uas/UASInterface.h index 4399314400b07cb4149ac7f98abae70bac055504..339412c15aa16c56d70387b4eb07c8b8f9b412ad 100644 --- a/src/uas/UASInterface.h +++ b/src/uas/UASInterface.h @@ -191,6 +191,8 @@ public slots: virtual void setAction(MAV_ACTION action) = 0; /** @brief Execute command immediately **/ virtual void executeCommand(MAV_CMD command) = 0; + /** @brief Executes a command **/ + virtual void executeCommand(MAV_CMD command, int confirmation, float param1, float param2, float param3, float param4, int component) = 0; /** @brief Selects the airframe */ virtual void setAirframe(int airframe) = 0; diff --git a/src/ui/designer/QGCCommandButton.cc b/src/ui/designer/QGCCommandButton.cc index 00bd443a247a4b48c57081775e1b5f67ff8d4806..731e1c1783a8e279a39f6721b3d826e0c1735669 100644 --- a/src/ui/designer/QGCCommandButton.cc +++ b/src/ui/designer/QGCCommandButton.cc @@ -5,7 +5,7 @@ #include "UASManager.h" QGCCommandButton::QGCCommandButton(QWidget *parent) : - QGCToolWidgetItem("CommandButton", parent), + QGCToolWidgetItem("Command Button", parent), ui(new Ui::QGCCommandButton), uas(NULL) { @@ -21,6 +21,13 @@ QGCCommandButton::QGCCommandButton(QWidget *parent) : ui->editFinishButton->hide(); ui->editNameLabel->hide(); ui->editButtonName->hide(); + ui->editConfirmationCheckBox->hide(); + ui->editComponentSpinBox->hide(); + ui->editParamsVisibleCheckBox->hide(); + ui->editParam1SpinBox->hide(); + ui->editParam2SpinBox->hide(); + ui->editParam3SpinBox->hide(); + ui->editParam4SpinBox->hide(); // Add commands to combo box ui->editCommandComboBox->addItem("DO: Control Video", MAV_CMD_DO_CONTROL_VIDEO); @@ -37,10 +44,16 @@ void QGCCommandButton::sendCommand() if (QGCToolWidgetItem::uas) { // FIXME - int index = 0;//ui->editCommandComboBox->userData() + int index = ui->editCommandComboBox->itemData(ui->editCommandComboBox->currentIndex()).toInt(); MAV_CMD command = static_cast(index); - - QGCToolWidgetItem::uas->executeCommand(command); + int confirm = (ui->editConfirmationCheckBox->isChecked()) ? 1 : 0; + float param1 = ui->editParam1SpinBox->value(); + float param2 = ui->editParam2SpinBox->value(); + float param3 = ui->editParam3SpinBox->value(); + float param4 = ui->editParam4SpinBox->value(); + int component = ui->editComponentSpinBox->value(); + + QGCToolWidgetItem::uas->executeCommand(command, confirm, param1, param2, param3, param4, component); } else { @@ -59,6 +72,13 @@ void QGCCommandButton::startEditMode() ui->editFinishButton->show(); ui->editNameLabel->show(); ui->editButtonName->show(); + ui->editConfirmationCheckBox->show(); + ui->editComponentSpinBox->show(); + ui->editParamsVisibleCheckBox->show(); + ui->editParam1SpinBox->show(); + ui->editParam2SpinBox->show(); + ui->editParam3SpinBox->show(); + ui->editParam4SpinBox->show(); isInEditMode = true; } @@ -68,6 +88,16 @@ void QGCCommandButton::endEditMode() ui->editFinishButton->hide(); ui->editNameLabel->hide(); ui->editButtonName->hide(); + ui->editConfirmationCheckBox->hide(); + ui->editComponentSpinBox->hide(); + ui->editParamsVisibleCheckBox->hide(); + if (!ui->editParamsVisibleCheckBox->isChecked()) + { + ui->editParam1SpinBox->hide(); + ui->editParam2SpinBox->hide(); + ui->editParam3SpinBox->hide(); + ui->editParam4SpinBox->hide(); + } // Write to settings emit editingFinished(); @@ -81,6 +111,7 @@ void QGCCommandButton::writeSettings(QSettings& settings) settings.setValue("QGC_ACTION_BUTTON_DESCRIPTION", ui->nameLabel->text()); settings.setValue("QGC_ACTION_BUTTON_BUTTONTEXT", ui->commandButton->text()); settings.setValue("QGC_ACTION_BUTTON_ACTIONID", ui->editCommandComboBox->currentIndex()); + settings.setValue("QGC_COMMAND_BUTTON_PARAMS_VISIBLE", ui->editParamsVisibleCheckBox->isChecked()); settings.sync(); } @@ -93,5 +124,20 @@ void QGCCommandButton::readSettings(const QSettings& settings) ui->nameLabel->setText(settings.value("QGC_ACTION_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); ui->commandButton->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString()); ui->editCommandComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt()); + ui->editParamsVisibleCheckBox->setChecked(settings.value("QGC_COMMAND_BUTTON_PARAMS_VISIBLE").toBool()); + if (ui->editParamsVisibleCheckBox->isChecked()) + { + ui->editParam1SpinBox->show(); + ui->editParam2SpinBox->show(); + ui->editParam3SpinBox->show(); + ui->editParam4SpinBox->show(); + } + else + { + ui->editParam1SpinBox->hide(); + ui->editParam2SpinBox->hide(); + ui->editParam3SpinBox->hide(); + ui->editParam4SpinBox->hide(); + } qDebug() << "DONE READING SETTINGS"; } diff --git a/src/ui/designer/QGCCommandButton.ui b/src/ui/designer/QGCCommandButton.ui index 3476c96ab8c72df9c3a8d7986d99ebbc4a47323f..08037c8a3a72adf0f8f0fbd1dc5d9976eb11e7bf 100644 --- a/src/ui/designer/QGCCommandButton.ui +++ b/src/ui/designer/QGCCommandButton.ui @@ -6,55 +6,39 @@ 0 0 - 400 - 111 + 688 + 190 Form - - - - - - 50 - 0 - - - - Description - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + + - + Done - + Unnamed - + Description - + @@ -67,6 +51,132 @@ + + + + Component ID: + + + 0 + + + 255 + + + + + + + Set the confirm flag for this button. Some commands require that first one command is sent without confirm flag and then a second, equal command with confirm flag. This ensures safety. + + + Set CONFIRM flag + + + + + + + + + PARAM1 Value as defined in MAV_CMD list + + + PARAM1 Value as defined in MAV_CMD list + + + P1 + + + -2147483647.000000000000000 + + + 2147483647.000000000000000 + + + + + + + PARAM2 Value as defined in MAV_CMD list + + + PARAM2 Value as defined in MAV_CMD list + + + P2: + + + -2147483647.000000000000000 + + + 0.000000000000000 + + + + + + + PARAM3 Value as defined in MAV_CMD list + + + PARAM3 Value as defined in MAV_CMD list + + + P3: + + + -2147483647.000000000000000 + + + 2147483647.000000000000000 + + + + + + + PARAM4 Value as defined in MAV_CMD list + + + PARAM4 Value as defined in MAV_CMD list + + + P4: + + + -2147483647.000000000000000 + + + 2147483647.000000000000000 + + + + + + + + + + 50 + 0 + + + + Description + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Keep parameters visible + + +