Commit 8695b4d0 authored by Svetlana Pavlitskaya's avatar Svetlana Pavlitskaya

TORCS client without delay

parent c4ae23eb
......@@ -171,35 +171,42 @@ void TorcsClient::iterate()
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
bool firstRun = true;
shared->written = 0;
shared->pause = 1;
shared->control = 1;
bool firstShot = true;
bool readyForNewShot = true;
while (true) {
while(shared->written == 0) {
if (firstRun) {
firstRun = false;
shared->written = 0;
shared->pause = 1;
using namespace std::chrono_literals;
std::this_thread::sleep_for(1ms);
shared->control = 1;
}
auto screenshot = std::make_shared<DataContainer>();
memcpy(screenshot->data(), shared->data, screenshot->size());
shared->written = 0;
Affordance affordance;
affordance.populate(*shared); // ground truth affordance
publishCallback(screenshot, affordance);
if (shared->control == 1) {
shared->pause = 1;
while(!gotCommand) {
using namespace std::chrono_literals;
std::this_thread::sleep_for(5ms);
if (shared->written == 1) { // the new image data is ready to be read
if (!readyForNewShot)
{
shared->written = 0;
}
else
{
readyForNewShot = false;
auto screenshot = std::make_shared<DataContainer>();
memcpy(screenshot->data(), shared->data, screenshot->size());
shared->written = 0;
Affordance affordance;
affordance.populate(*shared); // ground truth affordance
publishCallback(screenshot, affordance);
firstShot = false;
}
}
if (gotCommand)
{
gotCommand = false;
readyForNewShot = true;
//shared->pause = 0;
//shared->control = 1;
shared->accelCmd = command.accelCmd;
shared->steerCmd = command.steerCmd;
shared->brakeCmd = command.brakeCmd;
}
shared->pause = 0;
}
#pragma clang diagnostic pop
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment