From 244334512667c4a9777ef94f7327b699ac39c2df Mon Sep 17 00:00:00 2001 From: nsubiron Date: Fri, 28 Jul 2017 17:03:30 +0200 Subject: [PATCH] Add more options to CARLA settings --- Resources/Example.CarlaSettings.ini | 10 ++++++++-- Source/Carla/Game/CarlaGameController.cpp | 3 ++- Source/Carla/Game/CarlaServer.cpp | 7 +++++-- Source/Carla/Game/CarlaServer.h | 3 ++- Source/Carla/Settings/CarlaSettings.cpp | 4 +++- Source/Carla/Settings/CarlaSettings.h | 6 +++++- Util/PythonClient/carla_client.py | 4 ++++ 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Resources/Example.CarlaSettings.ini b/Resources/Example.CarlaSettings.ini index 8f731bff9..335106166 100644 --- a/Resources/Example.CarlaSettings.ini +++ b/Resources/Example.CarlaSettings.ini @@ -16,8 +16,14 @@ UseNetworking=true ; the command-line switch `-world-port=N`, write and read ports will be set to ; N+1 and N+2 respectively. WorldPort=2000 -WritePort=2001 -ReadPort=2002 +; Time-out in milliseconds for the networking operations. +ServerTimeOut=10000 +; In synchronous mode, CARLA waits every tick until the control from the client +; is received. +SynchronousMode=true +; Send info about every non-player agent in the scene every frame. Slows down +; the simulation significantly. +SendNonPlayerAgentsInfo=false [CARLA/LevelSettings] ; Path of the vehicle class to be used for the player. Leave empty for default. diff --git a/Source/Carla/Game/CarlaGameController.cpp b/Source/Carla/Game/CarlaGameController.cpp index 4d35aea05..954f9edec 100644 --- a/Source/Carla/Game/CarlaGameController.cpp +++ b/Source/Carla/Game/CarlaGameController.cpp @@ -114,7 +114,8 @@ void CarlaGameController::Tick(float DeltaSeconds) check(GameState != nullptr); if (Errc::Error == Server->SendMeasurements( *GameState, - Player->GetPlayerState())) { + Player->GetPlayerState(), + CarlaSettings->bSendNonPlayerAgentsInfo)) { Server = nullptr; } } diff --git a/Source/Carla/Game/CarlaServer.cpp b/Source/Carla/Game/CarlaServer.cpp index b369f313b..ff56c3ef3 100644 --- a/Source/Carla/Game/CarlaServer.cpp +++ b/Source/Carla/Game/CarlaServer.cpp @@ -242,7 +242,8 @@ static void GetAgentInfo( CarlaServer::ErrorCode CarlaServer::SendMeasurements( const ACarlaGameState &GameState, - const ACarlaPlayerState &PlayerState) + const ACarlaPlayerState &PlayerState, + const bool bSendNonPlayerAgentsInfo) { // Measurements. carla_measurements values; @@ -259,7 +260,9 @@ CarlaServer::ErrorCode CarlaServer::SendMeasurements( Set(player.intersection_offroad, PlayerState.GetOffRoadIntersectionFactor()); TArray Agents; - GetAgentInfo(GameState, Agents); + if (bSendNonPlayerAgentsInfo) { + GetAgentInfo(GameState, Agents); + } values.non_player_agents = (Agents.Num() > 0 ? Agents.GetData() : nullptr); values.number_of_non_player_agents = Agents.Num(); diff --git a/Source/Carla/Game/CarlaServer.h b/Source/Carla/Game/CarlaServer.h index 54cfc3cf8..db8d07442 100644 --- a/Source/Carla/Game/CarlaServer.h +++ b/Source/Carla/Game/CarlaServer.h @@ -38,7 +38,8 @@ public: ErrorCode SendMeasurements( const ACarlaGameState &GameState, - const ACarlaPlayerState &PlayerState); + const ACarlaPlayerState &PlayerState, + bool bSendNonPlayerAgentsInfo); private: diff --git a/Source/Carla/Settings/CarlaSettings.cpp b/Source/Carla/Settings/CarlaSettings.cpp index 38fbf6137..e4204ba0b 100644 --- a/Source/Carla/Settings/CarlaSettings.cpp +++ b/Source/Carla/Settings/CarlaSettings.cpp @@ -88,8 +88,9 @@ static void LoadSettingsFromConfig( ConfigFile.GetBool(S_CARLA_SERVER, TEXT("UseNetworking"), Settings.bUseNetworking); ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WorldPort"), Settings.WorldPort); ConfigFile.GetInt(S_CARLA_SERVER, TEXT("ServerTimeOut"), Settings.ServerTimeOut); - ConfigFile.GetBool(S_CARLA_SERVER, TEXT("SynchronousMode"), Settings.bSynchronousMode); } + ConfigFile.GetBool(S_CARLA_SERVER, TEXT("SynchronousMode"), Settings.bSynchronousMode); + ConfigFile.GetBool(S_CARLA_SERVER, TEXT("SendNonPlayerAgentsInfo"), Settings.bSendNonPlayerAgentsInfo); // LevelSettings. ConfigFile.GetString(S_CARLA_LEVELSETTINGS, TEXT("PlayerVehicle"), Settings.PlayerVehicle); ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfVehicles"), Settings.NumberOfVehicles); @@ -203,6 +204,7 @@ void UCarlaSettings::LogSettings() const UE_LOG(LogCarla, Log, TEXT("World Port = %d"), WorldPort); UE_LOG(LogCarla, Log, TEXT("Server Time-out = %d ms"), ServerTimeOut); UE_LOG(LogCarla, Log, TEXT("Synchronous Mode = %s"), EnabledDisabled(bSynchronousMode)); + UE_LOG(LogCarla, Log, TEXT("Send Non-Player Agents Info = %s"), EnabledDisabled(bSendNonPlayerAgentsInfo)); UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_LEVELSETTINGS); UE_LOG(LogCarla, Log, TEXT("Player Vehicle = %s"), (PlayerVehicle.IsEmpty() ? TEXT("default") : *PlayerVehicle)); UE_LOG(LogCarla, Log, TEXT("Number Of Vehicles = %d"), NumberOfVehicles); diff --git a/Source/Carla/Settings/CarlaSettings.h b/Source/Carla/Settings/CarlaSettings.h index 7473e1c3a..f58b83965 100644 --- a/Source/Carla/Settings/CarlaSettings.h +++ b/Source/Carla/Settings/CarlaSettings.h @@ -80,7 +80,11 @@ public: * client is received. */ UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking)) - bool bSynchronousMode = false; + bool bSynchronousMode = true; + + /** Send info about every non-player agent in the scene every frame. */ + UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking)) + bool bSendNonPlayerAgentsInfo = false; /// @} // =========================================================================== diff --git a/Util/PythonClient/carla_client.py b/Util/PythonClient/carla_client.py index 98fc59828..63bfc0f3b 100755 --- a/Util/PythonClient/carla_client.py +++ b/Util/PythonClient/carla_client.py @@ -16,6 +16,9 @@ import carla_server_pb2 as carla_protocol CarlaSettings = """ +[CARLA/Server] +SynchronousMode=true +SendNonPlayerAgentsInfo=false [CARLA/LevelSettings] NumberOfVehicles=10 NumberOfPedestrians=20 @@ -172,6 +175,7 @@ def test_carla_client(): logging.info('received non-initialized measurements') else: logging.info('received valid measurements') + logging.info('received info of %d agents', len(data.non_player_agents)) logging.info('waiting for images') data = client.read_images() logging.info('received %d bytes of images', len(data) if data is not None else 0)