This commit is contained in:
Xisco Bosch 2017-03-22 16:10:29 +01:00
parent 197462939f
commit 183e985b15
6 changed files with 40 additions and 18 deletions

View File

@ -70,7 +70,7 @@ namespace carla {
}*/
bool CarlaServer::needsRestart(){
return _pimpl->needsRestart() && _pimpl->worldConnected() && _pimpl->clientConnected() && _pimpl->serverConnected();
return _pimpl->needsRestart() || (!_pimpl->worldConnected() || !_pimpl->clientConnected() || !_pimpl->serverConnected());
}
} // namespace carla

View File

@ -132,6 +132,15 @@ namespace server {
server.writeString(message, error);
Scene demo_scene;
if (demo_scene.ParseFromString(message)){
std::cout << "POSSIBLE POSITIONS 5"<< std::endl;
for (int i=0; i<demo_scene.position_size(); ++i){
std::cout << " x: " << demo_scene.position(i).pos_x() << " y: " << demo_scene.position(i).pos_y() << std::endl;
}
}
if (error) {
logTCPError("Failed to send world", error);
}
@ -142,9 +151,12 @@ namespace server {
}
}
static void Connect(TCPServer &server) {
static void Connect(TCPServer &server, CarlaCommunication &communication) {
std::cout << "Waiting... port: " << server.port << std::endl;
server.AcceptSocket();
communication.checkRestart();
}
static void ReconnectAll(CarlaCommunication &communication){
@ -192,17 +204,17 @@ namespace server {
_worldThread {
[this]() { return worldReceiveThread(this->_world, this->_worldThread); },
[this](const std::string & msg) { worldSendThread(this->_world, this->_worldThread, msg); },
[this]() { Connect(this->_world); },
[this]() { Connect(this->_world, *this); },
[this]() { ReconnectAll(*this);}
},
_serverThread {
[this](const Reward_Values &rwd) { serverWorkerThread(this->_server, this->_serverThread, this->_proto, rwd); },
[this]() { Connect(this->_server); },
[this]() { Connect(this->_server, *this); },
[this]() { ReconnectAll(*this);}
},
_clientThread {
[this]() { return clientWorkerThread(this->_client, this->_clientThread); },
[this]() { Connect(this->_client); },
[this]() { Connect(this->_client, *this); },
[this]() { ReconnectAll(*this);}
}
{
@ -243,8 +255,6 @@ namespace server {
void CarlaCommunication::sendWorld(const uint32_t modes,const uint32_t scenes) {
_needsRestart = false;
World world;
_proto->LoadWorld(world, modes, scenes);
@ -336,6 +346,13 @@ namespace server {
//_client = TCPServer(_clientPort);
}
void CarlaCommunication::checkRestart(){
if (_needsRestart && _world.Connected() &&
_client.Connected() && _server.Connected())
_needsRestart = false;
}
thread::AsyncReaderJobQueue<Reward_Values>& CarlaCommunication::getServerThread(){
return _serverThread;
}

View File

@ -55,6 +55,8 @@ namespace server {
thread::AsyncWriterJobQueue<std::string>& getClientThread();
thread::AsyncReadWriteJobQueue<std::string, std::string>& getWorldThread();
void checkRestart();
bool worldConnected();
bool clientConnected();
bool serverConnected();

View File

@ -80,6 +80,8 @@ namespace thread {
_readJob(value);
}
if (!_restart){
W temp;
while(_writeQueue.try_pop(temp));
_writeQueue.push(_writeJob());
}

View File

@ -60,6 +60,8 @@ namespace thread {
_restart = false;
_queue.canWait(true);
while (!_restart && !_done) {
T temp;
while(_queue.try_pop(temp));
_queue.push(_job());
//Sleep(10);
}

View File

@ -107,7 +107,7 @@ int main(int argc, char *argv[]) {
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});
@ -127,7 +127,7 @@ int main(int argc, char *argv[]) {
while (!server.needsRestart() && !server.tryReadEpisodeStart(start, end));
std::cout << "Received: startIndex = " << start
<< ", endIndex = " << end << std::endl;
}
server.sendEndReset();
while (!server.needsRestart()) {
@ -139,17 +139,16 @@ int main(int argc, char *argv[]) {
while (!server.needsRestart() && !server.tryReadEpisodeStart(startPoint, endPoint));
std::cout << "--> Start: " << startPoint << " End: " << endPoint << " <--" << std::endl;
server.sendEndReset();
}else {
if (server.tryReadControl(steer, gas)) {
std::cout << "Steer: " << steer << " Gas: " << gas << std::endl;
}
static decltype(carla::Reward_Values::timestamp) timestamp = 0u;
reward.timestamp = timestamp++;
server.sendReward(reward);
}else {
if (server.tryReadControl(steer, gas)) {
std::cout << "Steer: " << steer << " Gas: " << gas << std::endl;
}
static decltype(carla::Reward_Values::timestamp) timestamp = 0u;
reward.timestamp = timestamp++;
server.sendReward(reward);
}
}
std::cout << " ----- RESTARTING -----" << std::endl;
std::cout << " ----- RESTARTING -----" << std::endl;
}
}
} catch (const std::exception &e) {