Skip to content

Commit

Permalink
Merge pull request #146 from tier4/feature/autoware-simualtion-config
Browse files Browse the repository at this point in the history
Implemented AutowareSimulation.cs
  • Loading branch information
mackierx111 committed Jun 14, 2023
2 parents 4fabf8b + be7fb32 commit 9c00197
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 49 deletions.
8 changes: 8 additions & 0 deletions Assets/AWSIM/Scenes/Main/AutowareSimualtion.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions Assets/AWSIM/Scenes/Main/AutowareSimualtion/AutowareSimulation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using UnityEngine;
using System;
using AWSIM.TrafficSimulation;

namespace AWSIM
{
/// <summary>
/// Script for Scene. By Scirpt-Execution-Order, This class is called earlier than other MonoBehaviour.
/// Enables configuration at scene startup.
/// </summary>
public class AutowareSimulation : MonoBehaviour
{
[SerializeField] TrafficManager trafficManager;

[Header("Player Config")]
[SerializeField] string commandLineConfigParam = "--json_path";

[Header("Editor Debug")]
[SerializeField] bool useJsonConfig;

[Tooltip("Specify this Path if you want to debug Json loading at Unity Editor runtime.")]
[SerializeField] string jsonPath;

[Serializable]
public class Configuration
{
public float TimeScale; // Reflected in Time.timeScale
public int RandomTrafficSeed; // Reflected in TrafficManager.seed
public int MaxVehicleCount; // Reflected in TrafficManager.maxVehicleCount
}

void Awake()
{

#if !UNITY_EDITOR
// initialize
useJsonConfig = false;
jsonPath = "";

// For player, if path is not specified as a command line argument, json is not read.
useJsonConfig = CommandLineUtility.GetCommandLineArg(out jsonPath, commandLineConfigParam);
#endif

if (useJsonConfig)
{
var config = CommandLineUtility.LoadJsonFromPath<Configuration>(jsonPath);
Time.timeScale = config.TimeScale;
trafficManager.seed = config.RandomTrafficSeed;
trafficManager.maxVehicleCount = config.MaxVehicleCount;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 1536.168, g: 1903.334, b: 2519.2246, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -481,6 +481,7 @@ GameObject:
m_Component:
- component: {fileID: 543989980}
- component: {fileID: 543989981}
- component: {fileID: 543989982}
m_Layer: 0
m_Name: AutowareSimulation
m_TagString: Untagged
Expand Down Expand Up @@ -519,6 +520,22 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
meshSource: 2
--- !u!114 &543989982
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 543989979}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cbff45cdd7c84db439f1a4e2e2e66844, type: 3}
m_Name:
m_EditorClassIdentifier:
trafficManager: {fileID: 723377035}
commandLineConfigParam: --json_path
useJsonConfig: 0
jsonPath:
--- !u!114 &553355659 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9027057600446549292, guid: 58d73df60b244d146bdf5f5896f78355, type: 3}
Expand Down Expand Up @@ -689,6 +706,17 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 830ab73cebda3db4580ebd3ece935931, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &723377035 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 445656315769820269, guid: 58d73df60b244d146bdf5f5896f78355, type: 3}
m_PrefabInstance: {fileID: 813212876}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0004da06b69044905bc1db0ab38531a0, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &797679383
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -3991,53 +4019,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 23c1ce4fb46143f46bc5cb5224c934f6, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Version: 7
m_ObsoleteRenderingPath: 0
m_ObsoleteFrameSettings:
overrides: 0
enableShadow: 0
enableContactShadows: 0
enableShadowMask: 0
enableSSR: 0
enableSSAO: 0
enableSubsurfaceScattering: 0
enableTransmission: 0
enableAtmosphericScattering: 0
enableVolumetrics: 0
enableReprojectionForVolumetrics: 0
enableLightLayers: 0
enableExposureControl: 1
diffuseGlobalDimmer: 0
specularGlobalDimmer: 0
shaderLitMode: 0
enableDepthPrepassWithDeferredRendering: 0
enableTransparentPrepass: 0
enableMotionVectors: 0
enableObjectMotionVectors: 0
enableDecals: 0
enableRoughRefraction: 0
enableTransparentPostpass: 0
enableDistortion: 0
enablePostprocess: 0
enableOpaqueObjects: 0
enableTransparentObjects: 0
enableRealtimePlanarReflection: 0
enableMSAA: 0
enableAsyncCompute: 0
runLightListAsync: 0
runSSRAsync: 0
runSSAOAsync: 0
runContactShadowsAsync: 0
runVolumeVoxelizationAsync: 0
lightLoopSettings:
overrides: 0
enableDeferredTileAndCluster: 0
enableComputeLightEvaluation: 0
enableComputeLightVariants: 0
enableComputeMaterialVariants: 0
enableFptlForForwardOpaque: 0
enableBigTilePrepass: 0
isFptlEnabled: 0
clearColorMode: 0
backgroundColorHDR: {r: 0.025, g: 0.07, b: 0.19, a: 0}
clearDepth: 1
Expand Down Expand Up @@ -4093,6 +4074,53 @@ MonoBehaviour:
data1: 0
data2: 0
defaultFrameSettings: 0
m_Version: 7
m_ObsoleteRenderingPath: 0
m_ObsoleteFrameSettings:
overrides: 0
enableShadow: 0
enableContactShadows: 0
enableShadowMask: 0
enableSSR: 0
enableSSAO: 0
enableSubsurfaceScattering: 0
enableTransmission: 0
enableAtmosphericScattering: 0
enableVolumetrics: 0
enableReprojectionForVolumetrics: 0
enableLightLayers: 0
enableExposureControl: 1
diffuseGlobalDimmer: 0
specularGlobalDimmer: 0
shaderLitMode: 0
enableDepthPrepassWithDeferredRendering: 0
enableTransparentPrepass: 0
enableMotionVectors: 0
enableObjectMotionVectors: 0
enableDecals: 0
enableRoughRefraction: 0
enableTransparentPostpass: 0
enableDistortion: 0
enablePostprocess: 0
enableOpaqueObjects: 0
enableTransparentObjects: 0
enableRealtimePlanarReflection: 0
enableMSAA: 0
enableAsyncCompute: 0
runLightListAsync: 0
runSSRAsync: 0
runSSAOAsync: 0
runContactShadowsAsync: 0
runVolumeVoxelizationAsync: 0
lightLoopSettings:
overrides: 0
enableDeferredTileAndCluster: 0
enableComputeLightEvaluation: 0
enableComputeLightVariants: 0
enableComputeMaterialVariants: 0
enableFptlForForwardOpaque: 0
enableBigTilePrepass: 0
isFptlEnabled: 0
--- !u!81 &2122627085
AudioListener:
m_ObjectHideFlags: 0
Expand Down
5 changes: 5 additions & 0 deletions Assets/AWSIM/Scenes/Main/AutowareSimualtion/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"TimeScale": 0.2,
"RandomTrafficSeed": 33,
"MaxVehicleCount": 2
}
7 changes: 7 additions & 0 deletions Assets/AWSIM/Scenes/Main/AutowareSimualtion/config.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/AWSIM/Scripts/RandomTraffic/TrafficManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AWSIM.TrafficSimulation
public class TrafficManager : MonoBehaviour
{
[SerializeField, Tooltip("Seed value for random generator.")]
private int seed;
public int seed;
[Header("NPC Vehicle Settings")]
[SerializeField] private NPCVehicleConfig vehicleConfig = NPCVehicleConfig.Default();

Expand Down
73 changes: 73 additions & 0 deletions Assets/AWSIM/Scripts/Utilities/CommandLineUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;

namespace AWSIM
{
/// <summary>
/// Convenience static class for command line.
/// </summary>
public static class CommandLineUtility
{
/// <summary>
/// Get instance from Json by specifying Path.
/// </summary>
/// <typeparam name="T">Class to be converted from json.</typeparam>
/// <param name="path">Path where Json is located.</param>
/// <returns></returns>
public static T LoadJsonFromPath<T>(string path)
{
try
{
string rawContent = File.ReadAllText(path);
T content = JsonUtility.FromJson<T>(rawContent);
return content;
}
catch (Exception exceptipn)
{
Debug.LogError(exceptipn.Message);
return default;
}
}

/// <summary>
/// Get the corresponding command line argument.
/// </summary>
/// <param name="param">Parameter</param>
/// <returns></returns>
public static string GetCommandLineArg(string param)
{
var cmdArgs = System.Environment.GetCommandLineArgs();
for (int i = 0; i < cmdArgs.Length; i++)
{
if (cmdArgs[i] == param && cmdArgs.Length > i + 1)
{
return cmdArgs[i + 1];
}
}

return null;
}

/// <summary>
/// Get the corresponding command line argument.
/// </summary>
/// <param name="arg">Argument</param>
/// <param name="param">Parameter</param>
/// <returns></returns>
public static bool GetCommandLineArg(out string arg, string param)
{
var _arg = GetCommandLineArg(param);
if (_arg != null)
{
arg = _arg;
return true;
}

arg = "";
return false;
}
}
}
11 changes: 11 additions & 0 deletions Assets/AWSIM/Scripts/Utilities/CommandLineUtility.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9c00197

Please sign in to comment.