Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop the robots when the stop receiving packages for 1 sec #168

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/sslworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class SSLWorld : public QObject
QUdpSocket *simControlSocket;
QUdpSocket *blueControlSocket;
QUdpSocket *yellowControlSocket;

QElapsedTimer elapsedLastPackageBlue;
QElapsedTimer elapsedLastPackageYellow;

bool updatedCursor;
Robot* robots[MAX_ROBOT_COUNT*2]{};
int sendGeomCount;
Expand Down
38 changes: 37 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ MainWindow::MainWindow(QWidget *parent)
QObject::connect(simControlSocket,SIGNAL(readyRead()),this,SLOT(simControlSocketReady()));
QObject::connect(blueControlSocket,SIGNAL(readyRead()),this,SLOT(blueControlSocketReady()));
QObject::connect(yellowControlSocket,SIGNAL(readyRead()),this,SLOT(yellowControlSocketReady()));

glwidget->ssl->visionServer = visionServer;
glwidget->ssl->commandSocket = commandSocket;
glwidget->ssl->blueStatusSocket = blueStatusSocket;
Expand Down Expand Up @@ -410,6 +410,42 @@ void MainWindow::update()
noiselabel->setVisible(configwidget->noise());
cursorlabel->setText(QString("Cursor: [X=%1;Y=%2;Z=%3]").arg(dRealToStr(glwidget->ssl->cursor_x)).arg(dRealToStr(glwidget->ssl->cursor_y)).arg(dRealToStr(glwidget->ssl->cursor_z)));
statusWidget->update();

if(glwidget != nullptr && glwidget->ssl != nullptr)
{
// Stops blue robots from moving if no package has been received for 1 second
if(glwidget->ssl->elapsedLastPackageBlue.nsecsElapsed()*1e-9 > 1)
{
for(int i=0; i < glwidget->cfg->Robots_Count(); ++i)
{
const int index = glwidget->ssl->robotIndex(i, BLUE-1);

if(index == -1 ||
glwidget->ssl->robots[index] == nullptr)
continue;
Bollos00 marked this conversation as resolved.
Show resolved Hide resolved

glwidget->ssl->robots[index]->resetSpeeds();
// glwidget->ssl->robots[index]->kicker->setRoller(0);
Bollos00 marked this conversation as resolved.
Show resolved Hide resolved
// glwidget->ssl->robots[index]->kicker->kick(0, 0);
}
}
// Stops yellow robots from moving if no package has been received for 1 second
if(glwidget->ssl->elapsedLastPackageYellow.nsecsElapsed()*1e-9 > 1)
{
for(int i=0; i < glwidget->cfg->Robots_Count(); ++i)
{
const int index = glwidget->ssl->robotIndex(i, YELLOW-1);

if(index == -1 ||
glwidget->ssl->robots[index] == nullptr)
continue;

glwidget->ssl->robots[index]->resetSpeeds();
// glwidget->ssl->robots[index]->kicker->setRoller(0);
// glwidget->ssl->robots[index]->kicker->kick(0, 0);
}
}
}
}

void MainWindow::updateRobotLabel()
Expand Down
7 changes: 7 additions & 0 deletions src/sslworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ SSLWorld::SSLWorld(QGLWidget* parent, ConfigWidget* _cfg, RobotsFormation *form1
}

restartRequired = false;

elapsedLastPackageBlue.start();
elapsedLastPackageYellow.start();
}

int SSLWorld::robotIndex(int robot,int team) {
Expand Down Expand Up @@ -705,6 +708,8 @@ void SSLWorld::blueControlSocketReady() {
robotControlResponse.SerializeToArray(buffer.data(), buffer.size());
blueControlSocket->writeDatagram(buffer.data(), buffer.size(), datagram.senderAddress(), datagram.senderPort());
}

elapsedLastPackageBlue.start();
}

void SSLWorld::yellowControlSocketReady() {
Expand All @@ -723,6 +728,8 @@ void SSLWorld::yellowControlSocketReady() {
robotControlResponse.SerializeToArray(buffer.data(), buffer.size());
yellowControlSocket->writeDatagram(buffer.data(), buffer.size(), datagram.senderAddress(), datagram.senderPort());
}

elapsedLastPackageYellow.start();
}


Expand Down