Reset & restart
This commit is contained in:
parent
d86ad9b2c3
commit
53e11ccbed
|
@ -136,13 +136,13 @@ namespace server {
|
||||||
//server.writeString("world", error);
|
//server.writeString("world", error);
|
||||||
|
|
||||||
|
|
||||||
//Scene demo_scene;
|
Scene demo_scene;
|
||||||
//if (demo_scene.ParseFromString(message)){
|
if (demo_scene.ParseFromString(message)){
|
||||||
//std::cout << "POSSIBLE POSITIONS"<< std::endl;
|
std::cout << "POSSIBLE POSITIONS THREAD"<< std::endl;
|
||||||
//for (int i=0; i<demo_scene.position_size(); ++i){
|
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;
|
std::cout << " x: " << demo_scene.position(i).pos_x() << " y: " << demo_scene.position(i).pos_y() << std::endl;
|
||||||
//}
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
logTCPError("Failed to send world", error);
|
logTCPError("Failed to send world", error);
|
||||||
|
@ -266,8 +266,10 @@ namespace server {
|
||||||
_proto -> LoadScene(scene, values);
|
_proto -> LoadScene(scene, values);
|
||||||
|
|
||||||
auto message = std::make_unique<std::string>();
|
auto message = std::make_unique<std::string>();
|
||||||
if (scene.SerializeToString(message.get()))
|
|
||||||
|
if (scene.SerializeToString(message.get())){
|
||||||
_worldThread.push(std::move(message));
|
_worldThread.push(std::move(message));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,6 +322,7 @@ namespace server {
|
||||||
|
|
||||||
bool CarlaCommunication::tryReadRequestNewEpisode(){
|
bool CarlaCommunication::tryReadRequestNewEpisode(){
|
||||||
std::unique_ptr <std::string> request = _worldThread.tryPop();
|
std::unique_ptr <std::string> request = _worldThread.tryPop();
|
||||||
|
|
||||||
if (request == nullptr) return false;
|
if (request == nullptr) return false;
|
||||||
|
|
||||||
RequestNewEpisode reqEpisode;
|
RequestNewEpisode reqEpisode;
|
||||||
|
|
|
@ -51,7 +51,8 @@ namespace thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(std::unique_ptr<R> item) {
|
void push(std::unique_ptr<R> item) {
|
||||||
_readQueue.push(std::move(item));
|
|
||||||
|
if (item != nullptr) _readQueue.push(std::move(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconnect(){
|
void reconnect(){
|
||||||
|
@ -78,9 +79,6 @@ namespace thread {
|
||||||
_restart = false;
|
_restart = false;
|
||||||
_readQueue.canWait(true);
|
_readQueue.canWait(true);
|
||||||
while (!_restart && !_done) {
|
while (!_restart && !_done) {
|
||||||
|
|
||||||
std::cout << "1" << std::endl;
|
|
||||||
|
|
||||||
auto value = _readQueue.wait_and_pop();
|
auto value = _readQueue.wait_and_pop();
|
||||||
if (value != nullptr) {
|
if (value != nullptr) {
|
||||||
_readJob(*value);
|
_readJob(*value);
|
||||||
|
|
|
@ -58,21 +58,17 @@ namespace thread {
|
||||||
private:
|
private:
|
||||||
void workerThread() {
|
void workerThread() {
|
||||||
while (!_done){
|
while (!_done){
|
||||||
std::cout << "2.1" << std::endl;
|
|
||||||
_connectionJob();
|
_connectionJob();
|
||||||
_restart = false;
|
_restart = false;
|
||||||
_queue.canWait(true);
|
_queue.canWait(true);
|
||||||
while (!_restart && !_done) {
|
while (!_restart && !_done) {
|
||||||
|
|
||||||
std::cout << "2.2" << std::endl;
|
|
||||||
|
|
||||||
auto value = _queue.wait_and_pop();
|
auto value = _queue.wait_and_pop();
|
||||||
if (value != nullptr) _job(*value);
|
if (value != nullptr) {
|
||||||
//Sleep(10);
|
_job(*value);
|
||||||
}
|
}//Sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "2.3" << std::endl;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::atomic_bool _done;
|
std::atomic_bool _done;
|
||||||
|
|
|
@ -57,22 +57,14 @@ namespace thread {
|
||||||
|
|
||||||
void workerThread() {
|
void workerThread() {
|
||||||
while (!_done){
|
while (!_done){
|
||||||
std::cout << "3.1" << std::endl;
|
|
||||||
|
|
||||||
_connectJob();
|
_connectJob();
|
||||||
_restart = false;
|
_restart = false;
|
||||||
_queue.canWait(true);
|
_queue.canWait(true);
|
||||||
while (!_restart && !_done) {
|
while (!_restart && !_done) {
|
||||||
|
|
||||||
std::cout << "3.2" << std::endl;
|
|
||||||
|
|
||||||
_queue.push(std::move(_job()));
|
_queue.push(std::move(_job()));
|
||||||
//Sleep(10);
|
//Sleep(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "3.3" << std::endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::atomic_bool _done;
|
std::atomic_bool _done;
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace thread {
|
||||||
//_queue.push(new_value);
|
//_queue.push(new_value);
|
||||||
//_condition.notify_one();
|
//_condition.notify_one();
|
||||||
_value = std::move(new_value);
|
_value = std::move(new_value);
|
||||||
|
_condition.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
void canWait(bool wait){
|
void canWait(bool wait){
|
||||||
|
@ -42,7 +43,6 @@ namespace thread {
|
||||||
_condition.wait(lock, [this]() {
|
_condition.wait(lock, [this]() {
|
||||||
return _value != nullptr || !_canWait;
|
return _value != nullptr || !_canWait;
|
||||||
});
|
});
|
||||||
|
|
||||||
return std::move(_value);
|
return std::move(_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,10 +125,10 @@ int main(int argc, char *argv[]) {
|
||||||
const std::array<float, 16u> pMatrix = {{ 10.0 }};
|
const std::array<float, 16u> pMatrix = {{ 10.0 }};
|
||||||
sceneValues.projection_matrices.push_back(pMatrix);
|
sceneValues.projection_matrices.push_back(pMatrix);
|
||||||
|
|
||||||
std::cout << "POSSIBLE POSITIONS 5"<< std::endl;
|
/* std::cout << "POSSIBLE POSITIONS "<< std::endl;
|
||||||
for (int i=0; i<sceneValues.possible_positions.size(); ++i){
|
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;
|
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;
|
if (!server.sendSceneValues(sceneValues)) std::cerr << "ERROR while sending SceneValues" << std::endl;
|
||||||
|
@ -153,7 +153,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
float steer, gas;
|
float steer, gas;
|
||||||
/*bool newEpisode = false;
|
bool newEpisode = false;
|
||||||
if (!server.newEpisodeRequested(newEpisode)){
|
if (!server.newEpisodeRequested(newEpisode)){
|
||||||
std::cerr << "ERROR while checking for newEpisode request" << std::endl;
|
std::cerr << "ERROR while checking for newEpisode request" << std::endl;
|
||||||
break;
|
break;
|
||||||
|
@ -184,7 +184,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
*/
|
|
||||||
bool error = false, readed = false;
|
bool error = false, 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;
|
||||||
|
@ -201,7 +201,7 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << " ----- RESTARTING -----" << std::endl;
|
std::cout << " ----- RESTARTING -----" << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue