This commit is contained in:
ackimixs
2024-05-15 18:10:17 +02:00
parent b08d89407d
commit d10aa4baf3
2 changed files with 2 additions and 32 deletions

View File

@@ -173,7 +173,7 @@ void TCPServer::handleMessage(const std::string& message, int clientSocket)
}
}
else if (args[0] == "1") {
int speed = static_cast<int>((- value * 3.2) / 327.670f);
int speed = static_cast<int>((- value * 3.1) / 327.670f);
if (!handleEmergecnyFlag) {
this->broadcastMessage("strat;arduino;speed;" + std::to_string(speed) + "\n");
}
@@ -187,7 +187,7 @@ void TCPServer::handleMessage(const std::string& message, int clientSocket)
}
}
else if (args[0] == "2") {
double speed = static_cast<int>((value * 3.2) / 327.670f);
double speed = static_cast<int>((value * 3.1) / 327.670f);
this->broadcastMessage("start;arduino;rotate;" + std::to_string(speed));
}
}
@@ -227,13 +227,6 @@ void TCPServer::handleMessage(const std::string& message, int clientSocket)
this->broadcastMessage("strat;arduino;clear;1\n");
}
}
else if (tokens[0] == "arduino") {
if (tokens[2] == "set pos") {
std::vector<std::string> pos = TCPUtils::split(tokens[3], ",");
this->robotPose = {std::stof(pos[0]), std::stof(pos[1]), std::stof(pos[2]) / 100};
this->sendToClient("strat;lidar;set pos;" + std::to_string(this->robotPose.pos.x) + "," + std::to_string(this->robotPose.pos.y) + "," + std::to_string(this->robotPose.theta) + "\n", lidarSocket);
}
}
}
void TCPServer::broadcastMessage(const char* message, int senderSocket)
@@ -371,27 +364,6 @@ void TCPServer::checkIfAllClientsReady() {
if (allReady)
{
this->broadcastMessage("strat;all;ready;1\n");
std::thread([this]() { askArduinoPos(); }).detach();
this->broadcastMessage("strat;arduino;set pos;0,0,0");
this->broadcastMessage("strat;arduino;set pos;0,0,0");
}
}
void TCPServer::askArduinoPos() {
for (const auto & client : clients) {
if (client.name == "arduino") {
this->arduinoSocket = client.socket;
break;
}
}
if (this->arduinoSocket == -1) {
return;
}
while (!this->_shouldStop) {
this->sendToClient("strat;arduino;get pos;1\n", this->arduinoSocket);
usleep(50'000);
}
}

View File

@@ -106,8 +106,6 @@ public:
void stop();
void askArduinoPos();
[[nodiscard]] size_t nbClients() const;
[[nodiscard]] bool shouldStop() const;