Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. ========================================================================
  2. 2E3 CONSOLE APPLICATION : Road condition data sourcing
  3. ========================================================================
  4.  
  5. Compile information:
  6. Program was compiled in Windows 10 using the VS2015 toolset (v140).
  7. Compatibility was also checked using the VS2012 toolset (v110) to ensure functionality
  8. accross different versions.
  9. An executable compiled with the v110 toolset is also included in the event that the new
  10. toolset is not installed on the target computer
  11.  
  12. General usage
  13. When running, you are requested to enter a time step and threshold value.
  14. After this, the data begins to be collected and printed to the screen.
  15. After the EOF has been reached, a new list of the values over the threshold
  16. are printed in descending order, as well as the average acceleration.
  17. At any time during the collection process (i.e. after the paramter requests)
  18. you can stop gathering data and print out the descending list and average
  19. by pressing the 's' key (as in stop), or you can quit by pressing the
  20. 'x' key (as in x-it)
  21.  
  22. Raw data acquisition
  23. The data acquisition is simulated in the GPS and Sensor classes. Both have a
  24. instance of the FileReader class in order to obtain the actual data.
  25. When the sensor classes are created, they open a filestream to the supplied
  26. path of the data, which is kept open until the EOF is reached. When the
  27. getLocation() or readAcceleration() functions are called, they return the
  28. next set of data in the respective files (Rather than reading all data
  29. into a list at once at the start of the program).
  30. Every time data is requested from the FileReader class, it checks itself
  31. for an EOF condition, and if true, closes the filestream.
  32. The classes were made with the intention of being indiscernable to the
  33. wider program of not being an actual GPS coordinate. As such, in order
  34. to advance the program into using an actual GPS or accelerometer device,
  35. only these classes would have to be modified, leaving the main code intact.
  36.  
  37. Timed data requests
  38. At the start of the program, the user is requested to enter a time step, after
  39. which data is retrieved and printed to the screen continously with the
  40. required pause between. This is done by spawning a data retrieval thread which
  41. runs concurrently with the main program thread and loops continously while data
  42. is to be retrieved. At the start of the loop, the "starting time" is recorded. Data
  43. is then acquired, added to a holding object, added to a list etc. At the end of the
  44. loop, the "ending time" is recorded, and the time spent during that iteration is
  45. calculated. The thread then sleeps for the required time (timestep - time doing)
  46. before repeating for the next set of data.
  47.  
  48. Use of data
  49. The GPS data is stored as an instance of the Coordinate class which contains two
  50. floats as the latitude and longitude values. The acceleration data is stored as
  51. a Vector3 from the Vector class whcih contains 3 floats for (x, y, z), as well as
  52. some operator overloads. The Coordinate and Acceleration data at a particular point
  53. in time is stored as a collectiveData instance, which contains a Coordinate instance,
  54. a Vector3 instance and the time the data was acquired (relative to the start of the program)
  55. The collectiveData class also contains a pointer to an object of the same class as it is
  56. to be used in a linked list.
  57.  
  58. Lists
  59. 2 singly linked lists are used in this program. One contains all data in the order
  60. it was acquired, while the other contains only the data over the requested threshold
  61. in descending order. Both contain individual copies of the collectiveData instances
  62. as there would be an issue with sharing "next" pointers should the same instances
  63. be used. The lists are instantiated with the CustomList class, which contains
  64. add() and add_in_place() functions to add in retrieved order and descending order.
  65. A binary search tree was considered for the ordered list, however I found that when
  66. attempting to print the tree I was created a linked list from the tree to simplify
  67. the process, so forgoing the tree altogether was the most efficient choice.
  68.  
  69. Main program flow
  70. Timestep and threshold requested -> New data printed to screen when available -> Loops checking for key presses -> When gather is finished, print the average and descending lists -> Wait for user request to exit.
  71. -> Data gathering thread begins executing -> Lists are populated -> Thread ends at EOF or 's' key pressed
  72. -> Key listening thread begins executing -> When a key is pressed, give its value to global variable -> Thread ends with end of main thread
  73.  
  74. Additional features
  75. -Console formatting
  76. Console formatting is supplied through the ConsoleControl class which was written
  77. for the tic tac toe lab of week 2. With this class, you can safely and easily:
  78. -Change the text and background colour
  79. -Clear the console window
  80. -Change the title of the console window
  81. -Change the size of the window
  82. -Get and set the cursor position to draw tables/text with precision
  83. -Threading
  84. The data gathering and key listening happens in seperate threads to reduce
  85. interference between the main functions as well as to allow concurrent
  86. listening, printing and data gathering
  87. -Key listening
  88. The key listening is handled in a thread seperate to the main thread.
  89. As such, the thread can sit waiting for user input while the main
  90. thread executes as normal, checking once per loop to see if a key
  91. has been pressed.
  92. -Adjustable timing
  93. Using the clock() and sleep() functions, the program runs only when required
  94. and sleeps for the rest, cutting out uneccesary computations and improving
  95. efficiency (slightly).
  96. For example, the main loop need not run more than 60 times per second, and
  97. is therefore capped at this loop frequency.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement