IamCyBo / Graphical_Programming_CurveDriving

The Unlicense
0 stars 0 forks source link

D6 - Provide some validation method to compare the actual route with the targeted one and check the solution as implemented via D5 accordingly #11

Closed Frankybeen29 closed 7 months ago

IamCyBo commented 8 months ago

Feasibility

The track is defined by several line segment. The position of the car is displayed as a point. The distance of the car to the track can be found by calculating the distance of the point to every line segment (https://www.geeksforgeeks.org/minimum-distance-from-a-point-to-the-line-segment-using-vectors/):

  1. Find the vector $v$ representing the line segment with endpoints $P_1(x_1|y_1)$ and $P_2(x_2|y_2)$. $\vec{v} = \langle x_2 - x_1, y_2 - y_1 \rangle$
  2. Find the vector $w$ representing the point $Q(x_q|y_q)$ relative to one of the endpoints of the line segment. $\vec{w} = \langle x_q - x_1, y_q - y_1 \rangle$
  3. Project $w$ onto $v$ to find the point on the line segment closest to the given point to find $\vec{r} = \langle x_r - x_1, y_r - y_1 \rangle$. $\text{projection of } \vec{w} \text{ onto } \vec{v} = \frac{\vec{v} \cdot \vec{w}}{| \vec{v} |^2} \cdot \vec{v} = \vec{r}$
  4. Calculate the distance between the given point and the projected point. $d_{\text{min}} = \sqrt{(x_q - x_r)^2 + (y_q - y_r)^2}$

Or as one formula: $d_{\text{min}} = \left| \vec{w} - \left( \frac{{\vec{v} \cdot \vec{w}}}{{\vec{v} \cdot \vec{v}}} \right) \cdot \vec{v} \right| = \left|\vec{w} - \vec{r}\right|$

When the distance between car and the track does not exceed a certain threshhold (e.g. the turning radius of the car), then the car keeps track. Here, a system test can be written that with every timestep checks if the threshold is adhered to. If that's the case for the entire track, the test is passed.

Limitations

We have a large but limited resolution for the comparation. We measure every 10ms therefore the resolution should be high enogh but is still limited. We also track only differences that a higher than 4m because that should be sensible enough.

@Frankybeen29

Conclusion

Task is feasible.

MoxCodes22 commented 7 months ago
MoxCodes22 commented 7 months ago

Implementation: grafik

@Frankybeen29

Video: 2024-04-03_17h33_04

We can also log distance2route, x and y and plot them with python along the original route and mark the biggest deviation: output_main_12

319141827-1f6c7f59-bdb9-4fab-84e3-7f95a90033bb-1

IamCyBo commented 7 months ago

Covered Test cases:

testCalc: 1) Calculate the focuspoint and distance from this focuspoint to the last focuspoint, take the 2. point of the route 2) Calculate the focuspoint and distance from this focuspoint to the last focuspoint, take the last point of the route

testPointDistance: 1) Calculate the distance from the route to a point, the start point is closest 2) Calculate the distance from the route to a point, the closest is somewhere in the middle 3) Calculate the distance from the route to another point, the closest is somewhere in the middle

Frankybeen29 commented 7 months ago

Everything added to docs