Skip to content

Data processing

Kebslock edited this page Sep 18, 2023 · 11 revisions

Computation of vehicle position, speed and heading

Described below is how the backend computes positions, speed, heading and other related values for a vehicle. This is an important step in the data pipeline, because these values are not saved anywhere and need to be calculated from raw data. This processing can be found in the vehicle service and can be divided into several steps:

  1. Data acquisition: First the raw data needs to be fetched from the database. There are two types of data (both associated with the requested vehicle):

    • logs of trackers: Sent by stationary trackers, which are mounted on the vehicle. Only the last log of every tracker is taken into account, because at the moment their sending frequency is quite low and therefore not very useful for real time tracking. This could be changed in the future as the tracker data is probably more reliable than the second type.
    • logs of app instances: Sent by devices of users, who are driving the vehicle. Those logs can be sent more often and thus are closer to real time. For testing this is the better source of data (because of the low sending frequency of the stationary trackers). Therefore the logs of the last 30 seconds are included for the calculation. To improve performance these logs are sampled down to intervals of roughly three seconds.
  2. Vehicle travelling direction: The travelling direction of the vehicle needs to be computed next. This is a value of 1 or -1 representing the vehicle either travelling to the end and to the start of the track respectively. This is needed for further calculation, but is included in the final response as well to detect vehicles travelling towards each other. For this all logs are concatenated. There are two cases, how this is calculated:

    • If there is only one log (this could happen e.g. if no app instance is sending data for a vehicle), the step, which computes the progress of the vehicle on the track, needs to be done first. Therefore the position of this log is projected on the track and than the track kilometer can be obtained. With this value the orientation of the track at that position can be computed. Together with the heading of the vehicle from its only log the travelling direction can be computed. It should be mentioned, that all computations made with only one log perhaps cannot be very precise.
    • If there are at least two logs, all track kilometers are obtained from them in a similar way as above. Instead of looking up the orientation of the track at this point, the travelling direction can be computed directly from the track kilometers by simple subtraction and checking if the result is positive. As an advantage there is no heading of the vehicle needed and it is probably more robust.
    • For the sake of completeness it should be mentioned, that it is not possible to compute anything, if there are no logs at all (the response is a 404 in this case).
  3. Vehicle speed: To compute the vehicle speed all logs are concatenated together again. If there is only one log in total, the speed of it is just returned. If not, the track kilometer values are obtained as described above from the two most recent logs. By subtracting those two values and using the timestamps of them it is possible to get a good approximation of the speed. Than all three speeds - the two from the logs and the third, that just got calculated - are averaged again to get an even better approximation. Lastly this factor is multiplied to the result to take the passed time into account: $-e^{\frac{t-30}{6}} + 1$ where $t$ is the passed time to the latest log. If the final speed is negative, it is set to 0. This leads to a slowly decelerating vehicle, which stops after 30 seconds (if no new logs come in).

  4. Vehicle position: Next the current vehicle position is calculated. This can be divided into different steps again:

    1. Weighting the logs: This step should give each log a weight representing its certainty. Those weights are composed of two different factors. The first is a temporal factor, which represents how long ago the log was received, which can be computed directly with the timestamp of the log. The second one represents accuracy and is measured by distance to the track. Both factors have a certain cutoff value depending on their type (tracker or app) and are mapped from 0 to 1 accordingly.
    2. Predicting current positions: Than the current position of the vehicle is predicted for each log by obtaining the track kilometer of it and calculating the travelled distance. This is a simple calculation involving the already computed values of the vehicle's speed and travelling direction.
    3. Building the weighted average: Finally the current position is determined by building the average on all predicted track kilometer values based on their weight. Thus the final position is always mapped on the track. If the weights are all 0 (so the logs were not recent or accurate enough), the last kown position is just returned.
  5. Vehicle progress on its track: In this small step is calculated, where a vehicle is located in relation to its track. This is a really simple calculation by obtaining the current track kilometer (already a result of the position computation) and the total track length. It is noteworthy, that the track kilometer value will be included in the final result two.

  6. Vehicle heading: The last step is computing the heading of the vehicle. To get a meaningful value here the heading is mapped onto the track's orientation. This can be done by using the current track kilometer and the travelling direction of the vehicle.

Note: Some processing described above is not implemented yet.

Clone this wiki locally