IamCyBo / Graphical_Programming_CurveDriving

The Unlicense
0 stars 0 forks source link

D9 - Check how one should adapt the velocity to limit lateral acceleration #14

Closed Frankybeen29 closed 7 months ago

MoxCodes22 commented 7 months ago

Feasibility

We can calculate the lateral acceleration by given formula:

$a = \frac{v^2}{R}$

source: https://www.mrwaynesclass.com/circular/notes/corner/home.htm

We can get the current radius as in D3 from the steering angle and with the current velocity calculate the current acceleration. We get all these variables in the MyTurn.esdl, so we can just calculate the current acceleration here:

    radius = 2.85 [m] / Lib.sin(abs(beta));
    acc = Lib.pow(v * (5 / 18[kmph]), 2) * 1.0[mps2] * 1.0[m] / radius; 

A typical car has a maximum acceleration of 0.6 to 0.9g, therefore we choose 0.8g (source: https://www.mrwaynesclass.com/circular/index08.html).

With the formula provided, we can then calculate the maximum velocity that can be driven when steering with a certain angle aka driving on a curve with a certain radius:

$v_{targeted} = \sqrt{R \cdot a}$

However, this is of no use for us. Since the car has a breaking distance, we cannot reach a targeted velocity in an instance, so we need to kind of predict what velocity we need when driving through the next curve. Then we can break in time to reach an appropriate velocity.

But how can we predict? An approximation method that we came up with is explained in the following:

grafik

We can calculate the radius of the circle that is defined by the current position of the car and the two line segments defined by the focuspoint that is currently approached the former focuspoint and the focuspoint to come:

$R = distance2focuspoint \cdot tan(\frac{\alpha}{2})$

We start calculating that radius after coming out of the last curve when we are pretty much on track again meaning the angle difference between bearing and vector to next focuspoint is smaller than 0.01 rad. Then after that during the approach and during the curve we constantly calculate the radius which gets smaller and smaller which causes the target velocity to also decrease and we should break on time and reach an appropriate speed when being in the curve.

Limitations

This approach may not work that good when the curves are defined by many focuspoints as we accelerate again after a certain error is undershot. We would then accelerate in a curve which is not desired. However for routes with small resolution meaning defined by few points in good distance to each other this should work very well.

MoxCodes22 commented 7 months ago

Implementation

The current acceleration is calculated in MyTurn.esdl as described above. We can access this in myDrive_4.bd to log the acceleration and later check if in the curves we adhere to the desired.

grafik

Also another car message is introduced for the acceleration in case of possible use in experiments:

grafik

Since a lot of new calculations need to be done in the Control.esdl, a lot of them are transferred into newly created specifications.

The CalcAngle specification calculates $\frac{\alpha}{2}$: grafik

The CalcRadius specification calculates the radius of the circle: grafik

The CheckCurve specification checks whether we are back on track after leaving the curve: grafik

The NextFocuspoint specification handles not only when to approach the next focuspoint but also when to calculate the angle between the next two segments which is after leaving the current curve. It also makes sure that the old focuspoint is updated at the right moment so that the right angle is calculated. grafik

The TargetVelo specification determines the target velocity for control that is determined by the current calculated radius with the exception of the last segment where we just drive with 60 kmph until we break and then come to a stop at the end. grafik

The Main Specification still calculates the targeted steering angle, calls the above listed specifications and as a last step sends the acquired target velocity to the velocity controller to get the power and the break signals which are then send to the car. grafik

Result

When plotting the logged velocity, one can see that we break before the curves and also drive slowly through the curves. D9_results1

When plotting the driven curve and the actual, we can see that we drive through the curves way smoother and we also don't exceed the maximum lateral acceleration. There are some points which violate the condition but all in all this algorithm does it's job very well. perfektperfekt

When trying this algorithm on the Nurburg Ring, the mentioned limitations apply. The car breaks in the curves however also accelerates in certain intervals since multiple points make a curve. D9_results3

One can also see the violations on the acceleration plot: nurburg_good_acc

However improving that further would be a little too extensive for the project.

MoxCodes22 commented 7 months ago

Done

Frankybeen29 commented 7 months ago

Changes are in docs