#18 Cleaning up a bit

This commit is contained in:
nsubiron 2017-04-19 13:00:12 +02:00
parent f1733c6c76
commit 1d3b05109f
7 changed files with 130 additions and 344 deletions

View File

@ -1,9 +1,13 @@
#include "CarlaServer.h" #include "CarlaServer.h"
#include <carla/server/Server.h> #include <carla/server/CarlaCommunication.h>
namespace carla { namespace carla {
Image::Image() {}
Image::~Image() {}
Reward_Values::Reward_Values() {} Reward_Values::Reward_Values() {}
Reward_Values::~Reward_Values() {} Reward_Values::~Reward_Values() {}
@ -12,10 +16,13 @@ namespace carla {
Scene_Values::~Scene_Values() {} Scene_Values::~Scene_Values() {}
class CarlaServer::Pimpl : public carla::server::Server { class CarlaServer::Pimpl {
public: public:
Pimpl(uint32_t worldPort, uint32_t writePort, uint32_t readPort) :
carla::server::Server(worldPort, writePort, readPort) {} template<typename... Args>
Pimpl(Args&&... args) : communication(std::forward<Args>(args)...) {}
carla::server::CarlaCommunication communication;
}; };
CarlaServer::CarlaServer(uint32_t writePort, uint32_t readPort, uint32_t worldPort) : CarlaServer::CarlaServer(uint32_t writePort, uint32_t readPort, uint32_t worldPort) :
@ -23,69 +30,77 @@ namespace carla {
CarlaServer::~CarlaServer() {} CarlaServer::~CarlaServer() {}
bool CarlaServer::init(uint32_t LevelCount) { bool CarlaServer::init(uint32_t levelCount) {
if (!worldConnected() && !clientConnected() && !serverConnected()) return false; if (!worldConnected() && !clientConnected() && !serverConnected())
_pimpl->sendWorld(static_cast<uint32_t>(Mode::NUMBER_OF_MODES), LevelCount); return false;
_pimpl->communication.sendWorld(levelCount);
return true; return true;
} }
bool CarlaServer::tryReadSceneInit(Mode &mode, uint32_t &scene, bool &readed) { bool CarlaServer::tryReadSceneInit(uint32_t &scene, bool &readed) {
if (!worldConnected()) return false; if (!worldConnected())
readed = _pimpl->tryReadSceneInit(mode, scene); return false;
readed = _pimpl->communication.tryReadSceneInit(scene);
return true; return true;
} }
bool CarlaServer::tryReadEpisodeStart(uint32_t &startIndex, uint32_t &endIndex, bool &readed) { bool CarlaServer::tryReadEpisodeStart(uint32_t &startIndex, uint32_t &endIndex, bool &readed) {
if (!worldConnected()) return false; if (!worldConnected())
readed = _pimpl->tryReadEpisodeStart(startIndex, endIndex); return false;
readed = _pimpl->communication.tryReadEpisodeStart(startIndex, endIndex);
return true; return true;
} }
bool CarlaServer::tryReadControl(float &steer, float &throttle, bool &readed) { bool CarlaServer::tryReadControl(float &steer, float &throttle, bool &readed) {
if (!clientConnected()) return false; if (!clientConnected())
readed = _pimpl->tryReadControl(steer, throttle); return false;
readed = _pimpl->communication.tryReadControl(steer, throttle);
return true; return true;
} }
bool CarlaServer::newEpisodeRequested(bool &newEpisode) { bool CarlaServer::newEpisodeRequested(bool &newEpisode) {
if (!worldConnected()) return false; if (!worldConnected())
newEpisode = _pimpl->tryReadRequestNewEpisode(); return false;
newEpisode = _pimpl->communication.tryReadRequestNewEpisode();
return true; return true;
} }
bool CarlaServer::sendReward(Reward_Values *values) { bool CarlaServer::sendReward(Reward_Values *values) {
std::unique_ptr<Reward_Values> ptr(values); std::unique_ptr<Reward_Values> ptr(values);
if (!serverConnected()) return false; if (!serverConnected())
_pimpl->sendReward(std::move(ptr)); return false;
_pimpl->communication.sendReward(std::move(ptr));
return true; return true;
} }
bool CarlaServer::sendSceneValues(const Scene_Values &values) { bool CarlaServer::sendSceneValues(const Scene_Values &values) {
if (!worldConnected()) return false; if (!worldConnected())
_pimpl->sendSceneValues(values); return false;
_pimpl->communication.sendScene(values);
return true; return true;
} }
bool CarlaServer::sendEndReset() { bool CarlaServer::sendEndReset() {
if (!worldConnected()) return false; if (!worldConnected())
_pimpl->sendEndReset(); return false;
_pimpl->communication.sendReset();
return true; return true;
} }
bool CarlaServer::worldConnected(){ bool CarlaServer::worldConnected(){
return _pimpl->worldConnected() && !_pimpl->needsRestart(); return _pimpl->communication.worldConnected() && !_pimpl->communication.needsRestart();
} }
bool CarlaServer::clientConnected(){ bool CarlaServer::clientConnected(){
return _pimpl->clientConnected() && !_pimpl->needsRestart(); return _pimpl->communication.clientConnected() && !_pimpl->communication.needsRestart();
} }
bool CarlaServer::serverConnected(){ bool CarlaServer::serverConnected(){
return _pimpl->serverConnected() && !_pimpl->needsRestart(); return _pimpl->communication.serverConnected() && !_pimpl->communication.needsRestart();
} }
bool CarlaServer::needsRestart(){ bool CarlaServer::needsRestart(){
return _pimpl->needsRestart(); return _pimpl->communication.needsRestart();
} }
} // namespace carla } // namespace carla

View File

@ -27,12 +27,14 @@ namespace carla {
uint8_t A; uint8_t A;
}; };
enum ImageType{ enum ImageType {
IMAGE, IMAGE,
DEPTH, DEPTH,
}; };
struct Image { struct Image {
Image();
~Image();
std::vector<Color> image; std::vector<Color> image;
ImageType type; ImageType type;
uint32_t width, height; uint32_t width, height;
@ -61,14 +63,8 @@ namespace carla {
float intersect_other_lane; float intersect_other_lane;
/// Percentage of the car off-road. /// Percentage of the car off-road.
float intersect_offroad; float intersect_offroad;
/// Width and height of the images. /// Captured images.
//uint32_t image_width, image_height;
/// RGB images.
std::vector<Image> images; std::vector<Image> images;
//std::vector<Color> image_rgb_1;
/// Depth images.
//std::vector<Color> image_depth_0;
//std::vector<Color> image_depth_1;
}; };
struct Scene_Values { struct Scene_Values {
@ -76,18 +72,10 @@ namespace carla {
~Scene_Values(); ~Scene_Values();
/// Possible world positions to spawn the player. /// Possible world positions to spawn the player.
std::vector<Vector2D> possible_positions; std::vector<Vector2D> possible_positions;
/// Projection matrices of the cameras (1 in mode mono, 2 in stereo). /// Projection matrices of the cameras.
std::vector<std::array<float, 16u>> projection_matrices; std::vector<std::array<float, 16u>> projection_matrices;
}; };
enum class Mode : int8_t {
MONO,
STEREO,
NUMBER_OF_MODES,
INVALID = -1
};
/// Asynchronous TCP server. Uses three ports, one for sending messages /// Asynchronous TCP server. Uses three ports, one for sending messages
/// (write), one for receiving messages (read), and one for world level /// (write), one for receiving messages (read), and one for world level
/// commands (world). /// commands (world).
@ -109,13 +97,11 @@ namespace carla {
/// Initialize the server. /// Initialize the server.
/// ///
/// @param LevelCount Number of levels available. /// @param LevelCount Number of levels available.
bool init(uint32_t LevelCount); bool init(uint32_t levelCount);
/// Try to read if the client has selected an scene and mode. Return false /// Try to read if the client has selected an scene and mode. Return false
/// if the queue is empty. /// if the queue is empty.
/// bool tryReadSceneInit(uint32_t &scene, bool &readed);
/// If returned mode INVALID, ignore scene.
bool tryReadSceneInit(Mode &mode, uint32_t &scene, bool &readed);
/// Try to read if the client has selected an end & start point. Return /// Try to read if the client has selected an end & start point. Return
/// false if the queue is empty. /// false if the queue is empty.

View File

@ -10,16 +10,6 @@ namespace server {
// -- Static methods --------------------------------------------------------- // -- Static methods ---------------------------------------------------------
std::mutex _generalMutex;
static Mode getMode(int modeInt) {
switch (modeInt) {
case 0: return Mode::MONO;
case 1: return Mode::STEREO;
default: return Mode::INVALID;
}
}
template<typename ERROR_CODE> template<typename ERROR_CODE>
static void logTCPError(const std::string &text, const ERROR_CODE &errorCode) { static void logTCPError(const std::string &text, const ERROR_CODE &errorCode) {
std::cerr << "CarlaConnection - TCP Server: " << text << ": " << errorCode.message() << std::endl; std::cerr << "CarlaConnection - TCP Server: " << text << ": " << errorCode.message() << std::endl;
@ -141,9 +131,11 @@ namespace server {
} }
static void ReconnectAll(CarlaCommunication &communication) { static void ReconnectAll(CarlaCommunication &communication) {
std::lock_guard<std::mutex> lock(_generalMutex); /// @todo This blocks every CarlaCommunication with a single mutex.
static std::mutex MUTEX;
std::lock_guard<std::mutex> lock(MUTEX);
if (!communication.NeedsRestart()) { if (!communication.needsRestart()) {
std::cout << " ---- RECONNECT ALL ...." << std::endl; std::cout << " ---- RECONNECT ALL ...." << std::endl;
@ -165,7 +157,7 @@ namespace server {
communication.getClientThread().restart(); communication.getClientThread().restart();
} }
communication.Restart(); communication.restart();
} }
} }
@ -174,7 +166,6 @@ namespace server {
_server(writePort), _server(writePort),
_client(readPort), _client(readPort),
_needsRestart(false), _needsRestart(false),
_mode(Mode::MONO),
_proto(std::make_unique<Protocol>(this)), _proto(std::make_unique<Protocol>(this)),
_worldThread{ _worldThread{
[this]() { return worldReceiveThread(this->_world, this->_worldThread); }, [this]() { return worldReceiveThread(this->_world, this->_worldThread); },
@ -213,13 +204,14 @@ namespace server {
return true; return true;
} }
void CarlaCommunication::sendWorld(const uint32_t modes, const uint32_t scenes) { void CarlaCommunication::sendWorld(const uint32_t scenes) {
//ClearThreads //ClearThreads
_worldThread.clear(); _worldThread.clear();
_clientThread.clear(); _clientThread.clear();
_serverThread.clear(); _serverThread.clear();
World world; World world;
constexpr int modes = 0; /// @todo #18
_proto->LoadWorld(world, modes, scenes); _proto->LoadWorld(world, modes, scenes);
auto message = std::make_unique<std::string>(); auto message = std::make_unique<std::string>();
@ -253,8 +245,7 @@ namespace server {
} }
} }
bool CarlaCommunication::tryReadSceneInit(Mode &mode, uint32_t &scene) { bool CarlaCommunication::tryReadSceneInit(uint32_t &scene) {
mode = Mode::INVALID;
scene = 0u; scene = 0u;
std::unique_ptr<std::string> info = _worldThread.tryPop(); std::unique_ptr<std::string> info = _worldThread.tryPop();
@ -264,11 +255,7 @@ namespace server {
if (!sceneInit.ParseFromString(*info)) { return false; } if (!sceneInit.ParseFromString(*info)) { return false; }
mode = getMode(sceneInit.mode());
scene = sceneInit.scene(); scene = sceneInit.scene();
_mode = mode;
return true; return true;
} }
@ -303,17 +290,14 @@ namespace server {
void CarlaCommunication::restartServer() { void CarlaCommunication::restartServer() {
_server.close(); _server.close();
//_server = TCPServer(_serverPort);
} }
void CarlaCommunication::restartWorld() { void CarlaCommunication::restartWorld() {
_world.close(); _world.close();
//_world = TCPServer(_worldPort);
} }
void CarlaCommunication::restartClient() { void CarlaCommunication::restartClient() {
_client.close(); _client.close();
//_client = TCPServer(_clientPort);
} }
void CarlaCommunication::checkRestart() { void CarlaCommunication::checkRestart() {
@ -347,15 +331,11 @@ namespace server {
return _server.Connected(); return _server.Connected();
} }
Mode CarlaCommunication::GetMode() { bool CarlaCommunication::needsRestart() {
return _mode;
}
bool CarlaCommunication::NeedsRestart() {
return _needsRestart; return _needsRestart;
} }
void CarlaCommunication::Restart() { void CarlaCommunication::restart() {
_needsRestart = true; _needsRestart = true;
} }

View File

@ -36,10 +36,9 @@ namespace server {
void sendReset(); void sendReset();
//void sendWorld(const World &world); void sendWorld(const uint32_t scenes);
void sendWorld(const uint32_t modes, const uint32_t scenes);
bool tryReadSceneInit(Mode &mode, uint32_t &scene); bool tryReadSceneInit(uint32_t &scene);
bool tryReadEpisodeStart(uint32_t &start_index, uint32_t &end_index); bool tryReadEpisodeStart(uint32_t &start_index, uint32_t &end_index);
@ -63,10 +62,9 @@ namespace server {
std::mutex getGeneralMutex(); std::mutex getGeneralMutex();
Mode GetMode(); bool needsRestart();
bool NeedsRestart(); void restart();
void Restart();
private: private:
@ -78,8 +76,6 @@ namespace server {
std::atomic_bool _needsRestart; std::atomic_bool _needsRestart;
std::atomic<Mode> _mode;
const std::unique_ptr<Protocol> _proto; const std::unique_ptr<Protocol> _proto;
thread::AsyncReadWriteJobQueue< std::string, std::string> _worldThread; thread::AsyncReadWriteJobQueue< std::string, std::string> _worldThread;

View File

@ -1,88 +0,0 @@
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
#include "Server.h"
#include "CarlaCommunication.h"
#include "carla_protocol.pb.h"
#include <iostream>
#include <memory>
namespace carla {
namespace server {
// -- CarlaServer ------------------------------------------------------------
Server::Server(uint32_t worldPort, uint32_t writePort, uint32_t readPort) :
_communication(std::make_unique<CarlaCommunication>(worldPort, writePort, readPort)){}
Server::~Server() {
}
void Server::sendReward( std::unique_ptr<Reward_Values> values) {
//Reward reward;
//_proto->LoadReward(reward, values);
//_communication->sendReward(reward);
_communication->sendReward(std::move(values));
}
void Server::sendSceneValues(const Scene_Values &values) {
_communication->sendScene(values);
}
void Server::sendEndReset() {
_communication->sendReset();
}
void Server::sendWorld(const uint32_t modes, const uint32_t scenes) {
//World world;
//_proto->LoadWorld(world, modes, scenes);
//_communication->sendWorld(world);
_communication->sendWorld(modes, scenes);
}
bool Server::tryReadControl(float &steer, float &gas) {
return _communication->tryReadControl(steer, gas);
}
bool Server::tryReadSceneInit(Mode &mode, uint32_t &scene) {
return _communication->tryReadSceneInit(mode, scene);
}
bool Server::tryReadEpisodeStart(uint32_t &start_index, uint32_t &end_index) {
return _communication->tryReadEpisodeStart(start_index, end_index);
}
bool Server::tryReadRequestNewEpisode(){
return _communication->tryReadRequestNewEpisode();
}
Mode Server::GetMode() const {
return _communication->GetMode();
}
void Server::SetScene(int scene) {
_scene = scene;
}
bool Server::worldConnected() const{
return _communication->worldConnected();
}
bool Server::clientConnected() const{
return _communication->clientConnected();
}
bool Server::serverConnected() const{
return _communication->serverConnected();
}
bool Server::needsRestart() const {
return _communication->NeedsRestart();
}
} // namespace server
} // namespace carla

View File

@ -1,88 +0,0 @@
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
#pragma once
#include <carla/NonCopyable.h>
#include <carla/CarlaServer.h>
#include <atomic>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
namespace carla {
namespace server {
class CarlaCommunication;
/// Asynchronous TCP server. Uses two ports, one for sending messages (write)
/// and one for receiving messages (read).
///
/// Writing and reading are executed in two different threads. Each thread has
/// its own queue of messages.
///
/// Note that a new socket is created for every connection (every write and
/// read).
class Server : private NonCopyable {
public:
/// Starts two threads for writing and reading.
explicit Server(uint32_t worldPort, uint32_t writePort, uint32_t readPort);
~Server();
///// Send values of the current player status
void sendReward(std::unique_ptr<Reward_Values> values);
//// Send the values of the generated scene
void sendSceneValues(const Scene_Values &values);
//// Send a signal to the client to notify that the car is ready
void sendEndReset();
void sendWorld(uint32_t modes, uint32_t scenes);
///// Try to read the response of the client. Return false if the queue
///// is empty.
bool tryReadControl(float &steer, float &gas);
////Try to read if the client has selected an scene and mode. Return false if the queue is empty
bool tryReadSceneInit(Mode &mode, uint32_t &scene);
////Try to read if the client has selected an end & start point. Return false if the queue is empty
bool tryReadEpisodeStart(uint32_t &start_index, uint32_t &end_index);
bool tryReadRequestNewEpisode();
void setMode(Mode mode);
Mode GetMode() const;
void SetScene(int scene);
int GetScene() const;
bool worldConnected() const;
bool clientConnected() const;
bool serverConnected() const;
bool needsRestart() const;
private:
//std::mutex _mutex;
std::atomic_int _scene;
const std::unique_ptr<CarlaCommunication> _communication;
//const std::unique_ptr<Protocol> _proto;
};
} // namespace server
} // namespace carla

View File

@ -43,42 +43,41 @@ static std::vector<carla::Color> makeImage(uint32_t width, uint32_t height) {
return image; return image;
} }
std::unique_ptr<carla::Reward_Values> makeReward(){ std::unique_ptr<carla::Reward_Values> makeReward() {
auto reward = std::make_unique<carla::Reward_Values>(); auto reward = std::make_unique<carla::Reward_Values>();
const uint32_t imageWidth = 512u; const uint32_t imageWidth = 512u;
const uint32_t imageHeight = 512u; const uint32_t imageHeight = 512u;
reward->player_location = {1.0f, 1.0f}; reward->player_location = {1.0f, 1.0f};
reward->player_orientation = {1.0f, 0.0f, 0.0f}; reward->player_orientation = {1.0f, 0.0f, 0.0f};
reward->player_acceleration = {1.0f, 0.0f, 0.0f}; reward->player_acceleration = {1.0f, 0.0f, 0.0f};
reward->forward_speed = 100.0f; reward->forward_speed = 100.0f;
reward->collision_general = 10.0f; reward->collision_general = 10.0f;
reward->collision_pedestrian = 10.0f; reward->collision_pedestrian = 10.0f;
reward->collision_car = 10.0f; reward->collision_car = 10.0f;
reward->intersect_other_lane = 0.5f; reward->intersect_other_lane = 0.5f;
reward->intersect_offroad = 0.5f; reward->intersect_offroad = 0.5f;
for (int i = 0; i < 4; ++i){ for (int i = 0; i < 4; ++i) {
carla::Image img; carla::Image img;
img.image = makeImage(imageWidth, imageHeight); img.image = makeImage(imageWidth, imageHeight);
img.width = imageWidth; img.width = imageWidth;
img.height = imageHeight; img.height = imageHeight;
if (i < 2) img.type = carla::IMAGE; if (i < 2) img.type = carla::IMAGE;
else img.type = carla::DEPTH; else img.type = carla::DEPTH;
reward->images.push_back(img); reward->images.push_back(img);
} }
/* /*
reward->image_rgb_0 = makeImage(imageWidth, imageHeight); reward->image_rgb_0 = makeImage(imageWidth, imageHeight);
reward->image_rgb_1 = makeImage(imageWidth, imageHeight); reward->image_rgb_1 = makeImage(imageWidth, imageHeight);
reward->image_depth_0 = makeImage(imageWidth, imageHeight); reward->image_depth_0 = makeImage(imageWidth, imageHeight);
reward->image_depth_1 = makeImage(imageWidth, imageHeight); reward->image_depth_1 = makeImage(imageWidth, imageHeight);
*/ */
static decltype(carla::Reward_Values::timestamp) timestamp = 0u; static decltype(carla::Reward_Values::timestamp) timestamp = 0u;
reward->timestamp = timestamp++; reward->timestamp = timestamp++;
return reward; return reward;
} }
@ -91,67 +90,57 @@ int main(int argc, char *argv[]) {
const uint32_t worldPort = toInt(argv[1u]); const uint32_t worldPort = toInt(argv[1u]);
const uint32_t writePort = toInt(argv[2u]); const uint32_t writePort = toInt(argv[2u]);
const uint32_t readPort = toInt(argv[3u]); const uint32_t readPort = toInt(argv[3u]);
// const uint32_t mode = toInt(argv[4u]);
// const uint32_t scene = toInt(argv[5u]);
// This already starts the two threads. // This already starts the two threads.
carla::CarlaServer server(writePort, readPort, worldPort); carla::CarlaServer server(writePort, readPort, worldPort);
// Let's simulate the game loop. // Let's simulate the game loop.
for (;;) {
if (server.init(1u)) {
for (;;){
if (server.init(1u)){
{ {
carla::Mode mode;
uint32_t scene; uint32_t scene;
bool error = false, readed = false; bool error = false, readed = false;
do{ do {
error = !server.tryReadSceneInit(mode, scene, readed); error = !server.tryReadSceneInit(scene, readed);
}while(!readed && !error); } while (!readed && !error);
if (error) std::cerr << "ERROR while sending SceneValues" << std::endl; if (error) {
else std::cout << "Received: mode = " << (mode == carla::Mode::MONO ? "MONO" : "STEREO") std::cerr << "ERROR while sending SceneValues" << std::endl;
<< ", scene = " << scene << std::endl; }
else std::cout << "Received: scene = " << scene << std::endl;
} }
carla::Scene_Values sceneValues;
carla::Scene_Values sceneValues; sceneValues.possible_positions.push_back({0.0f, 0.0f});
sceneValues.possible_positions.push_back({1.0f, 2.0f});
sceneValues.possible_positions.push_back({3.0f, 4.0f});
const std::array<float, 16u> pMatrix = {{ 10.0 }};
sceneValues.projection_matrices.push_back(pMatrix);
if (!server.sendSceneValues(sceneValues)) {
std::cerr << "ERROR while sending SceneValues" << std::endl;
}
sceneValues.possible_positions.push_back({0.0f, 0.0f}); std::cout << "New episode" << std::endl;
sceneValues.possible_positions.push_back({1.0f, 2.0f}); {
sceneValues.possible_positions.push_back({3.0f, 4.0f}); uint32_t start, end;
const std::array<float, 16u> pMatrix = {{ 10.0 }}; bool error = false, readed = false;
sceneValues.projection_matrices.push_back(pMatrix); do {
error = !server.tryReadEpisodeStart(start, end, readed);
/* std::cout << "POSSIBLE POSITIONS "<< std::endl; } while (!readed && !error);
for (int i=0; i<sceneValues.possible_positions.size(); ++i){
std::cout << " x: " << sceneValues.possible_positions[i].x << " y: " << sceneValues.possible_positions[i].y << std::endl;
}*/
if (!server.sendSceneValues(sceneValues)) std::cerr << "ERROR while sending SceneValues" << std::endl;
std::cout << "New episode" << std::endl;
{
uint32_t start, end;
bool error = false, readed = false;
do{
error = !server.tryReadEpisodeStart(start, end, readed);
}while (!readed && !error);
if (error) std::cerr << "ERROR while reading EpisodeStart" << std::endl;
else std::cout << "Received: startIndex = " << start << ", endIndex = " << end << std::endl;
if (error) {
std::cerr << "ERROR while reading EpisodeStart" << std::endl;
} else {
std::cout << "Received: startIndex = " << start << ", endIndex = " << end << std::endl;
} }
}
if (!server.sendEndReset()) std::cerr << "ERROR while sending EndReset" << std::endl; if (!server.sendEndReset()) {
std::cerr << "ERROR while sending EndReset" << std::endl;
}
while (true) { while (true) {
float steer, gas; float steer, gas;
@ -172,39 +161,35 @@ int main(int argc, char *argv[]) {
uint32_t startPoint, endPoint; uint32_t startPoint, endPoint;
bool error = false, readed = false; bool error = false, readed = false;
do{ do {
error = !server.tryReadEpisodeStart(startPoint, endPoint, readed); error = !server.tryReadEpisodeStart(startPoint, endPoint, readed);
}while (!readed && !error); } while (!readed && !error);
if (error) { if (error) {
std::cerr << "ERROR while reading EpisodeStart" << std::endl; std::cerr << "ERROR while reading EpisodeStart" << std::endl;
break; break;
} } else {
else{
std::cout << "--> Start: " << startPoint << " End: " << endPoint << " <--" << std::endl; std::cout << "--> Start: " << startPoint << " End: " << endPoint << " <--" << std::endl;
server.sendEndReset(); server.sendEndReset();
} }
}else { } else {
bool readed = false; bool readed = false;
if (!server.tryReadControl(steer, gas, readed)){ if (!server.tryReadControl(steer, gas, readed)){
std::cerr << "ERROR while reading Control" << std::endl; std::cerr << "ERROR while reading Control" << std::endl;
break; break;
} } else if (readed) {
else if (readed)
std::cout << "CONTROL --> gas: " << gas << " steer: " << steer << std::endl; std::cout << "CONTROL --> gas: " << gas << " steer: " << steer << std::endl;
}
if (!server.sendReward(makeReward().release())) { if (!server.sendReward(makeReward().release())) {
std::cerr << "ERROR while sending Reward" << std::endl; std::cerr << "ERROR while sending Reward" << std::endl;
break; break;
} }
} }
} }
std::cout << " ----- RESTARTING -----" << std::endl;
std::cout << " ----- RESTARTING -----" << std::endl;
} }
} }
} catch (const std::exception &e) { } catch (const std::exception &e) {