/// <summary> /// Start logging. /// </summary> public static void Start() { if (logging) { Debug.LogWarning("Already logging!"); return; } Debug.Log("Log Started."); string br = Strings.newline + Strings.csvComment; char d = Strings.csvDelimiter; Simulation.Settings info = Simulation.settings; header = Strings.csvComment + Strings.projectTitle + " " + Strings.projectVersion + " - Data Log " + d + DateTime.Now.ToShortDateString() + d + DateTime.Now.ToShortTimeString(); header += br + info.title + d + info.date + " " + info.time; header += br + Strings.csvXmlCommentTag + info.fileName; header += br + "Test number" + d + Simulation.testNumber + d + "of" + d + info.numberOfTests; header += br + "Robot" + d + info.robotName; header += br + "Navigation Assembly" + d + info.navigationAssemblyName; header += br + "Environment" + d + info.environmentName; header += br + "Randomize Origin" + d + info.randomizeOrigin; header += br + "Randomize Destination" + d + info.randomizeDestination; header += br + "Maximum Test Time" + d + info.maximumTestTime; header += br + "Continue on NavObjectiveComplete" + d + info.continueOnNavObjectiveComplete; header += br + "Continue on RobotIsStuck" + d + info.continueOnRobotIsStuck; logging = true; Simulation.Instance.StartCoroutine(LogRoutine()); }
public UI_SimulationBatch() { _settings = new Simulation.Settings(); _editSettings = new UI_SimulationSettings(_settings); _files = new List <string>(); _folders = new List <string>(); _windows = new Stack <GUI.WindowFunction>(); _windows.Push(BatchListWindow); // hide window initially hidden = true; }
/// <summary> /// Browse for XML files to deserialize into Simulation.Settings /// </summary> void XmlBrowser(int windowID) { // back button GUILayout.BeginHorizontal(GUILayout.Width(UI_Toolbar.I.innerWidth)); if (GUILayout.Button("<", GUILayout.Width(30f))) { _windows.Pop(); } // refresh files and folders if (GUILayout.Button("R", GUILayout.Width(30f))) { Refresh(); } GUILayout.EndHorizontal(); // go up one directory if (_subPath != "") { if (GUILayout.Button("..")) { _subPath = Directory.GetParent(_subPath).Name; Refresh(); } } // list subdirectories for (int i = 0; i < _folders.Count; i++) { // enter subdirectory if (GUILayout.Button(_folders[i])) { _subPath += "\\" + new DirectoryInfo(_folders[i]).Name; Refresh(); } } // list files for (int i = 0; i < _files.Count; i++) { // try paths from file if (GUILayout.Button(_files[i])) { string path = currentDir + "\\" + _files[i]; Simulation.Settings settings = ObjectSerializer.DeSerializeObject <Simulation.Settings>(path); if (settings != null) { settings.active = false; Simulation.batch.Add(settings); _windows.Pop(); } } } }
/// <summary> /// Main routine for loading a CSV log file. /// </summary> /// <param name="csvFilePath">Csv file path.</param> static IEnumerator LoadCsvRoutine(string csvFilePath) { loading = true; string csvPath = Path.GetDirectoryName(csvFilePath); string csvFileName = Path.GetFileName(csvFilePath); // try opening the file with StreamReader StreamReader sr; try { sr = new StreamReader(csvFilePath); } catch (Exception e) { // log exception Debug.LogException(e); UI_Toolbar.I.additionalWindows.Add( new UI_Prompt( PromptResponse, UI_Prompt.Type.Close, "File Load Exception!", "See log for details" ) ); // stop loading loading = false; yield break; } // inspect CSV header string line; string header = ""; string xmlFileName = null; while ((line = sr.ReadLine()) != null) { // stop inspecting when comments are no longer found if (!line.StartsWith(Strings.csvComment)) { break; } header += line; // find XML filename stored in CSV if (line.Contains(Strings.csvXmlCommentTag)) { xmlFileName = line.Substring( line.IndexOf(Strings.csvXmlCommentTag) + Strings.csvXmlCommentTag.Length); Debug.Log("XML filename from CSV is: " + xmlFileName); } } // temporary settings object for deserialization Simulation.Settings settings; // if xml filename was not found in csv... if (xmlFileName == null) { settings = new Simulation.Settings(); // prompt user whether to select environment _waitingForResponse = true; UI_Toolbar.I.additionalWindows.Add( new UI_Prompt( PromptResponse, UI_Prompt.Type.YesNo, "XML filename not found in CSV header!", header + "\n Select environment to load?" ) ); while (_waitingForResponse) { yield return(new WaitForSeconds(0.1f)); } if (_response) { /// not yet implemented // browse environments and load selection Debug.Log("Not yet implemented: browse and load environment"); } } else { // try loading environment settings = ObjectSerializer.DeSerializeObject <Simulation.Settings>(csvPath + "\\" + xmlFileName); // if environment is different to the currently loaded environment // prompt user for action (discard other paths, or load new env and paths?) // (not yet implemented) if (environment) { if (environment.name != settings.environmentName) { _waitingForResponse = true; UI_Toolbar.I.additionalWindows.Add( new UI_Prompt( PromptResponse, UI_Prompt.Type.OkCancel, "Load new environment and paths?", "CSV log is for a different environment. Load new environment and paths instead?" ) ); while (_waitingForResponse) { yield return(new WaitForSeconds(0.1f)); } if (_response) { // load environment and clear paths if YES paths.Clear(); CamController.ClearAreaList(); LoadEnvironment(settings.environmentName); } else { // stop loading if NO loading = false; yield break; } } } else { LoadEnvironment(settings.environmentName); } } // load paths from CSV and display them // go to line with SimulationTime as first string while ((line = sr.ReadLine()) != null) { if (line.StartsWith(Log.Parameters.SimulationTime.ToString())) { break; } } // extract headings and store column indexes for path types int robotPositionIndex; string[] row = line.Split(Strings.csvDelimiter); for (robotPositionIndex = 0; robotPositionIndex < row.Length; robotPositionIndex++) { if (row[robotPositionIndex] == Log.Parameters.RobotPosition.ToString()) { break; } } BotPath botpos = new BotPath(); botpos.csvName = csvFileName; // Build BotPath objects for each path type columns found while ((line = sr.ReadLine()) != null) { row = line.Split(Strings.csvDelimiter); if (robotPositionIndex > row.Length) { Debug.LogWarning("LogLoader: row length too short?"); continue; } // try deserializing this vector3 data // (catch parsing errors not yet implemented) Vector3 pos = ParseVector3(row[robotPositionIndex]); // remove " chars from "12.3", for example // (catch parsing errors not yet implemented) float time = float.Parse(row[0].Substring(1, row[0].Length - 2)); botpos.AddNode(pos, time); } AddPath(botpos); UpdatePathColors(); loading = false; }
public UI_SimulationSettings(Simulation.Settings simSettings) { _windows = new Stack <GUI.WindowFunction>(); _windows.Push(SimulationSettingsWindow); _settings = simSettings; }
/// <summary> /// List Simulation.Settings in Simulation.batch and provide controls and editing the Simulation.batch /// </summary> void BatchListWindow(int windowID) { GUILayout.BeginHorizontal(GUILayout.Width(UI_Toolbar.I.innerWidth)); // add a new simulation to batch if (GUILayout.Button("Add new simulation")) { _settings = new Simulation.Settings(); _editSettings = new UI_SimulationSettings(_settings); UI_Toolbar.I.additionalWindows.Add((IWindowFunction)_editSettings); } // load a simulation from xml file if (GUILayout.Button("Add to batch from file...")) { Refresh(); _windows.Push(XmlBrowser); } GUILayout.EndHorizontal(); // Batch list GUILayout.Label("Currently in batch:"); if (Simulation.batch.Count < 1) { GUILayout.Label("None"); } for (int i = 0; i < Simulation.batch.Count; i++) { Simulation.Settings batchItem = Simulation.batch[i]; // batch list table row by row GUILayout.BeginHorizontal(GUILayout.Width(UI_Toolbar.I.innerWidth)); // display batch position if (i + 1 == Simulation.simulationNumber) { GUILayout.Label("->"); } // label string label = i + 1 + ". " + batchItem.title + ", " + batchItem.time; if (batchItem.active) { label += ", RUNNING"; } GUILayout.Label(label); // edit these settings if (GUILayout.Button("Edit")) { _settings = batchItem; _editSettings = new UI_SimulationSettings(_settings); UI_Toolbar.I.additionalWindows.Add((IWindowFunction)_editSettings); } if (GUILayout.Button("X")) { Simulation.batch.RemoveAt(i); } // indicate which have been executed already // if (batchItem.executed) GUILayout.EndHorizontal(); } GUILayout.Space(10); // start simulating if (Simulation.batch.Count > 0) { if (GUILayout.Button("Start Batch")) { BotNavSim.state = BotNavSim.State.Simulating; Simulation.Begin(); } GUILayout.Space(20); // remove all simulations from batch GUILayout.Space(20); if (GUILayout.Button("Clear Batch")) { Simulation.batch.Clear(); } } }