Fix compile errors in Linux

This commit is contained in:
nsubiron 2017-03-14 11:55:37 +01:00
parent 6eb9727cb8
commit 02baff814e
10 changed files with 387 additions and 424 deletions

View File

@ -1,6 +1,10 @@
cmake_minimum_required (VERSION 2.6)
project (CarlaServer)
SET(CMAKE_CXX_COMPILER clang++)
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED 14)
# Boost configuration
SET(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED system date_time regex)

View File

@ -3,6 +3,9 @@ BUILD_FOLDER=build
vsproject:
cmake -H. -B$(BUILD_FOLDER) -G "Visual Studio 14 2015 Win64"
stproject:
cmake -H. -B$(BUILD_FOLDER) -G "Sublime Text 2 - Ninja"
clean:
rm -Rf build CMakeFiles

View File

@ -3,140 +3,144 @@
#include <iostream>
namespace carla {
namespace server {
// -- Static methods ---------------------------------------------------------
namespace server {
// -- Static methods ---------------------------------------------------------
template <typename ERROR_CODE>
static void logTCPError(const std::string &text, const ERROR_CODE &errorCode) {
std::cerr << "CarlaConnection - TCP Server: " << text << ": " << errorCode.message() << std::endl;
}
template <typename ERROR_CODE>
static void logTCPError(const std::string &text, const ERROR_CODE &errorCode) {
std::cerr << "CarlaConnection - TCP Server: " << text << ": " << errorCode.message() << std::endl;
}
// This is the thread that sends a string over the TCP socket.
static void serverWorkerThread(TCPServer &server, std::string &message) {
TCPServer::error_code error;
//message = message.size.c_ + message;
// This is the thread that sends a string over the TCP socket.
static void serverWorkerThread(TCPServer &server, const std::string &message) {
TCPServer::error_code error;
//message = message.size.c_ + message;
//if (!server.Connected()) server.AcceptSocket();
server.writeString(message, error);
//if (!server.Connected()) server.AcceptSocket();
if (error)
logTCPError("Failed to send", error);
server.writeString(message, error);
}
if (error)
logTCPError("Failed to send", error);
}
//TODO:
// Sortida amb google protocol
// This is the thread that listens for string over the TCP socket.
static std::string clientWorkerThread(TCPServer &server) {
//TODO:
// Sortida amb google protocol
// This is the thread that listens for string over the TCP socket.
static std::string clientWorkerThread(TCPServer &server) {
//if (!server.Connected()) server.AcceptSocket();
//if (!server.Connected()) server.AcceptSocket();
std::string message;
TCPServer::error_code error;
std::string message;
TCPServer::error_code error;
server.readString(message, error);
if (error && (error != boost::asio::error::eof)) { // eof is expected.
logTCPError("Failed to read", error);
return std::string();
}
server.readString(message, error);
if (error && (error != boost::asio::error::eof)) { // eof is expected.
logTCPError("Failed to read", error);
return std::string();
}
return message;
}
return message;
}
// This is the thread that listens & sends a string over the TCP world socket.
static std::string worldReceiveThread(TCPServer &server) {
std::string message;
TCPServer::error_code error;
// This is the thread that listens & sends a string over the TCP world socket.
static std::string worldReceiveThread(TCPServer &server) {
std::string message;
TCPServer::error_code error;
//if (!server.Connected()) server.AcceptSocket();
//if (!server.Connected()) server.AcceptSocket();
server.readString(message, error);
if (error && (error != boost::asio::error::eof)) { // eof is expected.
logTCPError("Failed to read world", error);
return std::string();
}
return message;
server.readString(message, error);
if (error && (error != boost::asio::error::eof)) { // eof is expected.
logTCPError("Failed to read world", error);
return std::string();
}
return message;
}
}
static void worldSendThread(TCPServer &server, std::string &message) {
TCPServer::error_code error;
//message = message.size + message;
static void worldSendThread(TCPServer &server, const std::string &message) {
TCPServer::error_code error;
//message = message.size + message;
//if (!server.Connected()) server.AcceptSocket();
//if (!server.Connected()) server.AcceptSocket();
server.writeString(message, error);
if (error)
logTCPError("Failed to send world", error);
server.writeString(message, error);
if (error)
logTCPError("Failed to send world", error);
}
}
static void Connect(TCPServer &server) {
if (!server.Connected()) server.AcceptSocket();
}
static void Connect(TCPServer &server) {
if (!server.Connected()) server.AcceptSocket();
}
CarlaCommunication::CarlaCommunication(int worldPort, int writePort, int readPort) :
_world(worldPort),
_server(writePort),
_client(readPort),
_worldThread([this]() {return worldReceiveThread(this->_world); },
[this](std::string &msg) { worldSendThread(this->_world, msg); },
[this]() {Connect(this->_world); }),
_serverThread([this](std::string &str) { serverWorkerThread(this->_server, str); },
[this]() {Connect(this->_server); }),
_clientThread([this]() { return clientWorkerThread(this->_client); },
[this]() {Connect(this->_client); })
{
CarlaCommunication::CarlaCommunication(int worldPort, int writePort, int readPort) :
_world(worldPort),
_server(writePort),
_client(readPort),
_worldThread{
[this]() { return worldReceiveThread(this->_world); },
[this](const std::string &msg) { worldSendThread(this->_world, msg); },
[this]() { Connect(this->_world); }},
_serverThread{
[this](const std::string &str) { serverWorkerThread(this->_server, str); },
[this]() { Connect(this->_server); }},
_clientThread{
[this]() { return clientWorkerThread(this->_client); },
[this]() { Connect(this->_client); }}
{
/*std::cout << "WorldPort: " << worldPort << std::endl;
std::cout << "writePort: " << writePort << std::endl;
std::cout << "readPort: " << readPort << std::endl;*/
}
/*std::cout << "WorldPort: " << worldPort << std::endl;
std::cout << "writePort: " << writePort << std::endl;
std::cout << "readPort: " << readPort << std::endl;*/
void CarlaCommunication::sendReward(const Reward &reward) {
std::string message;
bool error = !reward.SerializeToString(&message);
if (!error) {
_serverThread.push(message);
std::cout << "Send Reward" << std::endl;
}
}
}
bool CarlaCommunication::tryReadControl(std::string &control) {
return _clientThread.tryPop(control);
}
void CarlaCommunication::sendReward(const Reward &reward) {
std::string message;
bool error = !reward.SerializeToString(&message);
if (!error) {
_serverThread.push(message);
std::cout << "Send Reward" << std::endl;
}
}
void CarlaCommunication::sendWorld(const World &world) {
std::string message;
bool error = !world.SerializeToString(&message);
_worldThread.push(message);
}
bool CarlaCommunication::tryReadControl(std::string &control) {
return _clientThread.tryPop(control);
}
void CarlaCommunication::sendScene(const Scene &scene) {
std::string message;
bool error = !scene.SerializeToString(&message);
_worldThread.push(message);
}
void CarlaCommunication::sendWorld(const World &world) {
std::string message;
bool error = !world.SerializeToString(&message);
_worldThread.push(message);
}
void CarlaCommunication::sendReset(const EpisodeReady &ready) {
std::string message;
bool error = !ready.SerializeToString(&message);
if (!error) {
//std::cout << "Send End Reset" << std::endl;
_worldThread.push(message);
}
else {
std::cout << " >> SEND RESET ERROR <<" << std::endl;
}
}
void CarlaCommunication::sendScene(const Scene &scene) {
std::string message;
bool error = !scene.SerializeToString(&message);
_worldThread.push(message);
}
void CarlaCommunication::sendReset(const EpisodeReady &ready) {
std::string message;
bool error = !ready.SerializeToString(&message);
if (!error) {
//std::cout << "Send End Reset" << std::endl;
_worldThread.push(message);
}
else {
std::cout << " >> SEND RESET ERROR <<" << std::endl;
}
}
bool CarlaCommunication::tryReadWorldInfo(std::string &info) {
return _worldThread.tryPop(info);
}
bool CarlaCommunication::tryReadWorldInfo(std::string &info) {
return _worldThread.tryPop(info);
}
}
}
}

View File

@ -3,43 +3,44 @@
#include "carla/server/Protocol.h"
#include "carla/server/TCPServer.h"
#include "carla/thread/AsyncReadWriteJobQueue.h"
#include "carla/thread/AsyncReaderJobQueue.h"
#include "carla/thread/AsyncWriterJobQueue.h"
#include "carla/thread/AsyncReadWriteJobQueue.h"
namespace carla {
namespace server {
class CarlaCommunication : private NonCopyable {
public:
namespace server {
explicit CarlaCommunication(int worldPort, int writePort, int readPort);
class CarlaCommunication : private NonCopyable {
public:
void sendReward(const Reward &reward);
explicit CarlaCommunication(int worldPort, int writePort, int readPort);
bool tryReadControl(std::string &control);
void sendReward(const Reward &reward);
void sendScene(const Scene &scene);
bool tryReadControl(std::string &control);
void sendReset(const EpisodeReady &ready);
void sendScene(const Scene &scene);
void sendWorld(const World &world);
void sendReset(const EpisodeReady &ready);
bool tryReadWorldInfo(std::string &info);
void sendWorld(const World &world);
private:
bool tryReadWorldInfo(std::string &info);
TCPServer _server;
private:
TCPServer _client;
TCPServer _server;
TCPServer _world;
TCPServer _client;
thread::AsyncReaderJobQueue<std::string> _serverThread;
TCPServer _world;
thread::AsyncWriterJobQueue<std::string> _clientThread;
thread::AsyncReaderJobQueue<std::string> _serverThread;
thread::AsyncReadWriteJobQueue<std::string, std::string> _worldThread;
thread::AsyncWriterJobQueue<std::string> _clientThread;
};
}
}
thread::AsyncReadWriteJobQueue<std::string, std::string> _worldThread;
};
}
}

View File

@ -7,15 +7,14 @@
#include <memory>
namespace carla {
namespace server {
// -- CarlaServer ------------------------------------------------------------
CarlaServer::CarlaServer(int worldPort, int writePort, int readPort, int modesCount, int scenesCount) :
_communication(std::make_unique<CarlaCommunication>(worldPort, writePort, readPort)), _proto(std::make_unique<Protocol>(this)),
_modes(modesCount),
_scenes(scenesCount){
_communication(std::make_unique<CarlaCommunication>(worldPort, writePort, readPort)), _proto(std::make_unique<Protocol>(this)),
_modes(modesCount),
_scenes(scenesCount){
}
@ -23,120 +22,120 @@ namespace server {
}
void CarlaServer::sendReward(const Reward_Values &values) {
Reward reward = _proto->LoadReward(values);
_communication->sendReward(reward);
Reward reward = _proto->LoadReward(values);
_communication->sendReward(reward);
}
void CarlaServer::sendSceneValues(const Scene_Values &values) {
Scene scene = _proto->LoadScene(values);
_communication->sendScene(scene);
Scene scene = _proto->LoadScene(values);
_communication->sendScene(scene);
}
void CarlaServer::sendEndReset() {
EpisodeReady eReady;
eReady.set_ready(true);
_communication->sendReset(eReady);
EpisodeReady eReady;
eReady.set_ready(true);
_communication->sendReset(eReady);
}
void CarlaServer::sendWorld() {
World world = _proto->LoadWorld();
_communication->sendWorld(world);
World world = _proto->LoadWorld();
_communication->sendWorld(world);
}
bool CarlaServer::tryReadControl(float &steer, float &gas) {
std::string controlMessage;
std::string controlMessage;
bool success = _communication->tryReadControl(controlMessage);
Control control;
if (success) {
success &= control.ParseFromString(controlMessage);
}
steer = control.steer();
gas = control.gas();
Control control;
if (success) {
success &= control.ParseFromString(controlMessage);
}
steer = control.steer();
gas = control.gas();
if (!success) {
steer = 0.0f;
gas = 0.0f;
}
else {
steer = control.steer();
gas = control.gas();
//std::cout << "Steer: " << steer << " Gas: " << gas << std::endl;
}
if (!success) {
steer = 0.0f;
gas = 0.0f;
}
else {
steer = control.steer();
gas = control.gas();
//std::cout << "Steer: " << steer << " Gas: " << gas << std::endl;
}
return success;
return success;
}
bool CarlaServer::tryReadSceneInit(int &mode, int &scene) {
std::string initMessage;
bool success = _communication->tryReadWorldInfo(initMessage);
SceneInit sceneInit;
std::string initMessage;
bool success = _communication->tryReadWorldInfo(initMessage);
SceneInit sceneInit;
if (success) {
success &= sceneInit.ParseFromString(initMessage);
}
if (!success) {
mode = -1;
scene = -1;
}
else {
mode = sceneInit.mode();
scene = sceneInit.scene();
//std::cout << "Mode: " << mode << " Scene: " << scene << std::endl;
}
if (success) {
success &= sceneInit.ParseFromString(initMessage);
}
return success;
if (!success) {
mode = -1;
scene = -1;
}
else {
mode = sceneInit.mode();
scene = sceneInit.scene();
//std::cout << "Mode: " << mode << " Scene: " << scene << std::endl;
}
return success;
}
bool CarlaServer::tryReadEpisodeStart(float &start_index, float &end_index) {
std::string startData;
bool success = _communication->tryReadWorldInfo(startData);
EpisodeStart episodeStart;
success &= episodeStart.ParseFromString(startData);
std::string startData;
bool success = _communication->tryReadWorldInfo(startData);
EpisodeStart episodeStart;
success &= episodeStart.ParseFromString(startData);
if (!success) {
start_index = -1.0f;
end_index = -1.0f;
}
else {
start_index = episodeStart.start_index();
end_index = episodeStart.end_index();
//std::cout << "Start: " << start_index << " End: " << end_index << std::endl;
}
if (!success) {
start_index = -1.0f;
end_index = -1.0f;
}
else {
start_index = episodeStart.start_index();
end_index = episodeStart.end_index();
//std::cout << "Start: " << start_index << " End: " << end_index << std::endl;
}
return success;
return success;
}
void CarlaServer::setMode(Mode mode) {
_mode = mode;
_mode = mode;
}
Mode CarlaServer::GetMode() const {
return _mode;
return _mode;
}
void CarlaServer::SetScene(int scene) {
_scene = scene;
_scene = scene;
}
int CarlaServer::GetScene() const {
return _scene;
return _scene;
}
int CarlaServer::GetModesCount() const {
return _modes;
return _modes;
}
int CarlaServer::GetScenesCount() const {
return _scenes;
return _scenes;
}
void CarlaServer::SetReset(bool reset) {
_reset = reset;
_reset = reset;
}
bool CarlaServer::Reset() const {
return _reset;
return _reset;
}
} // namespace server

View File

@ -13,41 +13,41 @@
namespace carla {
namespace server {
struct Color {
char red;
char green;
char blue;
//char alpha;
};
struct Color {
char red;
char green;
char blue;
//char alpha;
};
struct Position {
float x, y;
};
struct Position {
float x, y;
};
struct Reward_Values {
float player_x, player_y;
float speed;
float collision_gen, collision_ped, collision_car;
float intersect;
float inertia_x, inertia_y, inertia_z;
std::int32_t timestamp;
float ori_x = 0, ori_y, ori_z;
std::vector<Color> img;
std::vector<Color> img_2;
std::vector<Color> depth_1;
std::vector<Color> depth_2;
};
struct Reward_Values {
float player_x, player_y;
float speed;
float collision_gen, collision_ped, collision_car;
float intersect;
float inertia_x, inertia_y, inertia_z;
std::int32_t timestamp;
float ori_x = 0, ori_y, ori_z;
std::vector<Color> img;
std::vector<Color> img_2;
std::vector<Color> depth_1;
std::vector<Color> depth_2;
};
struct Scene_Values {
std::vector<Position> _possible_Positions;
std::vector<const float *> _projection_Matrix;
};
struct Scene_Values {
std::vector<Position> _possible_Positions;
std::vector<const float*> _projection_Matrix;
};
enum Mode {
MONO = 0,
STEREO = 1
};
enum Mode {
MONO = 0,
STEREO = 1
};
/// Asynchronous TCP server. Uses two ports, one for sending messages (write)
/// and one for receiving messages (read).
///
@ -67,55 +67,54 @@ namespace server {
///// Send values of the current player status
void sendReward( const Reward_Values &values);
//// Send the values of the generated scene
void sendSceneValues( const Scene_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();
//// Send a signal to the client to notify that the car is ready
void sendEndReset();
void sendWorld();
void sendWorld();
///// 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(int &mode, int &scene);
////Try to read if the client has selected an end & start point. Return false if the queue is empty
bool tryReadEpisodeStart(float &start_index, float &end_index);
////Try to read if the client has selected an scene and mode. Return false if the queue is empty
bool tryReadSceneInit(int &mode, int &scene);
////Try to read if the client has selected an end & start point. Return false if the queue is empty
bool tryReadEpisodeStart(float &start_index, float &end_index);
int GetModesCount() const;
int GetModesCount() const;
int GetScenesCount() const;
int GetScenesCount() const;
void setMode(Mode mode);
Mode GetMode() const;
void setMode(Mode mode);
void SetScene(int scene);
int GetScene() const;
Mode GetMode() const;
void SetReset(bool reset);
bool Reset() const;
void SetScene(int scene);
int GetScene() const;
void SetReset(bool reset);
bool Reset() const;
private:
//std::mutex _mutex;
//std::mutex _mutex;
std::atomic<Mode> _mode = MONO;
std::atomic_int _scene;
std::atomic_bool _reset;
std::atomic<Mode> _mode {MONO};
std::atomic_int _scene;
std::atomic_bool _reset;
const int _modes;
const int _scenes;
const int _modes;
const int _scenes;
const std::unique_ptr<CarlaCommunication> _communication;
const std::unique_ptr<Protocol> _proto;
const std::unique_ptr<CarlaCommunication> _communication;
const std::unique_ptr<Protocol> _proto;
};
} // namespace server

View File

@ -1,47 +0,0 @@
#include "Carla.h"
#include <boost/asio.hpp>
#include <boost\bind.hpp>
namespace carla {
namespace server {
class TCPConnection : public boost::enable_shared_from_this<TCPConnection>
{
public:
typedef boost::shared_ptr<TCPConnection> pointer;
static pointer create(boost::asio::io_service &io_service) {
return pointer(new TCPConnection(io_service));
}
boost::asio::ip::tcp::socket& socket() {
return socket_;
}
void Send(const std::string &message) {
message_ = message;
boost::asio::async_write(socket_, boost::asio::buffer(message_),
boost::bind(&TCPConnection::handle_write, shared_from_this()));
}
private:
TCPConnection(boost::asio::io_service& io_service)
: socket_(io_service)
{
}
void handle_write(const boost::system::error_code& /*error*/,
size_t /*bytes_transferred*/)
{
}
std::string message_;
boost::asio::ip::tcp::socket socket_;
};
}
}

View File

@ -13,21 +13,24 @@ namespace thread {
/// Executes the given job asynchronously. Every item that the job returns is
/// added to the queue.
template <typename W, typename R>
template<typename W, typename R>
class CARLA_API AsyncReadWriteJobQueue {
public:
using WritingJob = std::function<W()>;
using ReadingJob = std::function<void(R)>;
using ConnectJob = std::function<void()>;
using ReadingJob = std::function<void(R)>;
using ConnectJob = std::function<void()>;
explicit AsyncReadWriteJobQueue(WritingJob &&writingJob, ReadingJob &&readingJob, ConnectJob &&connectJob) :
_done(false),
_writeJob(std::move(writingJob)),
_readJob(std::move(readingJob)),
_connectJob(std::move(connectJob)),
_writeQueue(),
_thread(new std::thread(&AsyncReadWriteJobQueue::workerThread, this)) {}
explicit AsyncReadWriteJobQueue(
WritingJob && writingJob,
ReadingJob && readingJob,
ConnectJob && connectJob) :
_done(false),
_writeJob(std::move(writingJob)),
_readJob(std::move(readingJob)),
_connectJob(std::move(connectJob)),
_writeQueue(),
_thread(new std::thread(&AsyncReadWriteJobQueue::workerThread, this)) {}
~AsyncReadWriteJobQueue() {
_done = true;
@ -37,30 +40,30 @@ namespace thread {
return _writeQueue.try_pop(value);
}
void push(R item) {
_readQueue.push(item);
}
void push(R item) {
_readQueue.push(item);
}
private:
void workerThread() {
_connectJob();
_connectJob();
while (!_done) {
R value;
_readQueue.wait_and_pop(value);
_readJob(value);
_writeQueue.push(_writeJob());
R value;
_readQueue.wait_and_pop(value);
_readJob(value);
_writeQueue.push(_writeJob());
}
}
std::atomic_bool _done;
WritingJob _writeJob;
ReadingJob _readJob;
ConnectJob _connectJob;
WritingJob _writeJob;
ReadingJob _readJob;
ConnectJob _connectJob;
ThreadSafeQueue<W> _writeQueue;
ThreadSafeQueue<R> _readQueue;
ThreadSafeQueue<R> _readQueue;
const ThreadUniquePointer _thread;
};

View File

@ -30,148 +30,145 @@ static std::string daytimeString() {
return str;
}
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
try {
if (argc != 6) {
std::cerr << "Usage: server <send-port> <read-port>" << std::endl;
return InvalidArguments;
}
using namespace carla::server;
using namespace carla::server;
// This already starts the two threads.
CarlaServer server(toInt(argv[1u]), toInt(argv[2u]), toInt(argv[3u]), toInt(argv[4u]), toInt(argv[5u]));
// Let's simulate the game loop.
Color c1;
c1.red = 255;
c1.green = 0;
c1.blue = 0;
//c1.alpha = 0;
Color c1;
c1.red = 255;
c1.green = 0;
c1.blue = 0;
//c1.alpha = 0;
Color c2;
c2.red = 4;
c2.green = 5;
c2.blue = 6;
//c2.alpha = 0;
Color c2;
c2.red = 4;
c2.green = 5;
c2.blue = 6;
//c2.alpha = 0;
Color c3;
c3.red = 7;
c3.green = 8;
c3.blue = 9;
//c3.alpha = 0;
Color c3;
c3.red = 7;
c3.green = 8;
c3.blue = 9;
//c3.alpha = 0;
Color c4;
c4.red = 10;
c4.green = 11;
c4.blue = 12;
//c4.alpha = 0;
Color c4;
c4.red = 10;
c4.green = 11;
c4.blue = 12;
//c4.alpha = 0;
std::vector<Color> img;
for (int i = 0; i < 1024; ++i) img.push_back(c1);
std::vector<Color> img;
for (int i=0; i < 1024; ++i) img.push_back(c1);
std::vector<Color> img_2;
for (int i = 0; i < 1024; ++i) img_2.push_back(c2);
std::vector<Color> img_2;
for (int i = 0; i < 1024; ++i) img_2.push_back(c2);
std::vector<Color> depth_1;
for (int i = 0; i < 1024; ++i) depth_1.push_back(c3);
std::vector<Color> depth_1;
for (int i = 0; i < 1024; ++i) depth_1.push_back(c3);
std::vector<Color> depth_2;
for (int i = 0; i < 1024; ++i) depth_2.push_back(c4);
std::vector<Color> depth_2;
for (int i = 0; i < 1024; ++i) depth_2.push_back(c4);
Reward_Values testData;
testData.player_x = 1.0f;
testData.player_y = 1.0f;
testData.speed = 100.0f;
testData.collision_gen = 10.0f;
testData.collision_ped = 10.0f;
testData.collision_car = 10.0f;
testData.intersect = 50.0f;
testData.inertia_x = 0.5f;
testData.inertia_y = 0.1f;
testData.inertia_z = 0.02f;
testData.timestamp = 1;
testData.ori_x = 10.0f;
testData.ori_y = 20.0f;
testData.ori_z = 30.0f;
testData.img = img;
testData.img_2 = img_2;
testData.depth_1 = depth_1;
testData.depth_2 = depth_2;
Reward_Values testData;
testData.player_x = 1.0f;
testData.player_y = 1.0f;
testData.speed = 100.0f;
testData.collision_gen = 10.0f;
testData.collision_ped = 10.0f;
testData.collision_car = 10.0f;
testData.intersect = 50.0f;
testData.inertia_x = 0.5f;
testData.inertia_y = 0.1f;
testData.inertia_z = 0.02f;
testData.timestamp = 1;
testData.ori_x = 10.0f;
testData.ori_y = 20.0f;
testData.ori_z = 30.0f;
testData.img = img;
testData.img_2 = img_2;
testData.depth_1 = depth_1;
testData.depth_2 = depth_2;
std::cout << "Server send World" << std::endl;
server.sendWorld();
std::cout << "Server send World" << std::endl;
server.sendWorld();
int mode, scene;
bool end = false;
int mode, scene;
bool end = false;
std::cout << "Server wait scene init" << std::endl;
do {
end = server.tryReadSceneInit(mode, scene);
}while (!end);
std::cout << "Server wait scene init" << std::endl;
do {
end = server.tryReadSceneInit(mode, scene);
} while (!end);
std::vector<Position> positions;
std::vector<const float*> pMatrix;
std::vector<Position> positions;
std::vector<const float *> pMatrix;
positions.push_back(Position{ 0.0f, 0.0f });
positions.push_back(Position{ 1.0f, 2.0f });
positions.push_back(Position{ 3.0f, 4.0f });
positions.push_back(Position { 0.0f, 0.0f });
positions.push_back(Position { 1.0f, 2.0f });
positions.push_back(Position { 3.0f, 4.0f });
float list[16] = { 10.0, 10.0,10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
float list[16] = { 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
pMatrix.push_back(list);
pMatrix.push_back(list);
Scene_Values sceneVal = {
positions,
pMatrix,
};
Scene_Values sceneVal = {
positions,
pMatrix,
};
std::cout << "Server send positions" << std::endl;
std::cout << "Server send positions" << std::endl;
server.sendSceneValues(sceneVal);
end = false;
float startPoint, endPoint;
server.sendSceneValues(sceneVal);
std::cout << "Server wait new episode" << std::endl;
end = false;
float startPoint, endPoint;
do {
std::cout << "Server wait new episode" << std::endl;
end = server.tryReadEpisodeStart(startPoint, endPoint);
}
while (!end);
do {
std::cout << "Server send end reset" << std::endl;
end = server.tryReadEpisodeStart(startPoint, endPoint);
} while (!end);
server.sendEndReset();
std::cout << "Server send end reset" << std::endl;
float steer, gas;
bool wait_control = false;
server.sendEndReset();
float steer, gas;
bool wait_control = false;
for (;;) {
if (server.tryReadEpisodeStart(startPoint, endPoint)) {
std::cout << "------> RESET <------" << std::endl;
std::cout << " --> Start: " << startPoint << " End: " << endPoint << std::endl;
server.sendEndReset();
}
else {
if (server.tryReadEpisodeStart(startPoint, endPoint)) {
std::cout << "------> RESET <------" << std::endl;
std::cout << " --> Start: " << startPoint << " End: " << endPoint << std::endl;
server.sendEndReset();
} else {
if (wait_control && server.tryReadControl(steer, gas)) {
std::cout << "Steer: " << steer << "Gas: " << gas << std::endl;
wait_control = false;
}
else if (!wait_control) {
server.sendReward(testData);
wait_control = true;
}
if (wait_control && server.tryReadControl(steer, gas)) {
std::cout << "Steer: " << steer << "Gas: " << gas << std::endl;
wait_control = false;
} else if (!wait_control) {
server.sendReward(testData);
wait_control = true;
}
}
Sleep(100);
}
{
using namespace std::chrono_literals;
std::this_thread::sleep_for(100ms);
}
}
} catch (const std::exception &e) {