Aufgrund einer Wartung wird GitLab am 28.09. zwischen 10:00 und 11:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 28.09. between 10:00 and 11:00 am.

Commit c8549d76 authored by Svetlana's avatar Svetlana

Controlling TORCS car via messages received from the mastercomponent

parent e659b7a3
...@@ -81,54 +81,3 @@ std::unique_ptr<DataContainer> TorcsClient::getScreenshot() ...@@ -81,54 +81,3 @@ std::unique_ptr<DataContainer> TorcsClient::getScreenshot()
return result; return result;
} }
void TorcsClient::sendCommand(Command cmd)
{
assert(connected);
while (shared->control == 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
shared->accelCmd = cmd.accelCmd;
shared->steerCmd = cmd.steerCmd;
shared->brakeCmd = cmd.brakeCmd;
shared->control = 0;
//shared->accelCmd = 10.0;
//shared->steerCmd = 1.0;
}
/*void writeScreenshot(shared_use_st* shared, unsigned int& num)
{
std::cout << "Read image." << std::endl;
FIBITMAP* newShot = FreeImage_Allocate(IMAGE_WIDTH, IMAGE_HEIGHT, 24);
if (!newShot)
{
std::cerr << "Failed to allocate freeimage file." << std::endl;
FreeImage_Unload(newShot);
return;
}
BYTE *bits = (BYTE*)FreeImage_GetBits(newShot);
for (int h = 0; h < IMAGE_HEIGHT; h++) {
BYTE *pixel = (BYTE*)bits;
for (int w = 0; w < IMAGE_WIDTH; w++) {
pixel[FI_RGBA_RED] = shared->data[((h)*IMAGE_WIDTH+w)*3+0];
pixel[FI_RGBA_GREEN] = shared->data[((h)*IMAGE_WIDTH+w)*3+1];
pixel[FI_RGBA_BLUE] = shared->data[((h)*IMAGE_WIDTH+w)*3+2];
pixel += 3;
}
bits += 3*IMAGE_WIDTH;
}
FreeImage_Save(FIF_BMP, newShot, (std::string("shot-")+std::to_string(num)).c_str());
FreeImage_Unload(newShot);
shared->control = 0;
shared->written = 0;
std::this_thread::sleep_for(std::chrono::seconds(2));std::cout << "Read image." << std::endl;
}*/
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
namespace torcs namespace torcs
{ {
constexpr auto IMAGE_WIDTH = 280; constexpr auto IMAGE_WIDTH = 640;
constexpr auto IMAGE_HEIGHT = 210; constexpr auto IMAGE_HEIGHT = 480;
constexpr auto IMAGE_CHANNELS = 3; constexpr auto IMAGE_CHANNELS = 3;
constexpr auto IMAGE_SIZE_BYTES = IMAGE_WIDTH*IMAGE_HEIGHT*IMAGE_CHANNELS; constexpr auto IMAGE_SIZE_BYTES = IMAGE_WIDTH*IMAGE_HEIGHT*IMAGE_CHANNELS;
...@@ -63,7 +63,6 @@ class TorcsClient ...@@ -63,7 +63,6 @@ class TorcsClient
{ {
public: public:
TorcsClient(); TorcsClient();
std::unique_ptr<DataContainer> getScreenshot();
void sendCommand(Command cmd); void sendCommand(Command cmd);
private: private:
......
...@@ -65,27 +65,11 @@ TorcsClient::TorcsClient() ...@@ -65,27 +65,11 @@ TorcsClient::TorcsClient()
shared->brakeCmd = 0.0; shared->brakeCmd = 0.0;
} }
std::unique_ptr<DataContainer> TorcsClient::getScreenshot()
{
assert(connected);
while(shared->written == 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto result = std::make_unique<DataContainer>();
memcpy(result->data(), shared->data, result->size());
shared->written = 0;
return result;
}
void TorcsClient::sendCommand(Command cmd) void TorcsClient::sendCommand(Command cmd)
{ {
assert(connected); assert(connected);
while (shared->control == 0) { while (shared->control == 1) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
...@@ -94,41 +78,5 @@ void TorcsClient::sendCommand(Command cmd) ...@@ -94,41 +78,5 @@ void TorcsClient::sendCommand(Command cmd)
shared->brakeCmd = cmd.brakeCmd; shared->brakeCmd = cmd.brakeCmd;
shared->control = 0; shared->control = 0;
//shared->accelCmd = 10.0;
//shared->steerCmd = 1.0;
} }
/*void writeScreenshot(shared_use_st* shared, unsigned int& num)
{
std::cout << "Read image." << std::endl;
FIBITMAP* newShot = FreeImage_Allocate(IMAGE_WIDTH, IMAGE_HEIGHT, 24);
if (!newShot)
{
std::cerr << "Failed to allocate freeimage file." << std::endl;
FreeImage_Unload(newShot);
return;
}
BYTE *bits = (BYTE*)FreeImage_GetBits(newShot);
for (int h = 0; h < IMAGE_HEIGHT; h++) {
BYTE *pixel = (BYTE*)bits;
for (int w = 0; w < IMAGE_WIDTH; w++) {
pixel[FI_RGBA_RED] = shared->data[((h)*IMAGE_WIDTH+w)*3+0];
pixel[FI_RGBA_GREEN] = shared->data[((h)*IMAGE_WIDTH+w)*3+1];
pixel[FI_RGBA_BLUE] = shared->data[((h)*IMAGE_WIDTH+w)*3+2];
pixel += 3;
}
bits += 3*IMAGE_WIDTH;
}
FreeImage_Save(FIF_BMP, newShot, (std::string("shot-")+std::to_string(num)).c_str());
FreeImage_Unload(newShot);
shared->control = 0;
shared->written = 0;
std::this_thread::sleep_for(std::chrono::seconds(2));std::cout << "Read image." << std::endl;
}*/
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
namespace torcs namespace torcs
{ {
constexpr auto IMAGE_WIDTH = 280; constexpr auto IMAGE_WIDTH = 640;
constexpr auto IMAGE_HEIGHT = 210; constexpr auto IMAGE_HEIGHT = 480;
constexpr auto IMAGE_CHANNELS = 3; constexpr auto IMAGE_CHANNELS = 3;
constexpr auto IMAGE_SIZE_BYTES = IMAGE_WIDTH*IMAGE_HEIGHT*IMAGE_CHANNELS; constexpr auto IMAGE_SIZE_BYTES = IMAGE_WIDTH*IMAGE_HEIGHT*IMAGE_CHANNELS;
...@@ -63,7 +63,6 @@ class TorcsClient ...@@ -63,7 +63,6 @@ class TorcsClient
{ {
public: public:
TorcsClient(); TorcsClient();
std::unique_ptr<DataContainer> getScreenshot();
void sendCommand(Command cmd); void sendCommand(Command cmd);
private: private:
......
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