Merge branch 'xisco' into nestor, related to #10 and #14

This commit is contained in:
nsubiron 2017-04-25 17:48:46 +02:00
commit 8366e5c0c9
7 changed files with 43 additions and 31 deletions

View File

@ -48,6 +48,7 @@ namespace carla {
if (!worldConnected()) if (!worldConnected())
return false; return false;
readed = _pimpl->communication.tryReadEpisodeStart(startIndex, endIndex); readed = _pimpl->communication.tryReadEpisodeStart(startIndex, endIndex);
std::cout << "Episode Start: " << readed << std::endl;
return true; return true;
} }
@ -62,6 +63,7 @@ namespace carla {
if (!worldConnected()) if (!worldConnected())
return false; return false;
newEpisode = _pimpl->communication.tryReadRequestNewEpisode(); newEpisode = _pimpl->communication.tryReadRequestNewEpisode();
std::cout << "New Episode Request: " << newEpisode << std::endl;
return true; return true;
} }
@ -77,6 +79,8 @@ namespace carla {
if (!worldConnected()) if (!worldConnected())
return false; return false;
_pimpl->communication.sendScene(values); _pimpl->communication.sendScene(values);
std::cout << "Send scene values" << std::endl;
return true; return true;
} }
@ -84,6 +88,9 @@ namespace carla {
if (!worldConnected()) if (!worldConnected())
return false; return false;
_pimpl->communication.sendReset(); _pimpl->communication.sendReset();
std::cout << "Send end reset" << std::endl;
return true; return true;
} }

View File

@ -44,7 +44,8 @@ namespace carla {
Reward_Values(); Reward_Values();
~Reward_Values(); ~Reward_Values();
/// Time-stamp of the current frame. /// Time-stamp of the current frame.
int32_t timestamp; int32_t platform_timestamp;
int32_t game_timestamp;
/// World location of the player. /// World location of the player.
Vector2D player_location; Vector2D player_location;
/// Orientation of the player. /// Orientation of the player.

View File

@ -221,16 +221,12 @@ namespace server {
} }
void CarlaCommunication::sendScene(const Scene_Values &values) { void CarlaCommunication::sendScene(const Scene_Values &values) {
// Protobuf produces a segmentation fault in the destructor of the Scene Scene scene;
// when called from Unreal Engine in Linux. As a workaround, we added this _proto->LoadScene(scene, values);
// cute memory leak.
/// @todo #10 Fix the memory leak!
Scene *scene = new Scene;
_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));
} }
} }

View File

@ -241,11 +241,6 @@ static bool getPNGImages(const std::vector<Image> &images, Reward &rwd) {
} }
std::cout << "send depth size: " << depth_size_data.size() <<
" send image size: " << image_size_data.size()<<
" send image: " << image_data.size()<<
" send depth: " << depth_data.size() << std::endl;
rwd.set_depth_sizes(depth_size_data); rwd.set_depth_sizes(depth_size_data);
rwd.set_image_sizes(image_size_data); rwd.set_image_sizes(image_size_data);
rwd.set_images(image_data); rwd.set_images(image_data);
@ -280,7 +275,8 @@ static bool getPNGImages(const std::vector<Image> &images, Reward &rwd) {
reward.set_player_y(values.player_location.y); reward.set_player_y(values.player_location.y);
reward.set_player_x(values.player_location.x); reward.set_player_x(values.player_location.x);
reward.set_speed(values.forward_speed); reward.set_speed(values.forward_speed);
reward.set_timestamp(values.timestamp); reward.set_platform_timestamp(values.platform_timestamp);
reward.set_game_timestamp(values.game_timestamp);
#ifdef CARLA_WITH_PNG_COMPRESSION #ifdef CARLA_WITH_PNG_COMPRESSION
if (!getPNGImages(values.images, reward)) { if (!getPNGImages(values.images, reward)) {

View File

@ -36,7 +36,12 @@ namespace carla {
port(port), port(port),
_service(), _service(),
_socket(_service), _socket(_service),
_connected(false){} _connected(false){
//int32_t timeout = 500;
//setsockopt(_socket.native(), SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout));
}
TCPServer::~TCPServer() {} TCPServer::~TCPServer() {}
@ -60,7 +65,6 @@ namespace carla {
void TCPServer::writeString(const std::string &message, error_code &error) { void TCPServer::writeString(const std::string &message, error_code &error) {
const int messageSize = static_cast<int>(message.length()); const int messageSize = static_cast<int>(message.length());
std::string outMessage(GetBytes(messageSize) + message); std::string outMessage(GetBytes(messageSize) + message);
boost::asio::write(_socket, boost::asio::buffer(outMessage), error); boost::asio::write(_socket, boost::asio::buffer(outMessage), error);
if (error) if (error)

View File

@ -78,13 +78,14 @@ message Reward {
optional float acceleration_x = 9; optional float acceleration_x = 9;
optional float acceleration_y = 10; optional float acceleration_y = 10;
optional float acceleration_z = 11; optional float acceleration_z = 11;
optional int32 timestamp = 12; optional int32 platform_timestamp = 12;
optional float ori_x = 13; optional int32 game_timestamp = 13;
optional float ori_y = 14; optional float ori_x = 14;
optional float ori_z = 15; optional float ori_y = 15;
optional bytes image_sizes = 16; optional float ori_z = 16;
optional bytes depth_sizes = 17; optional bytes image_sizes = 17;
optional bytes images = 18; optional bytes depth_sizes = 18;
optional bytes depths = 19; optional bytes images = 19;
optional bytes depths = 20;
} }

View File

@ -58,6 +58,7 @@ std::unique_ptr<carla::Reward_Values> makeReward() {
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;
reward->game_timestamp = 0u;
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
carla::Image img; carla::Image img;
@ -74,8 +75,9 @@ std::unique_ptr<carla::Reward_Values> makeReward() {
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::platform_timestamp) timestamp = 0u;
reward->timestamp = timestamp++;
reward->platform_timestamp = timestamp++;
return reward; return reward;
} }
@ -162,7 +164,11 @@ 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 {
std::cout << "Try read episode Start: ";
error = !server.tryReadEpisodeStart(startPoint, endPoint, readed); error = !server.tryReadEpisodeStart(startPoint, endPoint, readed);
std::cout << error << std::endl;
} while (!readed && !error); } while (!readed && !error);
if (error) { if (error) {
@ -183,10 +189,11 @@ int main(int argc, char *argv[]) {
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;