simulation_framework::evaluator::DistanceDrivenCalculator Class Reference
Last update: 16.07.2025class DistanceDrivenCalculator More...
#include <distance_calculator.h>
Public Member Functions | |
| double | Calculate (const osi3::GroundTruth &ground_truth) |
Detailed Description
class DistanceDrivenCalculator
DistanceDrivenCalculator class to calculate the total distance covered/driven by an Ego car based on osi GroundTruth Algorithm explaination:
- Find out the Ego vehicle index within MovingObject list from GroundTruth and compute the BoundingBox
- Get the position of Ego vehicle at each time interval/step.
- Calculate the Eucledian distance between two positions of Ego vehicle(at given time stamp)
- Make the sum of all the distances calculated(For each time step)
- One of the possible validation method could be to calculate distance from Formulas based on the Average car Velocity and total travel Time. And compare the result with distance calculated using Euclidean method.
- For now, we have added a few tests based on hard-coded values of position, which helps to confirm/validate the basic logic of distance driven calculation.
Definition at line 38 of file distance_calculator.h.
Member Function Documentation
◆ Calculate()
| double simulation_framework::evaluator::DistanceDrivenCalculator::Calculate | ( | const osi3::GroundTruth & | ground_truth | ) |
Definition at line 12 of file distance_calculator.cpp.
13{
14 double distance = 0.0;
15 auto host_vehicle_index = std::make_optional<int>();
16
17 const auto& host_vehicle_id = ground_truth.host_vehicle_id();
18 const auto moving_objects_count = ground_truth.moving_object_size();
19
20 for (int i = 0; i < moving_objects_count; ++i)
21 {
22 if (host_vehicle_id.value() == ground_truth.moving_object(i).id().value())
23 {
24 host_vehicle_index.value() = i;
25 break;
26 }
27 }
28
29 if (!host_vehicle_index.has_value())
30 {
31 return distance;
32 }
33
34 const auto& host_vehicle_base = ground_truth.moving_object(host_vehicle_index.value()).base();
35
36 if (!is_initialized_)
37 {
38 is_initialized_ = true;
39 last_xpos_ = host_vehicle_base.position().x();
40 last_ypos_ = host_vehicle_base.position().y();
41 return 0;
42 }
43
44 double current_xpos = host_vehicle_base.position().x();
45 double current_ypos = host_vehicle_base.position().y();
46
47 // Values to be substituted in the standard Euclidean distance formula
48 const auto delta_xpos = last_xpos_.value() - current_xpos;
49 const auto delta_ypos = last_ypos_.value() - current_ypos;
50
51 // Euclidean distance formula to calculate distance between two points/positions.
52 distance = std::sqrt((delta_xpos * delta_xpos) + (delta_ypos * delta_ypos));
53
54 // Update value of last position values with the recent current position value.
55 last_xpos_ = current_xpos;
56 last_ypos_ = current_ypos;
57
58 return distance;
59}
The documentation for this class was generated from the following files: