diff --git a/crazyflie_software/crazyflie-firmware-2021.06/src/modules/src/crtp_commander_generic.c b/crazyflie_software/crazyflie-firmware-2021.06/src/modules/src/crtp_commander_generic.c index a4b1f55c47b4b46387a0a6fd2fb5348b3465c9e1..f690d24e267310340ea0524f2e2dd54d2bf647d3 100644 --- a/crazyflie_software/crazyflie-firmware-2021.06/src/modules/src/crtp_commander_generic.c +++ b/crazyflie_software/crazyflie-firmware-2021.06/src/modules/src/crtp_commander_generic.c @@ -73,6 +73,7 @@ enum packet_type { positionType = 7, attitudeRateType = 8, attitudeType = 9, + mixedAttitudeType = 10, }; /* ---===== 2 - Decoding functions =====--- */ @@ -431,6 +432,39 @@ static void attitudeDecoder(setpoint_t *setpoint, uint8_t type, const void *data setpoint->thrust = values->thrust; } + +/* + * Custom mixed Attitude decoder, bypasses the normal attitude control path, + * packet contains the roll and pitch as attitude angles and the + * yaw as an attitude rate in addition to the thrust value + */ +struct mixedAttitudePacket_s{ + float rollAngle; // deg + float pitchAngle; // deg + float yawAngleRate; // deg/s + float thrust; // thrust percentage 0 - 60,000 +} __attribute__((packed)); +static void mixedAttitudeDecoder(setpoint_t *setpoint, uint8_t type, const void *data, size_t datalen){ + + const struct mixedAttitudePacket_s *values = data; + + ASSERT(datalen == sizeof(struct mixedAttitudePacket_s)); + + setpoint->mode.x = modeDisable; + setpoint->mode.y = modeDisable; + setpoint->mode.z = modeDisable; + + setpoint->mode.roll = modeAbs; + setpoint->mode.pitch = modeAbs; + setpoint->mode.yaw = modeVelocity; + + setpoint->attitude.roll = values->rollAngle; + setpoint->attitude.pitch = values->pitchAngle; + setpoint->attitudeRate.yaw = values->yawAngleRate; + + setpoint->thrust = values->thrust; +} + /* ---===== 3 - packetDecoders array =====--- */ const static packetDecoder_t packetDecoders[] = { [stopType] = stopDecoder, @@ -443,6 +477,7 @@ const static packetDecoder_t packetDecoders[] = { [positionType] = positionDecoder, [attitudeRateType] = attitudeRateDecoder, [attitudeType] = attitudeDecoder, + [mixedAttitudeType] = mixedAttitudeDecoder, }; /* Decoder switch */ diff --git a/groundStation/adapters/crazyflie/src/cf_adapter.c b/groundStation/adapters/crazyflie/src/cf_adapter.c index 9cc1912ded91d354c4b3a91246393da848d1e6b7..b4a65f9e2e5f1aeca9e0015ff4da25e62f4b3d25 100644 --- a/groundStation/adapters/crazyflie/src/cf_adapter.c +++ b/groundStation/adapters/crazyflie/src/cf_adapter.c @@ -271,7 +271,7 @@ size_t getSinglePacket(int fd, uint8_t * packet, int pSize){ } //get the total packet size - totalPacketSize = packetSize(*(packet+5)<<8 | (*(packet +6))); + totalPacketSize = packetSize(*(packet+6)<<8 | (*(packet +5))); printf("\t\ttotal packet size %d\n",totalPacketSize); //check that the total packet size isnt unreasonable TODO is this a valid check? diff --git a/groundStation/gui/MicroCART/.gitignore b/groundStation/gui/MicroCART/.gitignore index d5ce34de5297da99798e7d40d2d85f383424787e..019099be5ce29387acb1e9f0b543340c71b1c9b6 100644 --- a/groundStation/gui/MicroCART/.gitignore +++ b/groundStation/gui/MicroCART/.gitignore @@ -1,3 +1,6 @@ +#MicroCART GUI executable +MicroCART + # C++ objects and libs *.slo *.lo diff --git a/groundStation/gui/MicroCART/crazyflieworker.cpp b/groundStation/gui/MicroCART/crazyflieworker.cpp index 8894c2c63b265fc749ec2f122a7d885abef96f52..cb241a10c9e6d80736720022c3823d21ca2e74dd 100644 --- a/groundStation/gui/MicroCART/crazyflieworker.cpp +++ b/groundStation/gui/MicroCART/crazyflieworker.cpp @@ -26,6 +26,7 @@ void CrazyflieWorker::connectBackend() } else { qInfo() << "Attempted to connect crazyflieworker when already connected!"; } + isBackendConnected = true; loadParamIds(); loadLogIds(); QStringList paramGroupList; @@ -47,6 +48,7 @@ void CrazyflieWorker::disconnectBackend() if (conn) { ucart_backendDisconnect(conn); conn = NULL; + isBackendConnected = false; emit (disconnected()); } } @@ -61,6 +63,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"; currAttitudeRateSetpoint.roll = rollRate; currAttitudeRateSetpoint.pitch = pitchRate; currAttitudeRateSetpoint.yaw = yawRate; @@ -70,31 +73,57 @@ void CrazyflieWorker::setCurrAttRateSetpoint(float rollRate, float pitchRate, fl void CrazyflieWorker::sendAttRateSetpoint() { - struct frontend_override_data data; - data.enable = 2; //attitude rate - data.time = 0.2; //hold setpoint for 0.2 seconds TODO check if this amount of time is good? - data.throttle = currAttitudeRateSetpoint.throttle; - data.roll = currAttitudeRateSetpoint.roll; - data.pitch = currAttitudeRateSetpoint.pitch; - data.yaw = currAttitudeRateSetpoint.yaw; - - //send setpoint - frontend_setoutputoverride(conn, &data); + qInfo() << " send att rate" << currAttitudeRateSetpoint.throttle << " " << currAttitudeRateSetpoint.roll; + + if(isBackendConnected){ + struct frontend_override_data data; + data.enable = 2; //attitude rate + data.time = 0; + data.throttle = currAttitudeRateSetpoint.throttle; + data.roll = currAttitudeRateSetpoint.roll; + data.pitch = currAttitudeRateSetpoint.pitch; + data.yaw = currAttitudeRateSetpoint.yaw; + + //send setpoint + frontend_setoutputoverride(conn, &data); + } } void CrazyflieWorker::sendAttSetpoint() { - struct frontend_override_data data; - data.enable = 1; //attitude - data.time = 0.2; //hold setpoint for 0.2 seconds TODO - data.throttle = currAttitudeSetpoint.throttle; - data.roll = currAttitudeSetpoint.roll; - data.pitch = currAttitudeSetpoint.pitch; - data.yaw = currAttitudeSetpoint.yaw; - - //send setpoint - frontend_setoutputoverride(conn, &data); + qInfo() << " send att" << currAttitudeSetpoint.throttle; + + if(isBackendConnected){ + struct frontend_override_data data; + data.enable = 1; //attitude + data.time = 0; + data.throttle = currAttitudeSetpoint.throttle; + data.roll = currAttitudeSetpoint.roll; + data.pitch = currAttitudeSetpoint.pitch; + data.yaw = currAttitudeSetpoint.yaw; + + //send setpoint + frontend_setoutputoverride(conn, &data); + } +} + +void CrazyflieWorker::sendMixedAttSetpoint(){ + + qInfo() << "send mixed setpoint"; + + if(isBackendConnected){ + struct frontend_override_data data; + data.enable = 3; //roll and pitch are attitude, yaw is attitude angle + data.time = 0; + data.throttle = currAttitudeSetpoint.throttle; + data.roll = currAttitudeSetpoint.roll; + data.pitch = currAttitudeSetpoint.pitch; + data.yaw = currAttitudeRateSetpoint.yaw; + + //send setpoint + frontend_setoutputoverride(conn, &data); + } } void CrazyflieWorker::getParamValue(QString paramName){ diff --git a/groundStation/gui/MicroCART/crazyflieworker.h b/groundStation/gui/MicroCART/crazyflieworker.h index 104d37b86b3659fecdf0bcd248a438ade64060a8..43d37fc4955d23b4a245edf254aba96823017d7d 100644 --- a/groundStation/gui/MicroCART/crazyflieworker.h +++ b/groundStation/gui/MicroCART/crazyflieworker.h @@ -52,6 +52,7 @@ public slots: void disconnectBackend(); void sendAttSetpoint(); void sendAttRateSetpoint(); + void sendMixedAttSetpoint(); void getParamValue(QString paramName); void setCurrAttSetpoint(float roll, float pitch, float yaw, float throttle); void setCurrAttRateSetpoint(float rollRate, float pitchRate, float yawRate, float throttleRate); @@ -62,8 +63,6 @@ private: struct backend_conn * conn; Setpoint currAttitudeSetpoint; Setpoint currAttitudeRateSetpoint; - void sendAttitudeSetpoint(); - void sendAttitudeRateSetpoint(); std::string getLogFile(int type); void loadParamIds(); void loadLogIds(); @@ -74,6 +73,7 @@ private: QMap<QString, struct toc_info> logIds; std::vector<struct toc_group> paramGroups; std::vector<struct toc_group> logGroups; + bool isBackendConnected = false; }; #endif // CRAZYFLIEWORKER_H diff --git a/groundStation/gui/MicroCART/gamepadmonitor.cpp b/groundStation/gui/MicroCART/gamepadmonitor.cpp index 09f936fc56062f8b9f92e4c24f58974d87256312..486e2d929dbfd1c60d33ec0e31bb79b48b99bccb 100644 --- a/groundStation/gui/MicroCART/gamepadmonitor.cpp +++ b/groundStation/gui/MicroCART/gamepadmonitor.cpp @@ -5,10 +5,10 @@ GamepadMonitor::GamepadMonitor(QObject *parent) : QObject(parent) { m_gamepadManager = QGamepadManager::instance(); - rollScale = 20; //-20 to 20 deg/s - pitchScale = 20; - yawScale = 30; - thrustScale = 30000; //0 to 60,000 thrust + rollScale = DEFAULT_ROLL_SCALE; + pitchScale = DEFAULT_PITCH_SCALE; + yawScale = DEFAULT_YAW_SCALE; + thrustScale = DEFAULT_THRUST_SCALE; connect(m_gamepadManager, SIGNAL(gamepadConnected(int)), this, SLOT(gamepadConnectedHandler(int))); connect(m_gamepadManager, SIGNAL(gamepadDisconnected(int)), this, SLOT(gamepadDisconnectedHandler(int))); @@ -41,6 +41,12 @@ bool GamepadMonitor::isGamepadConnected(){ void GamepadMonitor::resetConfig(){ qInfo() << "gamepad config reset"; + + rollScale = DEFAULT_ROLL_SCALE; + pitchScale = DEFAULT_PITCH_SCALE; + yawScale = DEFAULT_YAW_SCALE; + thrustScale = DEFAULT_THRUST_SCALE; + m_gamepadManager->resetConfiguration(m_gamepad->deviceId()); } @@ -73,7 +79,40 @@ float GamepadMonitor::getPitch(){ } float GamepadMonitor::getThrust(){ - return (float) (m_gamepad->axisLeftY() + 1) * thrustScale; + //first scale range (-1, 1) to (-scale/2 , scale/2) + //then shift range to (0, scale) + //multiplying by range first allows for inverting input + return (float) (m_gamepad->axisLeftY() * thrustScale/2 ) + (std::abs(thrustScale)/2) ; +} + +void GamepadMonitor::setRollScale(float scale){ + rollScale = scale; +} + +void GamepadMonitor::setYawScale(float scale){ + yawScale = scale; +} + +void GamepadMonitor::setPitchScale(float scale){ + pitchScale = scale; +} + +void GamepadMonitor::setThrustScale(float scale){ + thrustScale = scale; +} + + +float GamepadMonitor::getRollScale(){ + return rollScale; +} +float GamepadMonitor::getPitchScale(){ + return pitchScale; +} +float GamepadMonitor::getYawScale(){ + return yawScale; +} +float GamepadMonitor::getThrustScale(){ + return thrustScale; } GamepadMonitor::~GamepadMonitor(){ diff --git a/groundStation/gui/MicroCART/gamepadmonitor.h b/groundStation/gui/MicroCART/gamepadmonitor.h index 5b3ef05cd76daef5ce874c70d814876876aaa3fc..dfb25f101283ff1f37be38697ecb24ee3985c7d9 100644 --- a/groundStation/gui/MicroCART/gamepadmonitor.h +++ b/groundStation/gui/MicroCART/gamepadmonitor.h @@ -5,6 +5,12 @@ #include <QtGamepad/QGamepad> +#define DEFAULT_ROLL_SCALE 30 //deg +#define DEFAULT_PITCH_SCALE 30 //deg +#define DEFAULT_YAW_SCALE 45 //deg / s +#define DEFAULT_THRUST_SCALE 60000 + + class GamepadMonitor : public QObject { Q_OBJECT @@ -21,6 +27,16 @@ public: void configureAxis(QString axisName); void resetConfig(); + void setRollScale(float scale); + void setPitchScale(float scale); + void setYawScale(float scale); + void setThrustScale(float scale); + + float getRollScale(); + float getPitchScale(); + float getYawScale(); + float getThrustScale(); + private: QGamepad *m_gamepad; diff --git a/groundStation/gui/MicroCART/mainwindow.cpp b/groundStation/gui/MicroCART/mainwindow.cpp index 26cd4162ec2ee856c5a9d92e39b0c4cd4db7268c..7835d8577024d76db089e0e87d9bbf5cbf415ec6 100644 --- a/groundStation/gui/MicroCART/mainwindow.cpp +++ b/groundStation/gui/MicroCART/mainwindow.cpp @@ -103,17 +103,21 @@ MainWindow::MainWindow(QWidget *parent) : crazyflieWorker->moveToThread(cfThread); /* connect signals for crazyflie worker */ - connect(this, SIGNAL (rateSetpointSignal(float, float, float, float)), crazyflieWorker, SLOT (setCurrAttSetpoint(float, float, float, float))); - connect(this, SIGNAL (angleSetpointSignal(float, float, float, float)), crazyflieWorker, SLOT (setCurrAttRateSetpoint(float, float, float, float))); - crazyflieTimer->setSingleShot(true); - connect(crazyflieTimer, SIGNAL(timeout()), this, SLOT (on_stopSetpointButton_clicked())); + 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))); + connect(crazyflieTimer, SIGNAL(timeout()), this, SLOT(trigger_send_setpoint())); + connect(this, SIGNAL(triggerAttSetpointSend()), crazyflieWorker, SLOT(sendAttSetpoint())); + connect(this, SIGNAL(triggerAttRateSetpointSend()), crazyflieWorker, SLOT(sendAttRateSetpoint())); + connect(this, SIGNAL(triggerMixedAttSetpointSend()), crazyflieWorker, SLOT(sendMixedAttSetpoint())); connect(crazyflieWorker, SIGNAL (gotParamGroups(QStringList)), this, SLOT (setParamGroups(QStringList))); + connect(ui->paramGroupComboBox, SIGNAL (currentIndexChanged(int)), this, SLOT (getGroupBoxChange(int))); connect(ui->paramGroupComboBox_2, SIGNAL (currentIndexChanged(int)), this, SLOT (getGroupBox2Change(int))); connect(ui->paramEntriesComboBox, SIGNAL (currentIndexChanged(int)), this, SLOT (getEntryBoxChange(int))); connect(ui->paramEntriesComboBox_2, SIGNAL (currentIndexChanged(int)), this, SLOT (getEntryBoxChange2(int))); connect(ui->pb_getParam, SIGNAL (clicked()), this, SLOT (on_pb_getParam_click())); connect(ui->pb_setParam, SIGNAL (clicked()), this, SLOT (on_pb_setParam_click())); + connect(crazyflieWorker, SIGNAL (gotGroupEntries(int, QStringList)), this, SLOT (newGroupEntries(int, QStringList))); connect(this, SIGNAL (getGroupEntries(int, QString)), crazyflieWorker, SLOT (getGroupEntries(int, QString))); connect(this, SIGNAL (getParamValue(QString)), crazyflieWorker, SLOT (getParamValue(QString))); @@ -124,9 +128,11 @@ MainWindow::MainWindow(QWidget *parent) : connect(workerStartTimer, SIGNAL (timeout()), trackerWorker, SLOT (connectBackend())); connect(workerStartTimer, SIGNAL (timeout()), controlWorker, SLOT (connectBackend())); connect(workerStartTimer, SIGNAL (timeout()), crazyflieWorker, SLOT (connectBackend())); + connect(this, SIGNAL (connectWorkers()), trackerWorker, SLOT (connectBackend())); connect(this, SIGNAL (connectWorkers()), controlWorker, SLOT (connectBackend())); connect(this, SIGNAL (connectWorkers()), crazyflieWorker, SLOT (connectBackend())); + connect(this, SIGNAL (disconnectWorkers()), trackerWorker, SLOT (disconnectBackend())); connect(this, SIGNAL (disconnectWorkers()), controlWorker, SLOT (disconnectBackend())); connect(this, SIGNAL (disconnectWorkers()), crazyflieWorker, SLOT (disconnectBackend())); @@ -158,6 +164,7 @@ MainWindow::MainWindow(QWidget *parent) : /* Start the things */ trackerTimer->start(100); + crazyflieTimer->start(100); workerThread->start(); cwThread->start(); cfThread->start(); @@ -191,6 +198,13 @@ MainWindow::MainWindow(QWidget *parent) : connect(pollGamepadTimer, SIGNAL(timeout()), this, SLOT(updateGamepad())); pollGamepadTimer->start(50); + //gamepad configure tab setup + ui->gamepadRollScale->setValue((int)gamepadMonitor->getRollScale()); + ui->gamepadPitchScale->setValue((int)gamepadMonitor->getPitchScale()); + ui->gamepadYawScale->setValue((int)gamepadMonitor->getYawScale()); + ui->gamepadThrustScale->setValue((int)gamepadMonitor->getThrustScale()); + + /* Populate scripts list */ QDir scriptsDir("scripts/"); @@ -755,8 +769,6 @@ void MainWindow::on_applySetpointButton_clicked() sp_yaw = ui->yawSetpointBox->text().toFloat(); sp_thrust = ui->tActual -> value(); - crazyflieTimer -> start(10000); - if(ui->angleRadioButton->isChecked()) { //send as angle setpoint emit(angleSetpointSignal(sp_roll, sp_pitch, sp_yaw, sp_thrust)); @@ -795,12 +807,16 @@ void MainWindow::on_tActual_sliderMoved(int position) /******** Gamepad handlers ********/ void MainWindow::onGamepadDisconnect(){ + crazyflieWorker->setCurrAttRateSetpoint(0,0,0,0); + //navigation tab ui->pitchSetpointBox->setText("0"); ui->rollSetpointBox->setText("0"); ui->yawSetpointBox->setText("0"); ui->tActual->setValue(0); + ui->rbManualSetpoint->setChecked(true); + //gamepad tab ui->noGamepadWarning->show(); ui->rbGamepadControl->setEnabled(false); ui->pb_configPitch->setEnabled(false); @@ -808,17 +824,42 @@ void MainWindow::onGamepadDisconnect(){ ui->pb_configYaw->setEnabled(false); ui->pb_configThrust->setEnabled(false); ui->pb_resetConfig->setEnabled(false); - ui->rbManualSetpoint->setChecked(true); + ui->gamepadRollScale->setEnabled(false); + ui->rollScaleLabel->setEnabled(false); + ui->gamepadPitchScale->setEnabled(false); + ui->pitchScaleLabel->setEnabled(false); + ui->gamepadYawScale->setEnabled(false); + ui->yawScaleLabel->setEnabled(false); + ui->gamepadThrustScale->setEnabled(false); + ui->thrustScaleLabel->setEnabled(false); + ui->thrustScaleNote->setEnabled(false); + + + } void MainWindow::onGamepadConnect(){ - ui->noGamepadWarning->hide(); + + //navigation tab ui->rbGamepadControl->setEnabled(true); + + //gamepad tab + ui->noGamepadWarning->hide(); ui->pb_configPitch->setEnabled(true); ui->pb_configRoll->setEnabled(true); ui->pb_configYaw->setEnabled(true); ui->pb_configThrust->setEnabled(true); ui->pb_resetConfig->setEnabled(true); + + ui->gamepadRollScale->setEnabled(true); + ui->rollScaleLabel->setEnabled(true); + ui->gamepadPitchScale->setEnabled(true); + ui->pitchScaleLabel->setEnabled(true); + ui->gamepadYawScale->setEnabled(true); + ui->yawScaleLabel->setEnabled(true); + ui->gamepadThrustScale->setEnabled(true); + ui->thrustScaleLabel->setEnabled(true); + ui->thrustScaleNote->setEnabled(true); } void MainWindow::updateGamepad(){ @@ -835,7 +876,10 @@ void MainWindow::updateGamepad(){ float yaw = gamepadMonitor->getYaw(); float thrust = gamepadMonitor->getThrust(); - crazyflieWorker->setCurrAttRateSetpoint(roll, pitch, yaw, thrust); + //create mixed setpoint + crazyflieWorker->setCurrAttSetpoint(roll, pitch, 0, thrust); + crazyflieWorker->setCurrAttRateSetpoint(0, 0, yaw, 0); + ui->rollSetpointBox->setText(QString::number(roll)); ui->pitchSetpointBox->setText(QString::number(pitch)); ui->yawSetpointBox->setText(QString::number(yaw)); @@ -847,6 +891,10 @@ void MainWindow::updateGamepad(){ void MainWindow::on_pb_resetConfig_clicked() { gamepadMonitor->resetConfig(); + ui->gamepadRollScale->setValue((int)gamepadMonitor->getRollScale()); + ui->gamepadPitchScale->setValue((int)gamepadMonitor->getPitchScale()); + ui->gamepadYawScale->setValue((int)gamepadMonitor->getYawScale()); + ui->gamepadThrustScale->setValue((int)gamepadMonitor->getThrustScale()); } void MainWindow::on_pb_configRoll_clicked() @@ -875,6 +923,7 @@ void MainWindow::on_rbManualSetpoint_toggled(bool checked) { if(checked) { crazyflieWorker->setCurrAttRateSetpoint(0,0,0,0); + crazyflieWorker->setCurrAttSetpoint(0,0,0,0); ui->pitchSetpointBox->setText("0"); ui->rollSetpointBox->setText("0"); ui->yawSetpointBox->setText("0"); @@ -885,16 +934,62 @@ void MainWindow::on_rbManualSetpoint_toggled(bool checked) ui->tActual-> setEnabled(true); ui->angleRadioButton-> setEnabled(true); ui->rateRadioButton-> setEnabled(true); + ui->applySetpointButton->setEnabled(true); + ui->stopSetpointButton->setEnabled(true); } } void MainWindow::on_rbGamepadControl_toggled(bool checked) { - ui->rollSetpointBox-> setEnabled(false); - ui->pitchSetpointBox-> setEnabled(false); - ui->yawSetpointBox-> setEnabled(false); - ui->tActual-> setEnabled(false); - ui->angleRadioButton-> setEnabled(false); - ui->rateRadioButton-> setEnabled(false); - ui->rateRadioButton-> setChecked(true); + + if(checked){ + ui->rollSetpointBox-> setEnabled(false); + ui->pitchSetpointBox-> setEnabled(false); + ui->yawSetpointBox-> setEnabled(false); + ui->tActual-> setEnabled(false); + ui->angleRadioButton-> setEnabled(false); + ui->rateRadioButton-> setEnabled(false); + ui->applySetpointButton->setEnabled(false); + ui->stopSetpointButton->setEnabled(false); + } +} + +void MainWindow::trigger_send_setpoint(){ + if(ui->rbGamepadControl->isChecked()){ + //using gamepad, send mixed attitude setpoint + emit(triggerMixedAttSetpointSend()); + }else{ + if(ui->angleRadioButton->isChecked()){ + emit(triggerAttSetpointSend()); + }else{ + emit(triggerAttRateSetpointSend()); + } + } +} + +void MainWindow::on_gamepadYawScale_valueChanged(int arg1) +{ + gamepadMonitor->setYawScale(arg1); + ui->yawVizBar->setMinimum(std::abs(arg1) * -1); + ui->yawVizBar->setMaximum(std::abs(arg1)); +} + +void MainWindow::on_gamepadThrustScale_valueChanged(int arg1) +{ + gamepadMonitor->setThrustScale(arg1); + //Dont need to change the scale of the thrust viz bar because it is always interpreted as 0 to 60,000 +} + +void MainWindow::on_gamepadRollScale_valueChanged(int arg1) +{ + gamepadMonitor->setRollScale(arg1); + ui->rollVizBar->setMinimum(std::abs(arg1) * -1); + ui->rollVizBar->setMaximum(std::abs(arg1)); +} + +void MainWindow::on_gamepadPitchScale_valueChanged(int arg1) +{ + gamepadMonitor->setPitchScale(arg1); + ui->pitchVizBar->setMinimum(std::abs(arg1) * -1); + ui->pitchVizBar->setMaximum(std::abs(arg1)); } diff --git a/groundStation/gui/MicroCART/mainwindow.h b/groundStation/gui/MicroCART/mainwindow.h index 725a74d3cc53e878ee86cbf8ef8bd963dcbb620e..becd6e3f5fd15b3c483179d270324619c860f251 100644 --- a/groundStation/gui/MicroCART/mainwindow.h +++ b/groundStation/gui/MicroCART/mainwindow.h @@ -34,6 +34,9 @@ signals: void rateSetpointSignal(float roll, float pitch, float yaw, float throttle); void angleSetpointSignal(float roll, float pitch, float yaw, float throttle); void getGroupEntries(int box, QString gName); + void triggerAttSetpointSend(); + void triggerAttRateSetpointSend(); + void triggerMixedAttSetpointSend(); private slots: void on_pbStart_clicked(); @@ -133,6 +136,16 @@ private slots: void on_rbManualSetpoint_toggled(bool checked); + void trigger_send_setpoint(); + + void on_gamepadYawScale_valueChanged(int arg1); + + void on_gamepadThrustScale_valueChanged(int arg1); + + void on_gamepadRollScale_valueChanged(int arg1); + + void on_gamepadPitchScale_valueChanged(int arg1); + private: Ui::MainWindow *ui; QStandardItemModel * setpointList; diff --git a/groundStation/gui/MicroCART/mainwindow.ui b/groundStation/gui/MicroCART/mainwindow.ui index 34a29f907a8b4e15df6e2f97b7a952d8c9f41269..c202a2c5c0e52b9881d56f6fc694aa9c90ddab89 100644 --- a/groundStation/gui/MicroCART/mainwindow.ui +++ b/groundStation/gui/MicroCART/mainwindow.ui @@ -33,7 +33,7 @@ </size> </property> <property name="currentIndex"> - <number>4</number> + <number>2</number> </property> <widget class="QWidget" name="backend"> <attribute name="title"> @@ -355,7 +355,7 @@ </rect> </property> <property name="text"> - <string>Configure Roll</string> + <string>Bind Roll</string> </property> </widget> <widget class="QSlider" name="rollVizBar"> @@ -371,10 +371,10 @@ </rect> </property> <property name="minimum"> - <number>-20</number> + <number>-30</number> </property> <property name="maximum"> - <number>20</number> + <number>30</number> </property> <property name="value"> <number>0</number> @@ -406,7 +406,7 @@ </rect> </property> <property name="text"> - <string>Configure Yaw</string> + <string>Bind Yaw</string> </property> </widget> <widget class="QSlider" name="yawVizBar"> @@ -422,10 +422,10 @@ </rect> </property> <property name="minimum"> - <number>-30</number> + <number>-45</number> </property> <property name="maximum"> - <number>30</number> + <number>45</number> </property> <property name="value"> <number>0</number> @@ -433,6 +433,9 @@ <property name="orientation"> <enum>Qt::Horizontal</enum> </property> + <property name="tickPosition"> + <enum>QSlider::NoTicks</enum> + </property> </widget> <widget class="QSlider" name="thrustVizBar"> <property name="enabled"> @@ -440,7 +443,7 @@ </property> <property name="geometry"> <rect> - <x>220</x> + <x>223</x> <y>190</y> <width>16</width> <height>160</height> @@ -462,17 +465,17 @@ </property> <property name="geometry"> <rect> - <x>780</x> + <x>783</x> <y>180</y> <width>16</width> <height>160</height> </rect> </property> <property name="minimum"> - <number>-20</number> + <number>-30</number> </property> <property name="maximum"> - <number>20</number> + <number>30</number> </property> <property name="value"> <number>0</number> @@ -484,41 +487,43 @@ <widget class="QPushButton" name="pb_configThrust"> <property name="geometry"> <rect> - <x>250</x> - <y>260</y> + <x>246</x> + <y>280</y> <width>141</width> <height>25</height> </rect> </property> <property name="text"> - <string>Configure Thrust</string> + <string>Bind Thrust</string> </property> </widget> <widget class="QPushButton" name="pb_configPitch"> <property name="geometry"> <rect> <x>810</x> - <y>250</y> + <y>270</y> <width>141</width> <height>25</height> </rect> </property> <property name="text"> - <string>Configure Pitch</string> + <string>Bind Pitch</string> </property> </widget> <widget class="QLabel" name="noGamepadWarning"> <property name="geometry"> <rect> - <x>360</x> + <x>381</x> <y>10</y> - <width>381</width> + <width>311</width> <height>61</height> </rect> </property> <property name="font"> <font> <pointsize>20</pointsize> + <underline>true</underline> + <kerning>true</kerning> </font> </property> <property name="text"> @@ -531,25 +536,261 @@ <set>Qt::AlignCenter</set> </property> </widget> - <widget class="QLabel" name="label_6"> + <widget class="QLabel" name="yawScaleLabel"> <property name="geometry"> <rect> - <x>450</x> - <y>130</y> - <width>181</width> - <height>91</height> + <x>162</x> + <y>113</y> + <width>211</width> + <height>20</height> </rect> </property> <property name="text"> - <string>Select the input to bind then move the joystick that will control that input</string> + <string>Yaw Scale: Deg / s</string> </property> - <property name="alignment"> - <set>Qt::AlignCenter</set> + </widget> + <widget class="QSpinBox" name="gamepadYawScale"> + <property name="geometry"> + <rect> + <x>240</x> + <y>110</y> + <width>51</width> + <height>26</height> + </rect> + </property> + <property name="minimum"> + <number>-999</number> + </property> + <property name="maximum"> + <number>999</number> + </property> + <property name="value"> + <number>45</number> + </property> + </widget> + <widget class="QWidget" name="horizontalLayoutWidget"> + <property name="geometry"> + <rect> + <x>160</x> + <y>390</y> + <width>791</width> + <height>151</height> + </rect> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Select the input to bind then move the joystick that will control that input to its maximum values.</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string>The scale of each input controls the maximum values sent to the Crazyflie with max joystick deflection. </string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_8"> + <property name="text"> + <string>Negative scale values can be used to invert a joystick if needed.</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QSpinBox" name="gamepadThrustScale"> + <property name="geometry"> + <rect> + <x>342</x> + <y>228</y> + <width>71</width> + <height>26</height> + </rect> + </property> + <property name="minimum"> + <number>-60000</number> </property> - <property name="wordWrap"> + <property name="maximum"> + <number>60000</number> + </property> + <property name="value"> + <number>60000</number> + </property> + </widget> + <widget class="QLabel" name="thrustScaleLabel"> + <property name="geometry"> + <rect> + <x>247</x> + <y>230</y> + <width>191</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Thrust Scale: </string> + </property> + </widget> + <widget class="QLabel" name="thrustScaleNote"> + <property name="geometry"> + <rect> + <x>248</x> + <y>256</y> + <width>221</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Note: max thrust is 60,000</string> + </property> + </widget> + <widget class="QSpinBox" name="gamepadRollScale"> + <property name="geometry"> + <rect> + <x>798</x> + <y>100</y> + <width>51</width> + <height>26</height> + </rect> + </property> + <property name="minimum"> + <number>-999</number> + </property> + <property name="maximum"> + <number>999</number> + </property> + <property name="value"> + <number>30</number> + </property> + </widget> + <widget class="QLabel" name="rollScaleLabel"> + <property name="enabled"> <bool>true</bool> </property> + <property name="geometry"> + <rect> + <x>720</x> + <y>103</y> + <width>211</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Roll Scale: Deg</string> + </property> + </widget> + <widget class="QSpinBox" name="gamepadPitchScale"> + <property name="geometry"> + <rect> + <x>895</x> + <y>239</y> + <width>51</width> + <height>26</height> + </rect> + </property> + <property name="minimum"> + <number>-999</number> + </property> + <property name="maximum"> + <number>999</number> + </property> + <property name="value"> + <number>30</number> + </property> </widget> + <widget class="QLabel" name="pitchScaleLabel"> + <property name="geometry"> + <rect> + <x>812</x> + <y>242</y> + <width>211</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Pitch Scale: Deg</string> + </property> + </widget> + <zorder>pitchScaleLabel</zorder> + <zorder>rollScaleLabel</zorder> + <zorder>thrustScaleLabel</zorder> + <zorder>yawScaleLabel</zorder> + <zorder>pb_configRoll</zorder> + <zorder>rollVizBar</zorder> + <zorder>pb_resetConfig</zorder> + <zorder>pb_configYaw</zorder> + <zorder>yawVizBar</zorder> + <zorder>thrustVizBar</zorder> + <zorder>pitchVizBar</zorder> + <zorder>pb_configThrust</zorder> + <zorder>pb_configPitch</zorder> + <zorder>noGamepadWarning</zorder> + <zorder>gamepadYawScale</zorder> + <zorder>horizontalLayoutWidget</zorder> + <zorder>gamepadThrustScale</zorder> + <zorder>thrustScaleNote</zorder> + <zorder>gamepadRollScale</zorder> + <zorder>gamepadPitchScale</zorder> </widget> <widget class="QWidget" name="plots"> <attribute name="title"> @@ -949,7 +1190,7 @@ <resources/> <connections/> <buttongroups> - <buttongroup name="AngleRateButtonGroup"/> <buttongroup name="buttonGroup_2"/> + <buttongroup name="AngleRateButtonGroup"/> </buttongroups> </ui>