BotNavSim  v0.4.3
Mobile Robot Simulation
LogLoader Class Reference

Log loader high level BotNavSim state manager More...

Inheritance diagram for LogLoader:
Collaboration diagram for LogLoader:

Static Public Member Functions

static void Enter ()
 Enter this BotNavSim state: setup camera views More...
 
static void Exit ()
 Exit BotNavSim.state behaviour: remove environment, clear paths More...
 
static void LoadPaths (string csvFilePath)
 Loads the paths stored in a CSV file. Also attempts to load the relevant environment. More...
 
static void AddPath (BotPath path)
 Adds a path to paths list. More...
 
static void RemovePath (BotPath path)
 Removes the path. More...
 
static void UpdatePathColors ()
 Updates the path colors with evenly spaced hues. More...
 

Static Public Attributes

static LogLoader Instance
 Reference to MonoBehaviour instance. More...
 

Properties

static List< BotPathpaths [get, private set]
 The BotPaths loaded from file. More...
 
static bool loading [get, private set]
 Gets a value indicating whether this LogLoader is loading from CSV. More...
 
static GameObject environment [get, private set]
 Gets the environment game object. More...
 
Bounds bounds [get, private set]
 Gets the environment bounds. More...
 
- Properties inherited from IObservable
string name [get]
 Gets the name of the observable object More...
 
Bounds bounds [get]
 Gets the bounds of the observable object (size and location) More...
 

Private Member Functions

void Awake ()
 Awake this instance. More...
 
void OnGUI ()
 Raises the GUI event. More...
 
void OnDrawGizmos ()
 Raises the draw gizmos event. More...
 

Static Private Member Functions

static LogLoader ()
 
static void PromptResponse (bool response)
 UI_Prompt.Response callback function More...
 
static IEnumerator LoadCsvRoutine (string csvFilePath)
 Main routine for loading a CSV log file. More...
 
static void LoadEnvironment (string name)
 Loads the environment. More...
 
static Vector3 ParseVector3 (string strv)
 Parses the vector3 object from a string like "(1.0,2.0,3.0)" More...
 

Static Private Attributes

static bool _waitingForResponse
 Bool indicating whether waiting for user response to prompt More...
 
static bool _response
 The UI_Prompt response from the user. More...
 

Detailed Description

Log loader high level BotNavSim state manager

Definition at line 10 of file LogLoader.cs.

Constructor & Destructor Documentation

static LogLoader.LogLoader ( )
staticprivate

Definition at line 18 of file LogLoader.cs.

18  {
19  paths = new List<BotPath>();
20  }
static List< BotPath > paths
The BotPaths loaded from file.
Definition: LogLoader.cs:25

Member Function Documentation

static void LogLoader.AddPath ( BotPath  path)
static

Adds a path to paths list.

Parameters
pathPath.

Definition at line 263 of file LogLoader.cs.

263  {
264  if (!paths.Contains(path)) paths.Add(path);
266  }
static void AddAreaOfInterest(IObservable area)
Adds an area of interest to the list of areas for the camera to observe.
static List< BotPath > paths
The BotPaths loaded from file.
Definition: LogLoader.cs:25
Controls the camera orientation and render modes according to ViewMode in viewModeList user input...

Here is the call graph for this function:

Here is the caller graph for this function:

void LogLoader.Awake ( )
private

Awake this instance.

Instance Methods

Definition at line 325 of file LogLoader.cs.

325  {
326  if (Instance == null) {
327  Instance = this;
328  } else {
329  Destroy(this);
330  }
331  }
static LogLoader Instance
Reference to MonoBehaviour instance.
Definition: LogLoader.cs:15
static void LogLoader.Enter ( )
static

Enter this BotNavSim state: setup camera views

Definition at line 64 of file LogLoader.cs.

64  {
68  }
static void AddViewMode(ViewMode mode)
Adds a ViewMode to viewModeList.
static LogLoader Instance
Reference to MonoBehaviour instance.
Definition: LogLoader.cs:15
static void AddAreaOfInterest(IObservable area)
Adds an area of interest to the list of areas for the camera to observe.
Controls the camera orientation and render modes according to ViewMode in viewModeList user input...

Here is the call graph for this function:

Here is the caller graph for this function:

static void LogLoader.Exit ( )
static

Exit BotNavSim.state behaviour: remove environment, clear paths

Definition at line 73 of file LogLoader.cs.

73  {
76  environment.transform.Recycle();
77  paths.Clear();
78  }
static List< BotPath > paths
The BotPaths loaded from file.
Definition: LogLoader.cs:25
Controls the camera orientation and render modes according to ViewMode in viewModeList user input...
static GameObject environment
Gets the environment game object.
Definition: LogLoader.cs:40
static void ClearViewModeList()
Clears the view mode list.
static void ClearAreaList()
Clears the area list.

Here is the call graph for this function:

Here is the caller graph for this function:

static IEnumerator LogLoader.LoadCsvRoutine ( string  csvFilePath)
staticprivate

Main routine for loading a CSV log file.

Parameters
csvFilePathCsv file path.

not yet implemented

Definition at line 106 of file LogLoader.cs.

106  {
107  loading = true;
108 
109  string csvPath = Path.GetDirectoryName(csvFilePath);
110  string csvFileName = Path.GetFileName(csvFilePath);
111 
112  // try opening the file with StreamReader
113  StreamReader sr;
114  try {
115  sr = new StreamReader(csvFilePath);
116  }
117  catch (Exception e) {
118  // log exception
119  Debug.LogException(e);
121  new UI_Prompt(
123  UI_Prompt.Type.Close,
124  "File Load Exception!",
125  "See log for details"
126  )
127  );
128  // stop loading
129  loading = false;
130  yield break;
131  }
132 
133  // inspect CSV header
134  string line;
135  string header = "";
136  string xmlFileName = null;
137  while ((line = sr.ReadLine()) != null) {
138  // stop inspecting when comments are no longer found
139  if (!line.StartsWith(Strings.csvComment)) {
140  break;
141  }
142  header += line;
143  // find XML filename stored in CSV
144  if (line.Contains(Strings.csvXmlCommentTag)) {
145  xmlFileName = line.Substring(
146  line.IndexOf(Strings.csvXmlCommentTag) +
147  Strings.csvXmlCommentTag.Length);
148  Debug.Log("XML filename from CSV is: " + xmlFileName);
149  }
150  }
151 
152  // temporary settings object for deserialization
153  Simulation.Settings settings;
154 
155 
156  // if xml filename was not found in csv...
157  if (xmlFileName == null) {
158  settings = new Simulation.Settings();
159  // prompt user whether to select environment
160  _waitingForResponse = true;
162  new UI_Prompt(
164  UI_Prompt.Type.YesNo,
165  "XML filename not found in CSV header!",
166  header + "\n Select environment to load?"
167  )
168  );
169  while (_waitingForResponse) {
170  yield return new WaitForSeconds(0.1f);
171  }
172  if (_response) {
174  // browse environments and load selection
175  Debug.Log("Not yet implemented: browse and load environment");
176  }
177  }
178  else {
179  // try loading environment
180  settings = ObjectSerializer.DeSerializeObject<Simulation.Settings>(csvPath + "\\" + xmlFileName);
181  // if environment is different to the currently loaded environment
182  // prompt user for action (discard other paths, or load new env and paths?)
183  // (not yet implemented)
184  if (environment) {
185  if (environment.name != settings.environmentName) {
186  _waitingForResponse = true;
188  new UI_Prompt(
190  UI_Prompt.Type.OkCancel,
191  "Load new environment and paths?",
192  "CSV log is for a different environment. Load new environment and paths instead?"
193  )
194  );
195  while (_waitingForResponse) {
196  yield return new WaitForSeconds(0.1f);
197  }
198  if (_response) {
199  // load environment and clear paths if YES
200  paths.Clear();
202  LoadEnvironment(settings.environmentName);
203  }
204  else {
205  // stop loading if NO
206  loading = false;
207  yield break;
208  }
209  }
210  }
211  else {
212  LoadEnvironment(settings.environmentName);
213  }
214  }
215 
216  // load paths from CSV and display them
217 
218  // go to line with SimulationTime as first string
219  while ((line = sr.ReadLine()) != null) {
220  if (line.StartsWith(Log.Parameters.SimulationTime.ToString())) {
221  break;
222  }
223  }
224 
225  // extract headings and store column indexes for path types
226  int robotPositionIndex;
227  string[] row = line.Split(Strings.csvDelimiter);
228  for(robotPositionIndex = 0; robotPositionIndex < row.Length; robotPositionIndex++) {
229  if (row[robotPositionIndex] == Log.Parameters.RobotPosition.ToString())
230  break;
231  }
232 
233 
234  BotPath botpos = new BotPath();
235  botpos.csvName = csvFileName;
236 
237  // Build BotPath objects for each path type columns found
238  while((line = sr.ReadLine()) != null) {
239  row = line.Split(Strings.csvDelimiter);
240  if (robotPositionIndex > row.Length) {
241  Debug.LogWarning("LogLoader: row length too short?");
242  continue;
243  }
244  // try deserializing this vector3 data
245  // (catch parsing errors not yet implemented)
246  Vector3 pos = ParseVector3(row[robotPositionIndex]);
247  // remove " chars from "12.3", for example
248  // (catch parsing errors not yet implemented)
249  float time = float.Parse(row[0].Substring(1,row[0].Length-2));
250  botpos.AddNode(pos, time);
251  }
252 
253 
254  AddPath(botpos);
256  loading = false;
257  }
BotPath displays information about a recorded path taken or calculated.
Definition: BotPath.cs:9
string csvName
Gets or sets the name of the csv.
Definition: BotPath.cs:34
static bool loading
Gets a value indicating whether this LogLoader is loading from CSV.
Definition: LogLoader.cs:33
const string csvXmlCommentTag
The csv xml comment tag identifies which line the associated XML settings file name is stored...
Definition: Strings.cs:46
static UI_Toolbar I
Singleton pattern.
Definition: UI_Toolbar.cs:16
static Vector3 ParseVector3(string strv)
Parses the vector3 object from a string like "(1.0,2.0,3.0)"
Definition: LogLoader.cs:311
const char csvDelimiter
The csv delimiter character. Avoid using comma because some data is serialized to include commas...
Definition: Strings.cs:35
Parameters
Definition: Log.cs:13
UI Toolbar provides controls for choosing which UI windows to display
Definition: UI_Toolbar.cs:11
static void AddPath(BotPath path)
Adds a path to paths list.
Definition: LogLoader.cs:263
static List< BotPath > paths
The BotPaths loaded from file.
Definition: LogLoader.cs:25
static void LoadEnvironment(string name)
Loads the environment.
Definition: LogLoader.cs:293
Controls the camera orientation and render modes according to ViewMode in viewModeList user input...
void AddNode(Vector3 node, float time)
Adds a node to the path.
Definition: BotPath.cs:81
This is a manager class used to overlook the running of a simulation.
Definition: Simulation.cs:8
const string csvComment
The csv comment character denotes lines which are not CSV data.
Definition: Strings.cs:40
List< IWindowFunction > additionalWindows
The additional windows to be drawn outside the toolbar. used for classes like UI_SimulationSettings ...
Definition: UI_Toolbar.cs:27
A utility class for strings used in this project.
Definition: Strings.cs:9
static bool _waitingForResponse
Bool indicating whether waiting for user response to prompt
Definition: LogLoader.cs:54
Provides data logging capabilities. Data is logged in CSV format.
Definition: Log.cs:10
static void UpdatePathColors()
Updates the path colors with evenly spaced hues.
Definition: LogLoader.cs:280
Object serializer utility class.
static GameObject environment
Gets the environment game object.
Definition: LogLoader.cs:40
static bool _response
The UI_Prompt response from the user.
Definition: LogLoader.cs:59
static void PromptResponse(bool response)
UI_Prompt.Response callback function
Definition: LogLoader.cs:97
IWindowFunction class that prompts the user for action.
Definition: UI_Prompt.cs:8
static void ClearAreaList()
Clears the area list.

Here is the call graph for this function:

Here is the caller graph for this function:

static void LogLoader.LoadEnvironment ( string  name)
staticprivate

Loads the environment.

Parameters
nameName.

Definition at line 293 of file LogLoader.cs.

293  {
295  if (environment) environment.transform.Recycle();
297  environment.name = name; // avoids: Unity appending "(Clone)" to instance names
298  Debug.Log(environment);
299  Bounds b = new Bounds();
300  foreach(Renderer r in environment.GetComponentsInChildren<Renderer>())
301  b.Encapsulate(r.bounds);
302  Instance.bounds = b;
304  }
string name
Gets the name of the observable object
Definition: IObservable.cs:12
static LogLoader Instance
Reference to MonoBehaviour instance.
Definition: LogLoader.cs:15
Environment loader searches for and loads environment GameObjects from the Unity Resources folder...
Definition: EnvLoader.cs:9
static GameObject LoadEnvironment(string name)
Loads the environment.
Definition: EnvLoader.cs:29
static void SetViewMode(ViewMode mode)
Sets the view mode.
Controls the camera orientation and render modes according to ViewMode in viewModeList user input...
Bounds bounds
Gets the environment bounds.
Definition: LogLoader.cs:47
static void SearchForEnvironments()
Searchs for environments.
Definition: EnvLoader.cs:16
static GameObject environment
Gets the environment game object.
Definition: LogLoader.cs:40

Here is the call graph for this function:

Here is the caller graph for this function:

static void LogLoader.LoadPaths ( string  csvFilePath)
static

Loads the paths stored in a CSV file. Also attempts to load the relevant environment.

Returns
List of paths found in CSV file.
Parameters
csvFilePathPath to CSV file.

Definition at line 86 of file LogLoader.cs.

86  {
87 
88  Instance.StartCoroutine( LoadCsvRoutine(csvFilePath) );
89 
90 
91  }
static LogLoader Instance
Reference to MonoBehaviour instance.
Definition: LogLoader.cs:15
static IEnumerator LoadCsvRoutine(string csvFilePath)
Main routine for loading a CSV log file.
Definition: LogLoader.cs:106

Here is the call graph for this function:

Here is the caller graph for this function:

void LogLoader.OnDrawGizmos ( )
private

Raises the draw gizmos event.

Definition at line 346 of file LogLoader.cs.

346  {
347  foreach(BotPath p in paths) {
348  if (p.visible) {
349  Gizmos.color = p.color;
350  Gizmos.DrawCube(p.bounds.center, p.bounds.size);
351  Gizmos.DrawLine(p.start, p.end);
352  }
353  }
354  }
BotPath displays information about a recorded path taken or calculated.
Definition: BotPath.cs:9
Bounds bounds
Definition: BotPath.cs:59
Vector3 end
Gets the end of the path.
Definition: BotPath.cs:53
Vector3 start
Gets the start of the path.
Definition: BotPath.cs:44
Color color
Gets or sets the color used in drawing the path via Draw.
Definition: BotPath.cs:70
static List< BotPath > paths
The BotPaths loaded from file.
Definition: LogLoader.cs:25
bool visible
Gets or sets a value indicating whether this BotPath is visible.
Definition: BotPath.cs:22
void LogLoader.OnGUI ( )
private

Raises the GUI event.

Definition at line 336 of file LogLoader.cs.

336  {
337  // draw path lines
338  foreach(BotPath p in paths) {
339  if (p.visible) p.DrawPath();
340  }
341  }
BotPath displays information about a recorded path taken or calculated.
Definition: BotPath.cs:9
static List< BotPath > paths
The BotPaths loaded from file.
Definition: LogLoader.cs:25
bool visible
Gets or sets a value indicating whether this BotPath is visible.
Definition: BotPath.cs:22
void DrawPath()
Draws the path on screen using Draw class
Definition: BotPath.cs:101

Here is the call graph for this function:

static Vector3 LogLoader.ParseVector3 ( string  strv)
staticprivate

Parses the vector3 object from a string like "(1.0,2.0,3.0)"

Returns
The vector3.
Parameters
strvVector3 string i.e. "(1.0,2.0,3.0)".

Definition at line 311 of file LogLoader.cs.

311  {
312  // remove " and bracket chars then split by commas
313  string[] split = strv.Substring(2,strv.Length-4).Split(',');
314  float x = float.Parse(split[0]);
315  float y = float.Parse(split[1]);
316  float z = float.Parse(split[2]);
317  return new Vector3(x, y, z);
318  }

Here is the caller graph for this function:

static void LogLoader.PromptResponse ( bool  response)
staticprivate

UI_Prompt.Response callback function

Parameters
responseIf set to true response.

Definition at line 97 of file LogLoader.cs.

97  {
98  _waitingForResponse = false;
99  _response = response;
100  }
static bool _waitingForResponse
Bool indicating whether waiting for user response to prompt
Definition: LogLoader.cs:54
static bool _response
The UI_Prompt response from the user.
Definition: LogLoader.cs:59

Here is the caller graph for this function:

static void LogLoader.RemovePath ( BotPath  path)
static

Removes the path.

Parameters
pathPath.

Definition at line 272 of file LogLoader.cs.

272  {
273  paths.Remove(path);
275  }
static List< BotPath > paths
The BotPaths loaded from file.
Definition: LogLoader.cs:25
Controls the camera orientation and render modes according to ViewMode in viewModeList user input...
static void RemoveAreaOfInterest(IObservable area)
Removes an area of interest from the list of areas for the camera to observe.

Here is the call graph for this function:

Here is the caller graph for this function:

static void LogLoader.UpdatePathColors ( )
static

Updates the path colors with evenly spaced hues.

Definition at line 280 of file LogLoader.cs.

280  {
281  float d = 1f/(float)paths.Count;
282  for(int i = 0; i < paths.Count; i++) {
283  float h = i*d;
284  Color c = HSBColor.ToColor(new HSBColor(h,1f,1f));
285  paths[i].color = c;
286  }
287  }
static Color ToColor(HSBColor hsbColor)
Definition: HSBColor.cs:93
static List< BotPath > paths
The BotPaths loaded from file.
Definition: LogLoader.cs:25
Utility struct for transforming RGB Color to HSB Color (sourced from a previous project) ...
Definition: HSBColor.cs:8

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool LogLoader._response
staticprivate

The UI_Prompt response from the user.

Definition at line 59 of file LogLoader.cs.

bool LogLoader._waitingForResponse
staticprivate

Bool indicating whether waiting for user response to prompt

Definition at line 54 of file LogLoader.cs.

LogLoader LogLoader.Instance
static

Reference to MonoBehaviour instance.

Definition at line 15 of file LogLoader.cs.

Property Documentation

Bounds LogLoader.bounds
getprivate set

Gets the environment bounds.

Definition at line 47 of file LogLoader.cs.

GameObject LogLoader.environment
staticgetprivate set

Gets the environment game object.

Definition at line 40 of file LogLoader.cs.

bool LogLoader.loading
staticgetprivate set

Gets a value indicating whether this LogLoader is loading from CSV.

true if loading; otherwise, false.

Definition at line 33 of file LogLoader.cs.

List<BotPath> LogLoader.paths
staticgetprivate set

The BotPaths loaded from file.

Definition at line 25 of file LogLoader.cs.


The documentation for this class was generated from the following file: