From 348087f986fc25cbac533ecc23059cdf9713c93d Mon Sep 17 00:00:00 2001 From: tecnosapiens Date: Wed, 17 Nov 2010 08:55:04 -0600 Subject: [PATCH] add mavlink message a fuctions to send PDI values --- src/uas/SlugsMAV.cc | 7 + src/uas/SlugsMAV.h | 4 + src/ui/MainWindow.cc | 1 + src/ui/SlugsPIDControl.cpp | 262 ++++++++++++++++++++++++++++++++++++- src/ui/SlugsPIDControl.h | 167 ++++++++++++++++++++++- src/ui/SlugsPIDControl.ui | 19 ++- 6 files changed, 444 insertions(+), 16 deletions(-) diff --git a/src/uas/SlugsMAV.cc b/src/uas/SlugsMAV.cc index 680221027..b016d2089 100644 --- a/src/uas/SlugsMAV.cc +++ b/src/uas/SlugsMAV.cc @@ -297,6 +297,13 @@ void SlugsMAV::receiveMessage(LinkInterface* link, mavlink_message_t message) break; } + case MAVLINK_MSG_ID_ACTION_ACK: + { + mavlink_action_ack_t ack; + + mavlink_msg_action_ack_decode(&message,&ack); + emit slugsActionAck(uasId,ack.action,ack.result); + } // case MAVLINK_MSG_ID_MID_LVL_CMDS://180 // { diff --git a/src/uas/SlugsMAV.h b/src/uas/SlugsMAV.h index 75d55d29d..a4ee35bfc 100644 --- a/src/uas/SlugsMAV.h +++ b/src/uas/SlugsMAV.h @@ -135,6 +135,10 @@ signals: uint8_t gpsvisSat, quint64 time); + void slugsActionAck(int systemId, + uint8_t action, + uint8_t result); + diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 0cc31a7c6..eb1ba7f90 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -228,6 +228,7 @@ void MainWindow::connectWidgets() connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), dynamic_cast(slugsHilSimWidget->widget()), SLOT(activeUasSet(UASInterface*)) ); } + } void MainWindow::arrangeCenterStack() diff --git a/src/ui/SlugsPIDControl.cpp b/src/ui/SlugsPIDControl.cpp index 23a2a284a..109703cf0 100644 --- a/src/ui/SlugsPIDControl.cpp +++ b/src/ui/SlugsPIDControl.cpp @@ -5,29 +5,93 @@ #include #include #include +#include +#include +#include "LinkManager.h" SlugsPIDControl::SlugsPIDControl(QWidget *parent) : QWidget(parent), ui(new Ui::SlugsPIDControl) { ui->setupUi(this); + + connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(activeUasSet(UASInterface*))); + + activeUAS = NULL; + + setRedColorStyle(); setGreenColorStyle(); - connect_set_pushButtons(); - connect_AirSpeed_LineEdit(); + + + +// connect_set_pushButtons(); +// connect_AirSpeed_LineEdit(); +// connect_PitchFollowei_LineEdit(); +// connect_RollControl_LineEdit(); +// connect_HeigthError_LineEdit(); +// connect_YawDamper_LineEdit(); +// connect_Pitch2dT_LineEdit(); } +/** + * @brief Called when the a new UAS is set to active. + * + * Called when the a new UAS is set to active. + * + * @param uas The new active UAS + */ +void SlugsPIDControl::activeUasSet(UASInterface* uas) +{ + SlugsMAV* slugsMav = dynamic_cast(uas); + + if (slugsMav != NULL) + { + connect(slugsMav,SIGNAL(slugsActionAck(int,uint8_t,uint8_t)),this,SLOT(recibeMensaje(int,uint8_t,uint8_t))); + } + + // Set this UAS as active if it is the first one + if(activeUAS == 0) + { + activeUAS = uas; + systemId = activeUAS->getUASID(); + connect_editLinesPDIvalues(); + + //qDebug()<<"------------------->Active UAS ID: "<getUASID(); + } + +} + +/** + * @brief Connect Edition Lines for PID Values + * + * @param + */ +void SlugsPIDControl::connect_editLinesPDIvalues() +{ + if(activeUAS) + { + connect_set_pushButtons(); + connect_AirSpeed_LineEdit(); + connect_PitchFollowei_LineEdit(); + connect_RollControl_LineEdit(); + connect_HeigthError_LineEdit(); + connect_YawDamper_LineEdit(); + connect_Pitch2dT_LineEdit(); + } +} + SlugsPIDControl::~SlugsPIDControl() { delete ui; } /** - * Set the background color RED style for the GroupBox PID when change lineEdit information + *@brief Set the background color RED style for the GroupBox PID when change lineEdit information * */ void SlugsPIDControl::setRedColorStyle() @@ -46,7 +110,7 @@ void SlugsPIDControl::setRedColorStyle() } /** - * Set the background color GREEN style for the GroupBox PID when change lineEdit information + *@brief Set the background color GREEN style for the GroupBox PID when change lineEdit information * */ void SlugsPIDControl::setGreenColorStyle() @@ -64,12 +128,17 @@ void SlugsPIDControl::setGreenColorStyle() } /** - * Connection Signal and Slot of the set buttons on the widget + *@brief Connection Signal and Slot of the set buttons on the widget */ void SlugsPIDControl::connect_set_pushButtons() { //ToDo connect buttons set and get. Before create the slots - connect(ui->dT_PID_set_pushButton, SIGNAL(clicked(bool)),this,SLOT(changeColor_GREEN_AirSpeed_groupBox())); + connect(ui->dT_PID_set_pushButton, SIGNAL(clicked()),this,SLOT(changeColor_GREEN_AirSpeed_groupBox())); + connect(ui->dE_PID_set_pushButton,SIGNAL(clicked()),this,SLOT(changeColor_GREEN_PitchFollowei_groupBox())); + connect(ui->dA_PID_set_pushButton,SIGNAL(clicked()),this,SLOT(changeColor_GREEN_RollControl_groupBox())); + connect(ui->HELPComm_PDI_set_pushButton,SIGNAL(clicked()),this,SLOT(changeColor_GREEN_HeigthError_groupBox())); + connect(ui->dR_PDI_set_pushButton,SIGNAL(clicked()),this,SLOT(changeColor_GREEN_YawDamper_groupBox())); + connect(ui->Pitch2dT_PDI_set_pushButton,SIGNAL(clicked()),this,SLOT(changeColor_GREEN_Pitch2dT_groupBox())); } @@ -90,7 +159,188 @@ void SlugsPIDControl::changeColor_RED_AirSpeed_groupBox(QString text) void SlugsPIDControl::changeColor_GREEN_AirSpeed_groupBox() { + //create the packet + pidMessage.target = activeUAS->getUASID(); + pidMessage.idx = 0; + pidMessage.pVal = ui->dT_P_set->text().toFloat(); + pidMessage.iVal = ui->dT_I_set->text().toFloat(); + pidMessage.dVal = ui->dT_D_set->text().toFloat(); + + UAS *uas = dynamic_cast(UASManager::instance()->getActiveUAS()); + + mavlink_message_t msg; + + mavlink_msg_pid_encode(MG::SYSTEM::ID,MG::SYSTEM::COMPID, &msg, &pidMessage); + uas->sendMessage(msg); + + + ui->AirSpeedHold_groupBox->setStyleSheet(GREENcolorStyle); } +void SlugsPIDControl::connect_PitchFollowei_LineEdit() +{ + connect(ui->dE_P_set, SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_PitchFollowei_groupBox(QString))); + connect(ui->dE_I_set, SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_PitchFollowei_groupBox(QString))); + connect(ui->dE_D_set, SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_PitchFollowei_groupBox(QString))); +} + +void SlugsPIDControl::changeColor_RED_PitchFollowei_groupBox(QString text) +{ + Q_UNUSED(text); + ui->PitchFlowei_groupBox->setStyleSheet(REDcolorStyle); + +} + +void SlugsPIDControl::changeColor_GREEN_PitchFollowei_groupBox() +{ + ui->PitchFlowei_groupBox->setStyleSheet(GREENcolorStyle); +} + +// Functions for Roll Control GroupBox +/** + * @brief Change color style to red when PID values of Roll Control are edited + * + * + * @param + */ +void SlugsPIDControl::changeColor_RED_RollControl_groupBox(QString text) +{ + Q_UNUSED(text); + ui->RollControl_groupBox->setStyleSheet(REDcolorStyle); +} + +/** + * @brief Change color style to green when PID values of Roll Control are send to UAS + * + * @param + */ +void SlugsPIDControl::changeColor_GREEN_RollControl_groupBox() +{ + ui->RollControl_groupBox->setStyleSheet(GREENcolorStyle); +} + +/** + * @brief Connects the SIGNALS from the editline to SLOT RollControl_groupBox + * + * @param + */ +void SlugsPIDControl::connect_RollControl_LineEdit() +{ + connect(ui->dA_P_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_RollControl_groupBox(QString))); + connect(ui->dA_I_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_RollControl_groupBox(QString))); + connect(ui->dA_D_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_RollControl_groupBox(QString))); +} + + +// Functions for Heigth Error GroupBox +/** + * @brief Change color style to red when PID values of Heigth Error are edited + * + * + * @param + */ +void SlugsPIDControl::changeColor_RED_HeigthError_groupBox(QString text) +{ + Q_UNUSED(text); + ui->HeightErrorLoPitch_groupBox->setStyleSheet(REDcolorStyle); +} + +/** + * @brief Change color style to green when PID values of Heigth Error are send to UAS + * + * @param + */ +void SlugsPIDControl::changeColor_GREEN_HeigthError_groupBox() +{ + ui->HeightErrorLoPitch_groupBox->setStyleSheet(GREENcolorStyle); +} + +/** + * @brief Connects the SIGNALS from the editline to SLOT HeigthError_groupBox + * + * @param + */ +void SlugsPIDControl::connect_HeigthError_LineEdit() +{ + connect(ui->HELPComm_P_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_HeigthError_groupBox(QString))); + connect(ui->HELPComm_I_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_HeigthError_groupBox(QString))); + connect(ui->HELPComm_FF_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_HeigthError_groupBox(QString))); +} + + +// Functions for Yaw Damper GroupBox +/** + * @brief Change color style to red when PID values of Yaw Damper are edited + * + * + * @param + */ +void SlugsPIDControl::changeColor_RED_YawDamper_groupBox(QString text) +{ + Q_UNUSED(text); + ui->YawDamper_groupBox->setStyleSheet(REDcolorStyle); +} + +/** + * @brief Change color style to green when PID values of Yaw Damper are send to UAS + * + * @param + */ +void SlugsPIDControl::changeColor_GREEN_YawDamper_groupBox() +{ + ui->YawDamper_groupBox->setStyleSheet(GREENcolorStyle); +} + +/** + * @brief Connects the SIGNALS from the editline to SLOT YawDamper_groupBox + * + * @param + */ +void SlugsPIDControl::connect_YawDamper_LineEdit() +{ + connect(ui->dR_P_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_YawDamper_groupBox(QString))); + connect(ui->dR_I_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_YawDamper_groupBox(QString))); + connect(ui->dR_D_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_YawDamper_groupBox(QString))); + + +} + +// Functions for Pitch to dT GroupBox +/** + * @brief Change color style to red when PID values of Pitch to dT are edited + * + * + * @param + */ +void SlugsPIDControl::changeColor_RED_Pitch2dT_groupBox(QString text) +{ + Q_UNUSED(text); + ui->Pitch2dTFFterm_groupBox->setStyleSheet(REDcolorStyle); +} + +/** + * @brief Change color style to green when PID values of Pitch to dT are send to UAS + * + * @param + */ +void SlugsPIDControl::changeColor_GREEN_Pitch2dT_groupBox() +{ + ui->Pitch2dTFFterm_groupBox->setStyleSheet(GREENcolorStyle); +} + +/** + * @brief Connects the SIGNALS from the editline to SLOT Pitch2dT_groupBox + * + * @param + */ +void SlugsPIDControl::connect_Pitch2dT_LineEdit() +{ + connect(ui->P2dT_FF_set,SIGNAL(textChanged(QString)),this,SLOT(changeColor_RED_Pitch2dT_groupBox(QString))); +} + +void SlugsPIDControl::recibeMensaje(int systemId, uint8_t action, uint8_t result) +{ + ui->recepcion_label->setText(QString::number(action)); +} diff --git a/src/ui/SlugsPIDControl.h b/src/ui/SlugsPIDControl.h index 20349df29..700a67760 100644 --- a/src/ui/SlugsPIDControl.h +++ b/src/ui/SlugsPIDControl.h @@ -3,6 +3,10 @@ #include #include +#include "UASInterface.h" +#include "QGCMAVLink.h" +#include "SlugsMAV.h" + namespace Ui { class SlugsPIDControl; @@ -18,11 +22,52 @@ public: public slots: + /** + * @brief Called when the a new UAS is set to active. + * + * Called when the a new UAS is set to active. + * + * @param uas The new active UAS + */ + void activeUasSet(UASInterface* uas); + + /** + */ void setRedColorStyle(); + /** + * @brief Set color StyleSheet GREEN + * + * @param + */ void setGreenColorStyle(); + /** + * @brief Connect Set pushButtons to change the color GroupBox + * + * @param + */ + void connect_set_pushButtons(); + + /** + * @brief Connect Edition Lines for PID Values + * + * @param + */ + void connect_editLinesPDIvalues(); +// Fuctions for Air Speed GroupBox + /** + * @brief Change color style to red when PID values of Air Speed are edited + * + * + * @param + */ void changeColor_RED_AirSpeed_groupBox(QString text); + /** + * @brief Change color style to green when PID values of Air Speed are send to UAS + * + * @param + */ void changeColor_GREEN_AirSpeed_groupBox(); /** * @brief Connects the SIGNALS from the editline to SLOT changeColor_RED_AirSpeed_groupBox() @@ -31,20 +76,134 @@ public slots: */ void connect_AirSpeed_LineEdit(); +// Functions for Pitch Followei GroupBox + /** + * @brief Change color style to red when PID values of Pitch Followei are edited + * + * + * @param + */ + void changeColor_RED_PitchFollowei_groupBox(QString text); + /** + * @brief Change color style to green when PID values of Pitch Followei are send to UAS + * + * @param + */ + void changeColor_GREEN_PitchFollowei_groupBox(); + /** + * @brief Connects the SIGNALS from the editline to SLOT PitchFlowei_groupBox + * + * @param + */ + void connect_PitchFollowei_LineEdit(); + + // Functions for Roll Control GroupBox + /** + * @brief Change color style to red when PID values of Roll Control are edited + * + * + * @param + */ + void changeColor_RED_RollControl_groupBox(QString text); + /** + * @brief Change color style to green when PID values of Roll Control are send to UAS + * + * @param + */ + void changeColor_GREEN_RollControl_groupBox(); + /** + * @brief Connects the SIGNALS from the editline to SLOT RollControl_groupBox + * + * @param + */ + void connect_RollControl_LineEdit(); + + // Functions for Heigth Error GroupBox + /** + * @brief Change color style to red when PID values of Heigth Error are edited + * + * + * @param + */ + void changeColor_RED_HeigthError_groupBox(QString text); + /** + * @brief Change color style to green when PID values of Heigth Error are send to UAS + * + * @param + */ + void changeColor_GREEN_HeigthError_groupBox(); + /** + * @brief Connects the SIGNALS from the editline to SLOT HeigthError_groupBox + * + * @param + */ + void connect_HeigthError_LineEdit(); + + // Functions for Yaw Damper GroupBox + /** + * @brief Change color style to red when PID values of Yaw Damper are edited + * + * + * @param + */ + void changeColor_RED_YawDamper_groupBox(QString text); + /** + * @brief Change color style to green when PID values of Yaw Damper are send to UAS + * + * @param + */ + void changeColor_GREEN_YawDamper_groupBox(); + /** + * @brief Connects the SIGNALS from the editline to SLOT YawDamper_groupBox + * + * @param + */ + void connect_YawDamper_LineEdit(); + + // Functions for Pitch to dT GroupBox + /** + * @brief Change color style to red when PID values of Pitch to dT are edited + * + * + * @param + */ + void changeColor_RED_Pitch2dT_groupBox(QString text); + /** + * @brief Change color style to green when PID values of Pitch to dT are send to UAS + * + * @param + */ + void changeColor_GREEN_Pitch2dT_groupBox(); + /** + * @brief Connects the SIGNALS from the editline to SLOT Pitch2dT_groupBox + * + * @param + */ + void connect_Pitch2dT_LineEdit(); + + + //Create, send and get Messages PID + // void createMessagePID(); + + void recibeMensaje(int systemId, uint8_t action, uint8_t result); - - - void connect_set_pushButtons(); - private: Ui::SlugsPIDControl *ui; + + UASInterface* activeUAS; + int systemId; + bool change_dT; + //Color Styles QString REDcolorStyle; QString GREENcolorStyle; QString ORIGINcolorStyle; + + //SlugsMav Message + mavlink_pid_t pidMessage; }; #endif // SLUGSPIDCONTROL_H diff --git a/src/ui/SlugsPIDControl.ui b/src/ui/SlugsPIDControl.ui index 35e7cd35f..419b3c7b9 100644 --- a/src/ui/SlugsPIDControl.ui +++ b/src/ui/SlugsPIDControl.ui @@ -122,6 +122,13 @@ + + + + Recepcion + + + @@ -671,14 +678,14 @@ - + SET - + GET @@ -834,14 +841,14 @@ - + SET - + GET @@ -922,14 +929,14 @@ - + SET - + GET -- 2.22.0