Improvements on how the settings are loaded, define a settings hierarchy

This commit is contained in:
nsubiron 2017-06-03 11:52:39 +01:00
parent 1a870a5df0
commit 0beacfdd83
5 changed files with 104 additions and 82 deletions

View File

@ -4,6 +4,7 @@
* Changed server-client protocol
- CarlaSettings.ini is sent for every new episode
- Control is extended with brake, reverse and handbrake
* Set a clearer hierarchy for loading settings files
* Made camera post-process settings able to change depending on the weather
* Added basic functionality for NPC vehicles
* Some improvements to the walker spawner

View File

@ -1,7 +1,12 @@
; Example of settings file for CARLA.
; Settings are loaded following the next hierarchy, with values later in the
; hierarchy overriding earlier values.
;
; Either provide through command-line `-carla-settings=<path-to-ini-file>`, or
; make a copy at `{ProjectFolder}/Config/CarlaSettings.ini`.
; 1) `{ProjectFolder}/Config/CarlaSettings.ini`
; 2) File provided by command-line argument `-carla-settings=<path-to-ini-file>`
; 3) Other command-line arguments as `-world-port`, or `-carla-no-networking`
; 4) Settings file sent by the client on every new episode.
[CARLA/Server]
; If set to false, a mock controller will be used instead of waiting for a
@ -15,24 +20,22 @@ WritePort=2001
ReadPort=2002
[CARLA/LevelSettings]
; Number of NPC vehicles to be spawned into the level.
; Number of non-player vehicles to be spawned into the level.
NumberOfVehicles=5
; Number of NPC pedestrians to be spawned into the level.
; Number of non-player pedestrians to be spawned into the level.
NumberOfPedestrians=15
; Index of the weather presets to use. If negative, weather won't be changed.
; Index of the weather/lighting presets to use. If negative, the default presets
; of the map will be used.
WeatherId=-1
[CARLA/SceneCapture]
; Names of the scene capture cameras to attach to the player, each of them
; should be defined in its own subsection.
Cameras=CameraStereoLeft/RGB,CameraStereoLeft/Depth,CameraStereoRight/RGB,CameraStereoRight/Depth
; Cameras=CameraMono
; Names of the scene capture cameras to attach to the player, comma-separated,
; each of them should be defined in its own subsection.
Cameras=MyCamera
; Defaults for each camera can be set here, e.g.
ImageSizeX=720
ImageSizeY=512
; Defaults for each camera can be set here too.
[CARLA/SceneCapture/CameraMono]
[CARLA/SceneCapture/MyCamera]
; Post-processing effect to be applied. Valid values:
; * None No effects applied.
; * SceneFinal Post-processing present at scene (bloom, fog, etc).
@ -40,38 +43,45 @@ ImageSizeY=512
; * SemanticSegmentation Semantic segmentation only.
PostProcessing=SceneFinal
; Size of the captured image in pixels.
ImageSizeX=720
ImageSizeY=512
ImageSizeX=1280
ImageSizeY=350
; Camera field of view in degrees.
CameraFOV=90
CameraFOV=110
; Position of the camera relative to the car in centimeters.
CameraPositionX=170
CameraPositionX=15
CameraPositionY=0
CameraPositionZ=150
CameraPositionZ=123
; Rotation of the camera relative to the car in degrees.
CameraRotationPitch=0
CameraRotationPitch=8
CameraRotationRoll=0
CameraRotationYaw=0
[CARLA/SceneCapture/CameraStereoLeft]
CameraPositionX=170
CameraPositionY=-30
CameraPositionZ=150
CameraRotationPitch=0
CameraRotationRoll=0
CameraRotationYaw=0
[CARLA/SceneCapture/CameraStereoLeft/RGB]
PostProcessing=SceneFinal
[CARLA/SceneCapture/CameraStereoLeft/Depth]
PostProcessing=Depth
[CARLA/SceneCapture/CameraStereoRight]
CameraPositionX=170
CameraPositionY=30
CameraPositionZ=150
CameraRotationPitch=0
CameraRotationRoll=0
CameraRotationYaw=0
[CARLA/SceneCapture/CameraStereoRight/RGB]
PostProcessing=SceneFinal
[CARLA/SceneCapture/CameraStereoRight/Depth]
PostProcessing=Depth
; Stereo setup example:
;
; [CARLA/SceneCapture]
; Cameras=CameraStereoLeft/RGB,CameraStereoLeft/Depth,CameraStereoRight/RGB,CameraStereoRight/Depth
; ImageSizeX=720
; ImageSizeY=512
; CameraFOV=90
; [CARLA/SceneCapture/CameraStereoLeft]
; CameraPositionX=170
; CameraPositionY=-30
; CameraPositionZ=150
; CameraRotationPitch=0
; CameraRotationRoll=0
; CameraRotationYaw=0
; [CARLA/SceneCapture/CameraStereoLeft/RGB]
; PostProcessing=SceneFinal
; [CARLA/SceneCapture/CameraStereoLeft/Depth]
; PostProcessing=Depth
; [CARLA/SceneCapture/CameraStereoRight]
; CameraPositionX=170
; CameraPositionY=30
; CameraPositionZ=150
; CameraRotationPitch=0
; CameraRotationRoll=0
; CameraRotationYaw=0
; [CARLA/SceneCapture/CameraStereoRight/RGB]
; PostProcessing=SceneFinal
; [CARLA/SceneCapture/CameraStereoRight/Depth]
; PostProcessing=Depth

View File

@ -8,8 +8,8 @@ To run the game at fixed time-step, e.g. 30 FPS
Other CARLA related command-line options
* `-carla-settings=<ini-file-path>` Load settings from the given INI file. See Example.CarlaSettings.ini.
* `-world-port=<port-number>` Listen for client connections at <port-number>, write and read ports are set to <port-number>+1 and <port-number>+2 respectively.
* `-carla-no-networking` Disable networking. Overrides any settings file.
* `-world-port=<port-number>` Listen for client connections at <port-number>, write and read ports are set to <port-number>+1 and <port-number>+2 respectively. Activates networking.
* `-carla-no-networking` Disable networking. Overrides any other settings file.
To activate semantic segmentation
---------------------------------

View File

@ -123,24 +123,15 @@ static void LoadSettingsFromConfig(
}
}
static bool GetSettingsFileName(FString &Value)
static FString GetSettingsFilePathFromCommandLine()
{
// Try to get it from the command-line arguments.
FString Value;
if (FParse::Value(FCommandLine::Get(), TEXT("-carla-settings="), Value)) {
if (FPaths::IsRelative(Value)) {
Value = FPaths::ConvertRelativePathToFull(FPaths::LaunchDir(), Value);
}
if (FPaths::FileExists(Value)) {
return true;
}
UE_LOG(LogCarla, Error, TEXT("Unable to find settings file \"%s\", falling back to default values"), *Value);
}
// If fails, check if there is one in the config folder.
Value = FPaths::Combine(FPaths::GameConfigDir(), TEXT("CarlaSettings.ini"));
if (FPaths::FileExists(Value)) {
return true;
}
return false;
return Value;
}
// =============================================================================
@ -149,45 +140,41 @@ static bool GetSettingsFileName(FString &Value)
void UCarlaSettings::LoadSettings()
{
FString FileName;
if (GetSettingsFileName(FileName)) {
UE_LOG(LogCarla, Log, TEXT("Loading CARLA settings from \"%s\""), *FileName);
const MyIniFile ConfigFile(FileName);
LoadSettingsFromConfig(ConfigFile, *this, true);
CurrentFileName = FileName;
} else {
CurrentFileName = TEXT("");
}
CurrentFileName = TEXT("");
// Load settings from project Config folder if present.
LoadSettingsFromFile(FPaths::Combine(FPaths::GameConfigDir(), TEXT("CarlaSettings.ini")), false);
// Load settings given by command-line arg if provided.
LoadSettingsFromFile(GetSettingsFilePathFromCommandLine(), true);
// Override settings from command-line.
uint32 Value;
if (FParse::Value(FCommandLine::Get(), TEXT("-world-port="), Value)) {
WorldPort = Value;
WritePort = Value + 1u;
ReadPort = Value + 2u;
}
if (FParse::Param(FCommandLine::Get(), TEXT("carla-no-networking"))) {
bUseNetworking = false;
{
uint32 Value;
if (FParse::Value(FCommandLine::Get(), TEXT("-world-port="), Value)) {
WorldPort = Value;
WritePort = Value + 1u;
ReadPort = Value + 2u;
bUseNetworking = true;
}
if (FParse::Param(FCommandLine::Get(), TEXT("carla-no-networking"))) {
bUseNetworking = false;
}
}
}
void UCarlaSettings::LoadSettingsFromString(
const FString &INIFileContents,
const bool bLoadCarlaServerSection)
void UCarlaSettings::LoadSettingsFromString(const FString &INIFileContents)
{
UE_LOG(LogCarla, Log, TEXT("Loading CARLA settings from string"));
// Reset cameras.
CameraDescriptions.Empty();
bSemanticSegmentationEnabled = false;
// Load config from string.
ResetCameraDescriptions();
MyIniFile ConfigFile;
ConfigFile.ProcessInputFileContents(INIFileContents);
constexpr bool bLoadCarlaServerSection = false;
LoadSettingsFromConfig(ConfigFile, *this, bLoadCarlaServerSection);
CurrentFileName = TEXT("<string-provided-by-client>");
}
void UCarlaSettings::LogSettings() const
{
UE_LOG(LogCarla, Log, TEXT("== CARLA Settings =============================================================="));
UE_LOG(LogCarla, Log, TEXT("Settings file: %s"), *CurrentFileName);
UE_LOG(LogCarla, Log, TEXT("Last settings file loaded: %s"), *CurrentFileName);
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SERVER);
UE_LOG(LogCarla, Log, TEXT("Use Networking = %s"), (bUseNetworking ? TEXT("True") : TEXT("False")));
UE_LOG(LogCarla, Log, TEXT("World Port = %d"), WorldPort);
@ -230,3 +217,23 @@ void UCarlaSettings::GetActiveWeatherDescription(
bWeatherWasChanged = false;
}
}
void UCarlaSettings::ResetCameraDescriptions()
{
CameraDescriptions.Empty();
bSemanticSegmentationEnabled = false;
}
void UCarlaSettings::LoadSettingsFromFile(const FString &FilePath, const bool bLogOnFailure)
{
if (FPaths::FileExists(FilePath)) {
UE_LOG(LogCarla, Log, TEXT("Loading CARLA settings from \"%s\""), *FilePath);
ResetCameraDescriptions();
const MyIniFile ConfigFile(FilePath);
constexpr bool bLoadCarlaServerSection = true;
LoadSettingsFromConfig(ConfigFile, *this, bLoadCarlaServerSection);
CurrentFileName = FilePath;
} else if (bLogOnFailure) {
UE_LOG(LogCarla, Error, TEXT("Unable to find settings file \"%s\""), *FilePath);
}
}

View File

@ -19,8 +19,8 @@ public:
/** Load the settings based on the command-line arguments and the INI file if provided. */
void LoadSettings();
/** Load the settings from the given string (formatted as INI). */
void LoadSettingsFromString(const FString &INIFileContents, bool bLoadCarlaServerSection = false);
/** Load the settings from the given string (formatted as INI). CarlaServer section is ignored. */
void LoadSettingsFromString(const FString &INIFileContents);
/** Log settings values. */
void LogSettings() const;
@ -41,6 +41,10 @@ public:
private:
void LoadSettingsFromFile(const FString &FilePath, bool bLogOnFailure);
void ResetCameraDescriptions();
/** File name of the settings file used to load this settings. Empty if none used. */
UPROPERTY(Category = "CARLA Settings|Debug", VisibleAnywhere)
FString CurrentFileName;