From 8bde30304c4ecd9f8772f45286e3c479eb85fde1 Mon Sep 17 00:00:00 2001 From: Lukas Bos Date: Wed, 19 Jun 2019 11:02:02 +0200 Subject: [PATCH] Feature/battery stats and refresh (#622) * make division between soft and hard refresh * formatting * add battery low message --- .../interface/widgets/MainControlsWidget.cpp | 32 +++++++++++-------- .../interface/widgets/MainControlsWidget.h | 4 +-- roboteam_ai/src/interface/widgets/widget.cpp | 3 ++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/roboteam_ai/src/interface/widgets/MainControlsWidget.cpp b/roboteam_ai/src/interface/widgets/MainControlsWidget.cpp index 65709c631a..fa1d5342e6 100644 --- a/roboteam_ai/src/interface/widgets/MainControlsWidget.cpp +++ b/roboteam_ai/src/interface/widgets/MainControlsWidget.cpp @@ -55,6 +55,20 @@ MainControlsWidget::MainControlsWidget(QWidget * parent) { } select_ruleset->setStyleSheet(QString::fromUtf8("QComboBox:disabled" "{ color: gray }")); + auto refreshHButtonsLayout = new QHBoxLayout(); + + refreshBtn = new QPushButton("Soft refresh"); + QObject::connect(refreshBtn, SIGNAL(clicked()), this, SLOT(refreshSignal())); + refreshHButtonsLayout->addWidget(refreshBtn); + refreshBtn->setStyleSheet("background-color: #0000cc;"); + + refreshJsonBtn = new QPushButton("Hard refresh"); + QObject::connect(refreshJsonBtn, SIGNAL(clicked()), this, SLOT(refreshJSONSignal())); + refreshHButtonsLayout->addWidget(refreshJsonBtn); + refreshJsonBtn->setStyleSheet("background-color: #0000cc;"); + vLayout->addLayout(refreshHButtonsLayout); + + auto hButtonsLayout = new QHBoxLayout(); haltBtn = new QPushButton("Halt"); @@ -70,11 +84,6 @@ MainControlsWidget::MainControlsWidget(QWidget * parent) { spaceClick = new QShortcut(QKeySequence(Qt::Key_Space), this, SLOT(sendPauseSignal())); spaceClick->setAutoRepeat(false); - refreshBtn = new QPushButton("Refresh"); - QObject::connect(refreshBtn, SIGNAL(clicked()), this, SLOT(refreshSignal())); - hButtonsLayout->addWidget(refreshBtn); - refreshBtn->setStyleSheet("background-color: #0000cc;"); - toggleColorBtn = new QPushButton("Color"); QObject::connect(toggleColorBtn, SIGNAL(clicked()), this, SLOT(toggleOurColorParam())); hButtonsLayout->addWidget(toggleColorBtn); @@ -127,14 +136,6 @@ void MainControlsWidget::setTimeOutTop(bool top) { Output::setTimeOutTop(top); } -QString MainControlsWidget::getSelectStrategyText() const { - return select_strategy->currentText(); -} - -void MainControlsWidget::setSelectStrategyText(QString text) { - select_strategy->setCurrentText(text); -} - void MainControlsWidget::setUseReferee(bool useRef) { Output::setUseRefereeCommands(useRef); @@ -213,6 +214,11 @@ void MainControlsWidget::setToggleSideBtnLayout() const { void MainControlsWidget::refreshSignal() { + robotDealer::RobotDealer::refresh(); + emit treeHasChanged(); +} + +void MainControlsWidget::refreshJSONSignal() { BTFactory::makeTrees(); robotDealer::RobotDealer::refresh(); emit treeHasChanged(); diff --git a/roboteam_ai/src/interface/widgets/MainControlsWidget.h b/roboteam_ai/src/interface/widgets/MainControlsWidget.h index 8537262887..7ce43c2790 100644 --- a/roboteam_ai/src/interface/widgets/MainControlsWidget.h +++ b/roboteam_ai/src/interface/widgets/MainControlsWidget.h @@ -20,8 +20,6 @@ class MainControlsWidget : public QWidget { Q_OBJECT public: explicit MainControlsWidget(QWidget * parent = nullptr); - QString getSelectStrategyText() const; - void setSelectStrategyText(QString text); signals: void treeHasChanged(); @@ -30,6 +28,7 @@ Q_OBJECT QVBoxLayout* vLayout; QPushButton* pauseBtn; QPushButton* refreshBtn; + QPushButton* refreshJsonBtn; QPushButton* toggleColorBtn; QPushButton* toggleSideBtn; QPushButton* haltBtn; @@ -54,6 +53,7 @@ public slots: void updatePause(); void setUseReferee(bool useRef); void refreshSignal(); + void refreshJSONSignal(); void updateContents(); void sendHaltSignal(); }; diff --git a/roboteam_ai/src/interface/widgets/widget.cpp b/roboteam_ai/src/interface/widgets/widget.cpp index 62293facaa..b9c91e027e 100644 --- a/roboteam_ai/src/interface/widgets/widget.cpp +++ b/roboteam_ai/src/interface/widgets/widget.cpp @@ -326,6 +326,9 @@ void Visualizer::drawRobot(QPainter &painter, Robot robot, bool ourTeam) { if (!robot.hasWorkingBallSensor()) { text += "BS "; } + if (robot.isBatteryLow()) { + text += "BATTERY LOW"; + } painter.drawText(robotpos.x, ypos += 20, QString::fromStdString(text)); }