diff --git a/crazyflie_groundstation/inc/CCrazyflie.h b/crazyflie_groundstation/inc/CCrazyflie.h index b1a738f6b2891df219c50a728d299781d5a9a477..dd7937812cbe31a33e8e638311c893d865b471cd 100644 --- a/crazyflie_groundstation/inc/CCrazyflie.h +++ b/crazyflie_groundstation/inc/CCrazyflie.h @@ -525,7 +525,7 @@ class CCrazyflie { * @param name The name of the logging block * @param frequency The frequency to log (in Hz) */ - bool addLoggingBlock(const char *name, uint16_t frequency); + bool addLoggingBlock(const char *name, uint16_t frequency, uint16_t id); /** * Remove a logging block (stop logging) diff --git a/crazyflie_groundstation/inc/CTOC.h b/crazyflie_groundstation/inc/CTOC.h index fd96360f7b41207504cf9f149e7e4c25063dac5c..b326be5e8b862707c0f5f4d20a97e135c7a18e03 100644 --- a/crazyflie_groundstation/inc/CTOC.h +++ b/crazyflie_groundstation/inc/CTOC.h @@ -118,7 +118,7 @@ class CTOC { int typeForName(std::string strName); // For loggable variables only - bool registerLoggingBlock(std::string strName, double dFrequency); + bool registerLoggingBlock(std::string strName, double dFrequency, uint16_t id); bool unregisterLoggingBlock(std::string strName); bool unregisterLoggingBlocks(); struct LoggingBlock loggingBlockForName(std::string strName, bool& bFound); diff --git a/crazyflie_groundstation/src/CTOC.cpp b/crazyflie_groundstation/src/CTOC.cpp index 27c1cf444cd3b99d808785d828cb0716fb62b803..4e484aad8f1b294add50ff8d77f133124e4163f2 100644 --- a/crazyflie_groundstation/src/CTOC.cpp +++ b/crazyflie_groundstation/src/CTOC.cpp @@ -640,9 +640,9 @@ struct LoggingBlock CTOC::loggingBlockForID(int nID, bool& bFound) { return lbEmpty; } -bool CTOC::registerLoggingBlock(std::string strName, double dFrequency) { +bool CTOC::registerLoggingBlock(std::string strName, double dFrequency, uint16_t id) { if( ALL_THE_DEBUG ) printf( "%s\n", __FUNCTION__); - int nID = 0; + int nID = id; bool bFound; if (dFrequency > 0) { // Only do it if a valid frequency > 0 is given @@ -651,13 +651,13 @@ bool CTOC::registerLoggingBlock(std::string strName, double dFrequency) { this->unregisterLoggingBlock(strName); } - do { - this->loggingBlockForID(nID, bFound); + // do { + // this->loggingBlockForID(nID, bFound); - if (bFound) { - nID++; - } - } while (bFound); + // if (bFound) { + // nID++; + // } + // } while (bFound); this->unregisterLoggingBlockID(nID); @@ -780,9 +780,7 @@ bool CTOC::unregisterLoggingBlocks() { if (crtpReceived) { delete crtpReceived; - for(std::list<struct LoggingBlock>::iterator itBlock = m_lstLoggingBlocks.begin(); itBlock != m_lstLoggingBlocks.end(); itBlock++) { - itBlock = m_lstLoggingBlocks.erase(itBlock); - } + m_lstLoggingBlocks.clear(); return true; } diff --git a/crazyflie_groundstation/src/ccrazyflie/CCrazyflie_loggingFuncs.cpp b/crazyflie_groundstation/src/ccrazyflie/CCrazyflie_loggingFuncs.cpp index 621fee8e401cc9537e5e168bdd2168de4f362e77..e3b05418a4b3dc812f79ad2b717ebe9fe8c91116 100644 --- a/crazyflie_groundstation/src/ccrazyflie/CCrazyflie_loggingFuncs.cpp +++ b/crazyflie_groundstation/src/ccrazyflie/CCrazyflie_loggingFuncs.cpp @@ -165,8 +165,8 @@ double CCrazyflie::sensorDoubleValue(std::string strName) { return m_tocLogs->doubleValue(strName); } -bool CCrazyflie::addLoggingBlock(const char *name, uint16_t frequency) { - bool retval = m_tocLogs->registerLoggingBlock(name, frequency); +bool CCrazyflie::addLoggingBlock(const char *name, uint16_t frequency, uint16_t id) { + bool retval = m_tocLogs->registerLoggingBlock(name, frequency, id); return(retval); } @@ -335,7 +335,7 @@ bool CCrazyflie::loadLoggingBlocksFromFile(std::string blockFileName) { continue; } blockLinesRead++; - addLoggingBlock(curName.c_str(), curFreq); + addLoggingBlock(curName.c_str(), curFreq, curId); continue; } else if(blockLinesRead > 3) { diff --git a/groundStation/gui/MicroCART/crazyflieworker.cpp b/groundStation/gui/MicroCART/crazyflieworker.cpp index 5fa186c7c5de7fc74a143b79dcfa8d4d85d5a3c7..edd1c2a11c0302119606ea2468b85899d1777fb6 100644 --- a/groundStation/gui/MicroCART/crazyflieworker.cpp +++ b/groundStation/gui/MicroCART/crazyflieworker.cpp @@ -1,4 +1,5 @@ #include "crazyflieworker.h" +#include <QFileDialog> #include <iostream> #include <unistd.h> #include <sys/stat.h> @@ -29,6 +30,9 @@ void CrazyflieWorker::connectBackend() isBackendConnected = true; loadParamIds(); loadLogIds(); + loadLogBlocks(); + QStringList logBlockNames = getLogBlockNames(); + emit(changeLogBlock_comboBox(logBlockNames)); QStringList paramGroupList; for(int i = 0; i < paramGroups.size(); i++) { QString qgName(paramGroups.at(i).groupName.c_str()); @@ -47,6 +51,18 @@ void CrazyflieWorker::connectBackend() } } emit(gotLogVariables(logVariablesList)); + QStringList activeVars; + for(int i = 0; i < logBlocks.size(); i++) { + if(logBlocks.at(i).isEnabled) { + for(int j = 0; j < logBlocks.at(i).variableNames.size(); j++) { + QString fullIdentifier(logBlocks.at(i).variableNames.at(j).strGroup.c_str()); + QString varname(logBlocks.at(i).variableNames.at(j).strName.c_str()); + fullIdentifier = fullIdentifier + "." + varname; + activeVars.append(fullIdentifier); + } + } + } + emit(gotActiveLogVariables(activeVars)); } /** @@ -75,7 +91,7 @@ void CrazyflieWorker::setCurrAttSetpoint(float roll, float pitch, float yaw, flo void CrazyflieWorker::setCurrAttRateSetpoint(float rollRate, float pitchRate, float yawRate, float throttle) { - qInfo() << "set rate"; + //qInfo() << "set rate"; currAttitudeRateSetpoint.roll = rollRate; currAttitudeRateSetpoint.pitch = pitchRate; currAttitudeRateSetpoint.yaw = yawRate; @@ -85,7 +101,7 @@ void CrazyflieWorker::setCurrAttRateSetpoint(float rollRate, float pitchRate, fl void CrazyflieWorker::sendAttRateSetpoint() { - qInfo() << " send att rate" << currAttitudeRateSetpoint.throttle << " " << currAttitudeRateSetpoint.roll; + //qInfo() << " send att rate" << currAttitudeRateSetpoint.throttle << " " << currAttitudeRateSetpoint.roll; if(isBackendConnected){ struct frontend_override_data data; @@ -104,7 +120,7 @@ void CrazyflieWorker::sendAttRateSetpoint() void CrazyflieWorker::sendAttSetpoint() { - qInfo() << " send att" << currAttitudeSetpoint.throttle; + //qInfo() << " send att" << currAttitudeSetpoint.throttle; if(isBackendConnected){ struct frontend_override_data data; @@ -122,7 +138,7 @@ void CrazyflieWorker::sendAttSetpoint() void CrazyflieWorker::sendMixedAttSetpoint(){ - qInfo() << "send mixed setpoint"; + //qInfo() << "send mixed setpoint"; if(isBackendConnected){ struct frontend_override_data data; @@ -311,3 +327,199 @@ void CrazyflieWorker::getGroupEntries(int box, QString gName) { } emit(gotGroupEntries(box, entryList)); } + +void CrazyflieWorker::frontendLogBlockCommand(int8_t command, int8_t id) { + struct frontend_logblockcommand_data data; + data.command = command; + data.id = id; + if(frontend_logblockcommand(conn, &data)) { + qInfo() << "error refreshing log blocks"; + return; + } + if(command == 0) { + logBlocks.clear(); + } + else if(command == 1) { + logBlocks.clear(); + loadLogBlocks(); + } + else if(command == 3) { + removeLogBlock(id); + } + else if(command == 4) { + enableLogBlock(id, true); + } + else if(command == 5) { + enableLogBlock(id, false); + } + // for(int i = 0; i < logBlocks.size(); i++) { + // QString blN(logBlocks.at(i).blockName.c_str()); + // qInfo() << logBlocks.at(i).id << ": " << blN << "enabled: " << logBlocks.at(i).isEnabled; + // } + QStringList logBlockNames = getLogBlockNames(); + emit(changeLogBlock_comboBox(logBlockNames)); + QStringList activeVars; + for(int i = 0; i < logBlocks.size(); i++) { + if(logBlocks.at(i).isEnabled) { + for(int j = 0; j < logBlocks.at(i).variableNames.size(); j++) { + QString fullIdentifier(logBlocks.at(i).variableNames.at(j).strGroup.c_str()); + QString varname(logBlocks.at(i).variableNames.at(j).strName.c_str()); + fullIdentifier = fullIdentifier + "." + varname; + activeVars.append(fullIdentifier); + } + } + } + emit(gotActiveLogVariables(activeVars)); +} + +void CrazyflieWorker::removeLogBlock(int id) { + for(int i = 0; i < logBlocks.size(); i++) { + if(id == logBlocks.at(i).id) { + logBlocks.erase(logBlocks.begin() + i); + return; + } + } +} + +void CrazyflieWorker::enableLogBlock(int id, bool isEnabled) { + for(int i = 0; i < logBlocks.size(); i++) { + if(id == logBlocks.at(i).id) { + logBlocks.at(i).isEnabled = isEnabled; + return; + } + } +} + +void CrazyflieWorker::loadLogBlocks() { + std::ifstream blockFile; + QString filename(QDir::currentPath() + "/../crazyflie_groundstation/loggingBlocks.txt"); + blockFile.open(filename.toStdString()); + std::string line = ""; + //0 if not readingBlock 1 is START BLOCK and so on + int blockLinesRead = 0; + struct logBlock cur; + std::string entryName; + + while(getline(blockFile, line)) { + if(!line.compare("START BLOCK")) { + blockLinesRead = 1; + continue; + } + else if(!line.compare("END BLOCK")) { + cur.isEnabled = true; + logBlocks.push_back(cur); + blockLinesRead = 0; + cur.id = -1; + cur.blockName = ""; + cur.isEnabled = false; + cur.variableNames.clear(); + entryName = ""; + continue; + } + else if(blockLinesRead == 1) { + try { + cur.id = std::stoi(line); + bool found = logBlockWithID(cur.id); + if(found) { + blockLinesRead = 0; + cur.id = -1; + cur.blockName = ""; + entryName = ""; + cur.isEnabled = false; + cur.variableNames.clear(); + continue; + } + } + catch(std::invalid_argument& e) { + std::cout << "Error: invalid ID. Skipping Block" << std::endl; + blockLinesRead = 0; + continue; + } + blockLinesRead++; + continue; + } + else if(blockLinesRead == 2) { + cur.blockName = line; + blockLinesRead++; + continue; + } + else if(blockLinesRead == 3) { + try { + int curFreq = std::stoi(line); + } + catch(std::invalid_argument& e) { + std::cout << "Error: invalid frequency. Skipping Block" << std::endl; + blockLinesRead = 0; + cur.id = -1; + cur.blockName = ""; + entryName = ""; + cur.isEnabled = false; + cur.variableNames.clear(); + continue; + } + blockLinesRead++; + //logBlocks.push_back(cur); + continue; + } + else if(blockLinesRead > 3) { + entryName = line; + struct toc_info entryInfo = tocElementForName(entryName); + cur.variableNames.push_back(entryInfo); + blockLinesRead++; + continue; + } + else { + continue; + } + } + blockFile.close(); +} + +void CrazyflieWorker::findLogBlockID(QString name, int8_t command) { + std::string lbName = name.toStdString(); + int id = -1; + for(int i = 0; i < logBlocks.size(); i++) { + if(!lbName.compare(logBlocks.at(i).blockName)) { + id = i; + break; + } + } + if(id == -1) { + return; + } + emit(gotLogBlockID(id, command)); +} + +bool CrazyflieWorker::logBlockWithID(int id) { + for(int i = 0; i < logBlocks.size(); i++) { + if(id == logBlocks.at(i).id) { + return true; + } + } + return false; +} + +QStringList CrazyflieWorker::getLogBlockNames() { + QStringList names; + for(int i =0; i < logBlocks.size(); i++) { + names.append(logBlocks.at(i).blockName.c_str()); + } + return names; +} + +struct toc_info CrazyflieWorker::tocElementForName(std::string name) { + QString qName(name.c_str()); + struct toc_info element = logIds.value(qName); + return element; +} + +void CrazyflieWorker::logBlockBoxChanged(QString text) { + bool enabled = false; + for(int i = 0; i < logBlocks.size(); i++) { + if(!logBlocks.at(i).blockName.compare(text.toStdString())) { + enabled = logBlocks.at(i).isEnabled; + break; + } + } + emit(gotBlockisEnabled(enabled)); +} \ No newline at end of file diff --git a/groundStation/gui/MicroCART/crazyflieworker.h b/groundStation/gui/MicroCART/crazyflieworker.h index 42dca39f0cf6ae91b97bfa5bcbe7312299e0b07a..50cbde7723714958f3831d3dc7c05dc3f83027f7 100644 --- a/groundStation/gui/MicroCART/crazyflieworker.h +++ b/groundStation/gui/MicroCART/crazyflieworker.h @@ -26,6 +26,13 @@ struct toc_group { std::vector<std::string> entryNames; }; +struct logBlock { + std::string blockName; + int id; + std::vector<struct toc_info> variableNames; + bool isEnabled; +}; + /** * @brief The crazyflieworker class * This class handles communication for the crazyflie, @@ -44,6 +51,10 @@ signals: void gotParamGroups(QStringList paramGroupList); void gotLogVariables(QStringList logVariables); void gotGroupEntries(int box, QStringList groupEntries); + void gotLogBlockID(int id, int8_t command); + void changeLogBlock_comboBox(QStringList logBlockNames); + void gotBlockisEnabled(bool isEnabled); + void gotActiveLogVariables(QStringList activeVars); void connected(); void disconnected(); @@ -59,6 +70,9 @@ public slots: void setCurrAttRateSetpoint(float rollRate, float pitchRate, float yawRate, float throttleRate); void setParamValue(QString paramName, double value); void getGroupEntries(int box, QString gName); + void frontendLogBlockCommand(int8_t command, int8_t id); + void findLogBlockID(QString name, int8_t command); + void logBlockBoxChanged(QString text); private: struct backend_conn * conn; @@ -67,6 +81,12 @@ private: std::string getLogFile(int type); void loadParamIds(); void loadLogIds(); + void removeLogBlock(int id); + void enableLogBlock(int id, bool isEnabled); + void loadLogBlocks(); + bool logBlockWithID(int id); + struct toc_info tocElementForName(std::string name); + QStringList getLogBlockNames(); int findParamGroup(std::string gName); int findLogGroup(std::string gName); struct toc_info paramNameLookup(QString paramName); @@ -74,6 +94,7 @@ private: QMap<QString, struct toc_info> logIds; std::vector<struct toc_group> paramGroups; std::vector<struct toc_group> logGroups; + std::vector<struct logBlock> logBlocks; bool isBackendConnected = false; }; diff --git a/groundStation/gui/MicroCART/mainwindow.cpp b/groundStation/gui/MicroCART/mainwindow.cpp index 47d5ca653dd449aaa6b2cd05db0e777252792179..f73beb9a09462b1b86fed61aabace9a29bcf7ee4 100644 --- a/groundStation/gui/MicroCART/mainwindow.cpp +++ b/groundStation/gui/MicroCART/mainwindow.cpp @@ -40,6 +40,7 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); + qRegisterMetaType<int8_t>("int8_t"); QGraphicsScene *posScene = new QGraphicsScene(this); // ui->posView->setScene(posScene); @@ -107,13 +108,26 @@ MainWindow::MainWindow(QWidget *parent) : logWorker->moveToThread(logThread); /* connect signals for crazyflie worker */ - connect(ui->logEntriesComboBox1, SIGNAL (currentIndexChanged(int)), this, SLOT (getLogEntryBoxChange1(int))); - connect(ui->logEntriesComboBox2, SIGNAL (currentIndexChanged(int)), this, SLOT (getLogEntryBoxChange2(int))); - connect(ui->logEntriesComboBox3, SIGNAL (currentIndexChanged(int)), this, SLOT (getLogEntryBoxChange3(int))); - connect(ui->logEntriesComboBox4, SIGNAL (currentIndexChanged(int)), this, SLOT (getLogEntryBoxChange4(int))); - connect(ui->logEntriesComboBox5, SIGNAL (currentIndexChanged(int)), this, SLOT (getLogEntryBoxChange5(int))); + connect(ui->logEntriesComboBox1, SIGNAL (currentTextChanged(QString)), this, SLOT (getLogEntryBoxChange1(QString))); + connect(ui->logEntriesComboBox2, SIGNAL (currentTextChanged(QString)), this, SLOT (getLogEntryBoxChange2(QString))); + connect(ui->logEntriesComboBox3, SIGNAL (currentTextChanged(QString)), this, SLOT (getLogEntryBoxChange3(QString))); + connect(ui->logEntriesComboBox4, SIGNAL (currentTextChanged(QString)), this, SLOT (getLogEntryBoxChange4(QString))); + connect(ui->logEntriesComboBox5, SIGNAL (currentTextChanged(QString)), this, SLOT (getLogEntryBoxChange5(QString))); connect(ui->pb_startLog, SIGNAL (clicked()), logWorker, SLOT (getLogValues(QString, QString, QString, QString, QString))); connect(logWorker, SIGNAL (gotLogValues(QStringList)), this, SLOT (graphLogs(QStringList))); + connect(ui->pb_logBlockFile, SIGNAL (clicked()), this, SLOT(openLogBlockFile())); + connect(ui->pb_logBlockRefresh, SIGNAL (clicked()), this, SLOT(on_pb_lbRefresh())); + connect(ui->pb_logBlockStop, SIGNAL (clicked()), this, SLOT(on_pb_lbStop())); + connect(ui->pb_logBlockResume, SIGNAL (clicked()), this, SLOT(on_pb_lbResume())); + connect(ui->pb_logBlockPause, SIGNAL (clicked()), this, SLOT(on_pb_lbPause())); + connect(ui->comboBox_logBlocks, SIGNAL (currentTextChanged(QString)), crazyflieWorker, SLOT (logBlockBoxChanged(QString))); + connect(crazyflieWorker, SIGNAL (gotBlockisEnabled(bool)), this, SLOT(setLogButtons(bool))); + //connect(ui->pb_logBlockDelete, SIGNAL (clicked()), this, SLOT(on_pb_lbDelete())); + connect(this, SIGNAL(sendLogBlockCommand(int8_t, int8_t)), crazyflieWorker, SLOT(frontendLogBlockCommand(int8_t, int8_t))); + connect(this, SIGNAL (requestLogBlockID(QString, int8_t)), crazyflieWorker, SLOT(findLogBlockID(QString, int8_t))); + connect(crazyflieWorker, SIGNAL (gotLogBlockID(int, int8_t)), this, SLOT(useLogBlockID(int, int8_t))); + connect(crazyflieWorker, SIGNAL (changeLogBlock_comboBox(QStringList)), SLOT(gotLogBlockNames(QStringList))); + connect(crazyflieWorker, SIGNAL (gotActiveLogVariables(QStringList)), this, SLOT(fillLogVariablesBox(QStringList))); connect(this, SIGNAL (rateSetpointSignal(float, float, float, float)), crazyflieWorker, SLOT (setCurrAttRateSetpoint(float, float, float, float))); connect(this, SIGNAL (angleSetpointSignal(float, float, float, float)), crazyflieWorker, SLOT (setCurrAttSetpoint(float, float, float, float))); @@ -195,10 +209,19 @@ MainWindow::MainWindow(QWidget *parent) : ui->pb_getParam->setEnabled(false); ui->pb_setParam->setEnabled(false); + ui->pb_logBlockRefresh->setEnabled(false); + ui->pb_logBlockStop->setEnabled(false); + ui->pb_logBlockResume->setEnabled(false); + ui->pb_logBlockPause->setEnabled(false); ui->setValueSpin->setMaximum(10000.00); ui->setValueSpin->setMinimum(-10000.00); ui->setValueSpin->setSingleStep(0.01); ui->setValueSpin->setValue(0); + logVar1 = "Logging Variable 1"; + logVar2 = "Logging Variable 2"; + logVar3 = "Logging Variable 3"; + logVar4 = "Logging Variable 4"; + logVar5 = "Logging Variable 5"; /* Connect various things that can result in sending setpoints */ // connect(ui->pbSendSetpoint, SIGNAL (clicked()), this, SLOT (sendSetpoints())); @@ -314,7 +337,10 @@ void MainWindow::workerConnected() ui->pbStart->setEnabled(false); ui->pbConnect->setEnabled(false); ui->pbStop->setEnabled(true); + ui->pb_logBlockRefresh->setEnabled(true); + ui->pb_logBlockStop->setEnabled(true); } + } void MainWindow::workerDisconnected() @@ -326,6 +352,10 @@ void MainWindow::workerDisconnected() ui->pbStart->setEnabled(true); ui->pbConnect->setEnabled(true); ui->pbStop->setEnabled(false); + ui->pb_getParam->setEnabled(false); + ui->pb_setParam->setEnabled(false); + ui->pb_logBlockRefresh->setEnabled(false); + ui->pb_logBlockStop->setEnabled(false); } } @@ -1052,3 +1082,221 @@ void MainWindow::graphLogs(QStringList logs) ui->dataPlot->replot(); } +void MainWindow::openLogBlockFile() { + QProcess *fileOpen = new QProcess(this); + QString exec = "gedit " + QDir::currentPath() + "/../crazyflie_groundstation/loggingBlocks.txt"; + fileOpen->start(exec); +} + +void MainWindow::on_pb_lbRefresh() { + emit(sendLogBlockCommand(1, -1)); +} + +void MainWindow::on_pb_lbStop() { + emit(sendLogBlockCommand(0, -1)); +} + +void MainWindow::on_pb_lbResume() { + QString blockName = ui->comboBox_logBlocks->currentText(); + emit(requestLogBlockID(blockName, 4)); +} + +void MainWindow::on_pb_lbPause() { + QString blockName = ui->comboBox_logBlocks->currentText(); + emit(requestLogBlockID(blockName, 5)); +} + +void MainWindow::on_pb_lbDelete() { + QString blockName = ui->comboBox_logBlocks->currentText(); + emit(requestLogBlockID(blockName, 3)); +} + +void MainWindow::useLogBlockID(int id, int8_t command) { + emit(sendLogBlockCommand(command, id)); +} + +void MainWindow::gotLogBlockNames(QStringList logBlockNames) { + ui->comboBox_logBlocks->clear(); + ui->comboBox_logBlocks->addItem("Logging Blocks"); + ui->comboBox_logBlocks->addItems(logBlockNames); +} + +void MainWindow::setLogButtons(bool isEnabled) { + if(!ui->comboBox_logBlocks->currentText().toStdString().compare("Logging Blocks")) { + ui->pb_logBlockResume->setEnabled(false); + ui->pb_logBlockPause->setEnabled(false); + } + else { + ui->pb_logBlockResume->setEnabled(!isEnabled); + ui->pb_logBlockPause->setEnabled(isEnabled); + } +} + +void MainWindow::fillLogVariablesBox(QStringList activeVars) { + ui->logEntriesComboBox1->setCurrentIndex(0); + ui->logEntriesComboBox2->setCurrentIndex(0); + ui->logEntriesComboBox3->setCurrentIndex(0); + ui->logEntriesComboBox4->setCurrentIndex(0); + ui->logEntriesComboBox5->setCurrentIndex(0); + logVar1 = "Logging Variable 1"; + logVar2 = "Logging Variable 2"; + logVar3 = "Logging Variable 3"; + logVar4 = "Logging Variable 4"; + logVar5 = "Logging Variable 5"; + ui->logEntriesComboBox1->clear(); + ui->logEntriesComboBox1->addItem("Logging Variable 1"); + ui->logEntriesComboBox2->clear(); + ui->logEntriesComboBox2->addItem("Logging Variable 2"); + ui->logEntriesComboBox3->clear(); + ui->logEntriesComboBox3->addItem("Logging Variable 3"); + ui->logEntriesComboBox4->clear(); + ui->logEntriesComboBox4->addItem("Logging Variable 4"); + ui->logEntriesComboBox5->clear(); + ui->logEntriesComboBox5->addItem("Logging Variable 5"); + ui->logEntriesComboBox1->addItems(activeVars); + ui->logEntriesComboBox2->addItems(activeVars); + ui->logEntriesComboBox3->addItems(activeVars); + ui->logEntriesComboBox4->addItems(activeVars); + ui->logEntriesComboBox5->addItems(activeVars); +} + +void MainWindow::getLogEntryBoxChange1(QString text) { + if(logVar1.toStdString().compare("Logging Variable 1")) { + ui->logEntriesComboBox2->addItem(logVar1); + ui->logEntriesComboBox3->addItem(logVar1); + ui->logEntriesComboBox4->addItem(logVar1); + ui->logEntriesComboBox5->addItem(logVar1); + } + logVar1 = text; + int idx = -1; + if(logVar1.toStdString().compare("Logging Variable 1")) { + idx = ui->logEntriesComboBox2->findText(logVar1); + if(idx >= 0) { + ui->logEntriesComboBox2->removeItem(idx); + } + idx = ui->logEntriesComboBox3->findText(logVar1); + if(idx >= 0) { + ui->logEntriesComboBox3->removeItem(idx); + } + idx = ui->logEntriesComboBox4->findText(logVar1); + if(idx >= 0) { + ui->logEntriesComboBox4->removeItem(idx); + } + idx = ui->logEntriesComboBox5->findText(logVar1); + if(idx >= 0) { + ui->logEntriesComboBox5->removeItem(idx); + } + } +} +void MainWindow::getLogEntryBoxChange2(QString text) { + if(logVar2.toStdString().compare("Logging Variable 2")) { + ui->logEntriesComboBox1->addItem(logVar2); + ui->logEntriesComboBox3->addItem(logVar2); + ui->logEntriesComboBox4->addItem(logVar2); + ui->logEntriesComboBox5->addItem(logVar2); + } + logVar2 = text; + int idx = -1; + if(logVar2.toStdString().compare("Logging Variable 2")) { + idx = ui->logEntriesComboBox1->findText(logVar2); + if(idx >= 0) { + ui->logEntriesComboBox1->removeItem(idx); + } + idx = ui->logEntriesComboBox3->findText(logVar2); + if(idx >= 0) { + ui->logEntriesComboBox3->removeItem(idx); + } + idx = ui->logEntriesComboBox4->findText(logVar2); + if(idx >= 0) { + ui->logEntriesComboBox4->removeItem(idx); + } + idx = ui->logEntriesComboBox5->findText(logVar2); + if(idx >= 0) { + ui->logEntriesComboBox5->removeItem(idx); + } + } +} +void MainWindow::getLogEntryBoxChange3(QString text) { + if(logVar3.toStdString().compare("Logging Variable 3")) { + ui->logEntriesComboBox1->addItem(logVar3); + ui->logEntriesComboBox2->addItem(logVar3); + ui->logEntriesComboBox4->addItem(logVar3); + ui->logEntriesComboBox5->addItem(logVar3); + } + logVar3 = text; + int idx = -1; + if(logVar3.toStdString().compare("Logging Variable 3")) { + idx = ui->logEntriesComboBox2->findText(logVar3); + if(idx >= 0) { + ui->logEntriesComboBox2->removeItem(idx); + } + idx = ui->logEntriesComboBox1->findText(logVar3); + if(idx >= 0) { + ui->logEntriesComboBox1->removeItem(idx); + } + idx = ui->logEntriesComboBox4->findText(logVar3); + if(idx >= 0) { + ui->logEntriesComboBox4->removeItem(idx); + } + idx = ui->logEntriesComboBox5->findText(logVar3); + if(idx >= 0) { + ui->logEntriesComboBox5->removeItem(idx); + } + } +} +void MainWindow::getLogEntryBoxChange4(QString text) { + if(logVar4.toStdString().compare("Logging Variable 4")) { + ui->logEntriesComboBox2->addItem(logVar4); + ui->logEntriesComboBox3->addItem(logVar4); + ui->logEntriesComboBox1->addItem(logVar4); + ui->logEntriesComboBox5->addItem(logVar4); + } + logVar4 = text; + int idx = -1; + if(logVar4.toStdString().compare("Logging Variable 4")) { + idx = ui->logEntriesComboBox2->findText(logVar4); + if(idx >= 0) { + ui->logEntriesComboBox2->removeItem(idx); + } + idx = ui->logEntriesComboBox3->findText(logVar4); + if(idx >= 0) { + ui->logEntriesComboBox3->removeItem(idx); + } + idx = ui->logEntriesComboBox1->findText(logVar4); + if(idx >= 0) { + ui->logEntriesComboBox1->removeItem(idx); + } + idx = ui->logEntriesComboBox5->findText(logVar4); + if(idx >= 0) { + ui->logEntriesComboBox5->removeItem(idx); + } + } +} +void MainWindow::getLogEntryBoxChange5(QString text) { + if(logVar5.toStdString().compare("Logging Variable 5")) { + ui->logEntriesComboBox2->addItem(logVar5); + ui->logEntriesComboBox3->addItem(logVar5); + ui->logEntriesComboBox4->addItem(logVar5); + ui->logEntriesComboBox5->addItem(logVar5); + } + logVar5 = text; + int idx = -1; + if(logVar5.toStdString().compare("Logging Variable 5")) { + idx = ui->logEntriesComboBox2->findText(logVar5); + if(idx >= 0) { + ui->logEntriesComboBox2->removeItem(idx); + } + idx = ui->logEntriesComboBox3->findText(logVar5); + if(idx >= 0) { + ui->logEntriesComboBox3->removeItem(idx); + } + idx = ui->logEntriesComboBox4->findText(logVar5); + if(idx >= 0) { + ui->logEntriesComboBox4->removeItem(idx); + } + idx = ui->logEntriesComboBox1->findText(logVar5); + if(idx >= 0) { + ui->logEntriesComboBox1->removeItem(idx); + } + } +} \ No newline at end of file diff --git a/groundStation/gui/MicroCART/mainwindow.h b/groundStation/gui/MicroCART/mainwindow.h index a7bbcb446f53f366a0206936518b9c88764a071f..895fa44e1486d5daa23ac8f99e84acb867674cc9 100644 --- a/groundStation/gui/MicroCART/mainwindow.h +++ b/groundStation/gui/MicroCART/mainwindow.h @@ -39,8 +39,8 @@ signals: void triggerAttRateSetpointSend(); void triggerMixedAttSetpointSend(); void getLogValues(QString log1, QString log2, QString log3, QString log4, QString log5); - - + void sendLogBlockCommand(int8_t command, int8_t id); + void requestLogBlockID(QString name, int8_t command); private slots: void on_pbStart_clicked(); @@ -153,6 +153,23 @@ private slots: void graphLogs(QStringList logs); + void openLogBlockFile(); + + void gotLogBlockNames(QStringList logBlockNames); + + void on_pb_lbRefresh(); + void on_pb_lbStop(); + void on_pb_lbResume(); + void on_pb_lbPause(); + void on_pb_lbDelete(); + void useLogBlockID(int id, int8_t command); + void setLogButtons(bool isEnabled); + void fillLogVariablesBox(QStringList activeVars); + void getLogEntryBoxChange1(QString text); + void getLogEntryBoxChange2(QString text); + void getLogEntryBoxChange3(QString text); + void getLogEntryBoxChange4(QString text); + void getLogEntryBoxChange5(QString text); private: Ui::MainWindow *ui; @@ -163,6 +180,7 @@ private: float sp_yaw; float sp_thrust; QTimer * trackerTimer; + QString logVar1, logVar2, logVar3, logVar4, logVar5; QTimer * workerStartTimer; QTimer * crazyflieTimer; QTimer *pollGamepadTimer; diff --git a/groundStation/gui/MicroCART/mainwindow.ui b/groundStation/gui/MicroCART/mainwindow.ui index ca31bb05eae27aab0e132d716b2179d3ff7a2800..b8e8daee5c1e148468e55632059958e7745aa7a7 100644 --- a/groundStation/gui/MicroCART/mainwindow.ui +++ b/groundStation/gui/MicroCART/mainwindow.ui @@ -33,7 +33,7 @@ </size> </property> <property name="currentIndex"> - <number>3</number> + <number>4</number> </property> <widget class="QWidget" name="backend"> <attribute name="title"> @@ -796,11 +796,11 @@ <attribute name="title"> <string>Log Blocks</string> </attribute> - <widget class="QComboBox" name="comboBox"> + <widget class="QComboBox" name="comboBox_logBlocks"> <property name="geometry"> <rect> - <x>410</x> - <y>680</y> + <x>740</x> + <y>370</y> <width>201</width> <height>25</height> </rect> @@ -811,11 +811,11 @@ </property> </item> </widget> - <widget class="QPushButton" name="pushButton"> + <widget class="QPushButton" name="pb_logBlockResume"> <property name="geometry"> <rect> - <x>330</x> - <y>750</y> + <x>740</x> + <y>470</y> <width>80</width> <height>25</height> </rect> @@ -824,11 +824,11 @@ <string>Resume</string> </property> </widget> - <widget class="QPushButton" name="pushButton_2"> + <widget class="QPushButton" name="pb_logBlockPause"> <property name="geometry"> <rect> - <x>470</x> - <y>750</y> + <x>860</x> + <y>470</y> <width>80</width> <height>25</height> </rect> @@ -837,24 +837,11 @@ <string>Pause</string> </property> </widget> - <widget class="QPushButton" name="pushButton_3"> - <property name="geometry"> - <rect> - <x>600</x> - <y>750</y> - <width>80</width> - <height>25</height> - </rect> - </property> - <property name="text"> - <string>Delete</string> - </property> - </widget> - <widget class="QPushButton" name="pushButton_4"> + <widget class="QPushButton" name="pb_logBlockFile"> <property name="geometry"> <rect> - <x>330</x> - <y>520</y> + <x>650</x> + <y>110</y> <width>401</width> <height>25</height> </rect> @@ -863,11 +850,11 @@ <string>Open Logging Block Setup File</string> </property> </widget> - <widget class="QPushButton" name="pushButton_5"> + <widget class="QPushButton" name="pb_logBlockRefresh"> <property name="geometry"> <rect> - <x>330</x> - <y>610</y> + <x>650</x> + <y>250</y> <width>141</width> <height>25</height> </rect> @@ -876,11 +863,11 @@ <string>Refresh Log Blocks</string> </property> </widget> - <widget class="QPushButton" name="pushButton_6"> + <widget class="QPushButton" name="pb_logBlockStop"> <property name="geometry"> <rect> - <x>590</x> - <y>610</y> + <x>910</x> + <y>250</y> <width>141</width> <height>25</height> </rect> @@ -892,8 +879,8 @@ <widget class="QLabel" name="label_2"> <property name="geometry"> <rect> - <x>460</x> - <y>450</y> + <x>780</x> + <y>60</y> <width>141</width> <height>20</height> </rect> @@ -905,13 +892,26 @@ <widget class="QListWidget" name="logVariableList"> <property name="geometry"> <rect> - <x>5</x> - <y>0</y> - <width>1101</width> - <height>441</height> + <x>0</x> + <y>40</y> + <width>511</width> + <height>881</height> </rect> </property> </widget> + <widget class="QLabel" name="label_3"> + <property name="geometry"> + <rect> + <x>180</x> + <y>10</y> + <width>131</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Logging Variables</string> + </property> + </widget> </widget> <widget class="QWidget" name="navigation"> <attribute name="title">