BotNavSim  v0.4.3
Mobile Robot Simulation
Log Class Reference

Provides data logging capabilities. Data is logged in CSV format. More...

Public Types

enum  Parameters {
  Parameters.SimulationTime, Parameters.SimulationTimeScale, Parameters.RobotPosition, Parameters.RobotIsStuck,
  Parameters.DestinationPosition, Parameters.NavigationPathFound, Parameters.NavigationMoveDirection
}
 

Static Public Member Functions

static void LogParameter (Parameters parameter, bool log)
 Moves parameters between availableParams and selectedParams lists. More...
 
static void Start ()
 Start logging. More...
 
static void Settings ()
 Serialize the current simulation settings and write to XML file. More...
 
static void Stop (Simulation.StopCode stopcode)
 Stop logging with Simulation.Stopcode and write log to CSV file. More...
 

Static Public Attributes

static float timeStep = 0.05f
 The time between log entries in seconds. More...
 
static List< ParametersavailableParams = new List<Parameters>()
 List of parameters that haven't been selected for logging. More...
 
static List< ParametersselectedParams = new List<Parameters>()
 List of parameters selected for logging. More...
 

Properties

static bool logging [get, private set]
 Gets a value indicating whether this Log is logging. More...
 

Static Private Member Functions

static Log ()
 
static IEnumerator LogRoutine ()
 logging routine More...
 
static string GetData (Parameters parameter)
 Gets the data for a specified parameter More...
 

Static Private Attributes

static string header
 metadata to write to the top of the CSV file More...
 
static Queue< string > log = new Queue<string>()
 FIFO timeframe data buffer to be written to file More...
 

Detailed Description

Provides data logging capabilities. Data is logged in CSV format.

Definition at line 10 of file Log.cs.

Member Enumeration Documentation

Enumerator
SimulationTime 

The simulation time (float).

SimulationTimeScale 

The simulation time scale (float).

RobotPosition 

The robot current position (Vector3).

RobotIsStuck 

Indication of robot stuck detection as percentage (0 to 100).

DestinationPosition 

The destination position (Vector3).

NavigationPathFound 

Bool output from INavigation.pathFound

NavigationMoveDirection 

Vector3 output from INavigation.PathDirection

Definition at line 13 of file Log.cs.

13  {
42  }
Indication of robot stuck detection as percentage (0 to 100).
The simulation time (float).
Vector3 output from INavigation.PathDirection
The destination position (Vector3).
Bool output from INavigation.pathFound
The robot current position (Vector3).
The simulation time scale (float).

Constructor & Destructor Documentation

static Log.Log ( )
staticprivate

Definition at line 79 of file Log.cs.

79  {
80  foreach(Parameters p in (Parameters[])Enum.GetValues(typeof(Parameters))) {
81  availableParams.Add(p);
82  }
83  // parameters logged by default
84  LogParameter(Parameters.SimulationTime, true);
85  LogParameter(Parameters.RobotPosition, true);
86  LogParameter(Parameters.NavigationMoveDirection, true);
87  LogParameter(Parameters.DestinationPosition, true);
88  }
static void LogParameter(Parameters parameter, bool log)
Moves parameters between availableParams and selectedParams lists.
Definition: Log.cs:95
static List< Parameters > availableParams
List of parameters that haven't been selected for logging.
Definition: Log.cs:52
Parameters
Definition: Log.cs:13

Here is the call graph for this function:

Member Function Documentation

static string Log.GetData ( Parameters  parameter)
staticprivate

Gets the data for a specified parameter

Returns
The data.
Parameters
parameterParameter.

Definition at line 209 of file Log.cs.

209  {
210  switch (parameter) {
211  case Parameters.SimulationTime:
212  return Simulation.time.ToString();
213  case Parameters.SimulationTimeScale:
214  return Simulation.timeScale.ToString();
215  case Parameters.RobotPosition:
216  return Simulation.robot.rigidbody.worldCenterOfMass.ToString("F2");
217  case Parameters.RobotIsStuck:
218  return Simulation.robot.stuckpc.ToString();
219  case Parameters.DestinationPosition:
220  return Simulation.destination.transform.position.ToString("F2");
221  case Parameters.NavigationPathFound:
222  return Simulation.robot.navigation.pathFound.ToString();
223  case Parameters.NavigationMoveDirection:
224  return Simulation.robot.navigationCommand.ToString("F2");
225  }
226  return null;
227  }
Vector3 navigationCommand
The cached navigation bearing from INavigation.
Definition: Robot.cs:89
static float timeScale
Gets or sets the time scale.
Definition: Simulation.cs:376
static Robot robot
Gets reference to the robot in the current simulation.
Definition: Simulation.cs:273
static GameObject destination
Gets reference to the destination.
Definition: Simulation.cs:302
Parameters
Definition: Log.cs:13
INavigation navigation
Interface to the navigation assembly.
Definition: Robot.cs:67
bool pathFound
Gets a value indicating whether this INavigation found a path between origin and destination.
Definition: INavigation.cs:49
int stuckpc
Definition: Robot.cs:152
This is a manager class used to overlook the running of a simulation.
Definition: Simulation.cs:8
static float time
Time (in seconds) since robot started searching for destination.
Definition: Simulation.cs:366

Here is the caller graph for this function:

static void Log.LogParameter ( Parameters  parameter,
bool  log 
)
static

Moves parameters between availableParams and selectedParams lists.

Parameters
parameterParameter.
logIf set to true parameter is added to selectedParams for logging.

Definition at line 95 of file Log.cs.

95  {
96  if (log) {
97  if (!availableParams.Contains(parameter)) {
98  Debug.LogWarning("Attempted to log unavailable parameter.");
99  return;
100  }
101  availableParams.Remove(parameter);
102  if (selectedParams.Contains(parameter)) {
103  Debug.LogWarning("Attempted to log parameter twice.");
104  return;
105  }
106  selectedParams.Add(parameter);
107  }
108  else {
109  selectedParams.Remove(parameter);
110  availableParams.Add(parameter);
111  }
112  }
static List< Parameters > availableParams
List of parameters that haven't been selected for logging.
Definition: Log.cs:52
static List< Parameters > selectedParams
List of parameters selected for logging.
Definition: Log.cs:57
static Queue< string > log
FIFO timeframe data buffer to be written to file
Definition: Log.cs:76

Here is the caller graph for this function:

static IEnumerator Log.LogRoutine ( )
staticprivate

logging routine

Definition at line 188 of file Log.cs.

188  {
189  string headings = "";
190  foreach(Parameters p in selectedParams) {
191  headings += p.ToString() + Strings.csvDelimiter;
192  }
193  log.Enqueue(headings);
194  while (logging) {
195  string line = "";
196  foreach(Parameters p in selectedParams) {
197  line += "\"" + GetData(p) + "\"" + Strings.csvDelimiter;
198  }
199  log.Enqueue(line);
200  yield return new WaitForSeconds(timeStep);
201  }
202  }
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
static float timeStep
The time between log entries in seconds.
Definition: Log.cs:47
static bool logging
Gets a value indicating whether this Log is logging.
Definition: Log.cs:64
A utility class for strings used in this project.
Definition: Strings.cs:9
static string GetData(Parameters parameter)
Gets the data for a specified parameter
Definition: Log.cs:209
static List< Parameters > selectedParams
List of parameters selected for logging.
Definition: Log.cs:57
static Queue< string > log
FIFO timeframe data buffer to be written to file
Definition: Log.cs:76

Here is the call graph for this function:

Here is the caller graph for this function:

static void Log.Settings ( )
static

Serialize the current simulation settings and write to XML file.

Definition at line 146 of file Log.cs.

146  {
147  string path = Strings.logFileDirectory;
148  path += "\\" + System.DateTime.Now.ToString("yyyy_MM_dd");
149  if (!System.IO.Directory.Exists(path)) {
150  System.IO.Directory.CreateDirectory(path);
151  }
152  path += "\\" + Simulation.settings.fileName;
153  Debug.Log("Settings saved at " + path);
154  ObjectSerializer.SerializeObject(Simulation.settings, path);
155  }
static string logFileDirectory
Gets the log file directory.
Definition: Strings.cs:52
static Settings settings
Gets or sets the settings for the current simulation.
Definition: Simulation.cs:241
This is a manager class used to overlook the running of a simulation.
Definition: Simulation.cs:8
A utility class for strings used in this project.
Definition: Strings.cs:9
Object serializer utility class.

Here is the caller graph for this function:

static void Log.Start ( )
static

Start logging.

Definition at line 117 of file Log.cs.

117  {
118  if (logging) {
119  Debug.LogWarning("Already logging!");
120  return;
121  }
122  Debug.Log("Log Started.");
123  string br = Strings.newline + Strings.csvComment;
124  char d = Strings.csvDelimiter;
126  header = Strings.csvComment + Strings.projectTitle + " " + Strings.projectVersion + " - Data Log " + d +
127  DateTime.Now.ToShortDateString() + d + DateTime.Now.ToShortTimeString();
128  header += br + info.title + d + info.date + " " + info.time;
129  header += br + Strings.csvXmlCommentTag + info.fileName;
130  header += br + "Test number" + d + Simulation.testNumber + d + "of" + d + info.numberOfTests;
131  header += br + "Robot" + d + info.robotName;
132  header += br + "Navigation Assembly" + d + info.navigationAssemblyName;
133  header += br + "Environment" + d + info.environmentName;
134  header += br + "Randomize Origin" + d + info.randomizeOrigin;
135  header += br + "Randomize Destination" + d + info.randomizeDestination;
136  header += br + "Maximum Test Time" + d + info.maximumTestTime;
137  header += br + "Continue on NavObjectiveComplete" + d + info.continueOnNavObjectiveComplete;
138  header += br + "Continue on RobotIsStuck" + d + info.continueOnRobotIsStuck;
139  logging = true;
140  Simulation.Instance.StartCoroutine(LogRoutine());
141  }
const string projectTitle
The project title.
Definition: Strings.cs:14
const string csvXmlCommentTag
The csv xml comment tag identifies which line the associated XML settings file name is stored...
Definition: Strings.cs:46
static Simulation Instance
Reference to the MonoBebehaviour instance
Definition: Simulation.cs:222
static string header
metadata to write to the top of the CSV file
Definition: Log.cs:71
static Settings settings
Gets or sets the settings for the current simulation.
Definition: Simulation.cs:241
const string projectVersion
The project version.
Definition: Strings.cs:19
const char csvDelimiter
The csv delimiter character. Avoid using comma because some data is serialized to include commas...
Definition: Strings.cs:35
static IEnumerator LogRoutine()
logging routine
Definition: Log.cs:188
static int testNumber
Gets the current test number (1 to settings.numberOfTests).
Definition: Simulation.cs:266
static string newline
Gets the newline.
Definition: Strings.cs:97
This is a manager class used to overlook the running of a simulation.
Definition: Simulation.cs:8
static bool logging
Gets a value indicating whether this Log is logging.
Definition: Log.cs:64
const string csvComment
The csv comment character denotes lines which are not CSV data.
Definition: Strings.cs:40
A utility class for strings used in this project.
Definition: Strings.cs:9

Here is the call graph for this function:

Here is the caller graph for this function:

static void Log.Stop ( Simulation.StopCode  stopcode)
static

Stop logging with Simulation.Stopcode and write log to CSV file.

Parameters
stopcodeStopcode.

Definition at line 161 of file Log.cs.

161  {
162  if (logging) {
163  logging = false;
164  string path = Strings.logFileDirectory;
165  path += "\\" + System.DateTime.Now.ToString("yyyy_MM_dd");
166  if (!Directory.Exists(path)) {
167  Directory.CreateDirectory(path);
168  }
169  path += "\\" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss_");
171  path += ".csv";
173  header += Strings.csvDelimiter + "and stopped with" + Strings.csvDelimiter + stopcode.ToString() + Strings.newline;
174  string data = header + Strings.newline;
175  while(log.Count > 0) {
176  data += log.Dequeue() + Strings.newline;
177  }
178  File.WriteAllText(path, data);
179  Debug.Log("Log created at: " + path);
180  }
181 
182  log.Clear();
183  }
static string logFileDirectory
Gets the log file directory.
Definition: Strings.cs:52
static string header
metadata to write to the top of the CSV file
Definition: Log.cs:71
static Settings settings
Gets or sets the settings for the current simulation.
Definition: Simulation.cs:241
const char csvDelimiter
The csv delimiter character. Avoid using comma because some data is serialized to include commas...
Definition: Strings.cs:35
string title
The title of this simulation.
Definition: Simulation.cs:73
static int testNumber
Gets the current test number (1 to settings.numberOfTests).
Definition: Simulation.cs:266
static string newline
Gets the newline.
Definition: Strings.cs:97
This is a manager class used to overlook the running of a simulation.
Definition: Simulation.cs:8
static bool logging
Gets a value indicating whether this Log is logging.
Definition: Log.cs:64
const string csvComment
The csv comment character denotes lines which are not CSV data.
Definition: Strings.cs:40
A utility class for strings used in this project.
Definition: Strings.cs:9
static float time
Time (in seconds) since robot started searching for destination.
Definition: Simulation.cs:366
static Queue< string > log
FIFO timeframe data buffer to be written to file
Definition: Log.cs:76

Here is the caller graph for this function:

Member Data Documentation

List<Parameters> Log.availableParams = new List<Parameters>()
static

List of parameters that haven't been selected for logging.

Definition at line 52 of file Log.cs.

string Log.header
staticprivate

metadata to write to the top of the CSV file

Definition at line 71 of file Log.cs.

Queue<string> Log.log = new Queue<string>()
staticprivate

FIFO timeframe data buffer to be written to file

Definition at line 76 of file Log.cs.

List<Parameters> Log.selectedParams = new List<Parameters>()
static

List of parameters selected for logging.

Definition at line 57 of file Log.cs.

float Log.timeStep = 0.05f
static

The time between log entries in seconds.

Definition at line 47 of file Log.cs.

Property Documentation

bool Log.logging
staticgetprivate set

Gets a value indicating whether this Log is logging.

true if logging; otherwise, false.

Definition at line 64 of file Log.cs.


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