~gpcf/advtrains

Proposal for an other train acceleration calculation : NOT to be included in "doc" branch without discussion v1 UNKNOWN

Tanavit: 1
 Proposal for an other train acceleration calculation : NOT to be included in "doc" branch without discussion

 1 files changed, 32 insertions(+), 2 deletions(-)
orwell <orwell@bleipb.de> writes:
Next
Hello

Sorry for this very late answer : I did not receive your comments in my 
mailbox and just discover it.

Three months ago Orwell wrote :
 > It also means that I am unwilling to change the movement logic at 
this time, unless there is a real benefit in doing so.

I agree with your schema of speed and position calculation although I 
think that using the position calculation derived from uniform acceleration
(https://en.wikipedia.org/wiki/Equations_of_motion#Constant_translational_acceleration_in_a_straight_line)
would provide a better result : in case of important acceleration the 
a/2*t^2 term could be significant.

And you could always approximate a non uniformly accelerated motion as 
the sum of a lot of small uniformly accelerated motion with a variable 
acceleration.

What could be discussed is the value of dt and the value of the 
{ac,de}celeration.


 > What we can talk about is step 2, the calculation of a. Especially 
for braking it is pretty unrealistic, since all wagons are assumed to 
have the same weight (1) and the same braking capability (-3m/s²).

I guess this is not so far from real trains : I am pretty sure the 
brakes are designed to stop the wagon on which they are put on the same 
distance whatever is the wagon. Big and heavy wagon have big brakes and 
small one have small brakes. If not designed such, some wagons would 
stop before the other ones : brakes and couplings would be unnecessarily 
stressed.

 > The weight and acceleration/braking capabilities should be settable 
for each wagon type, and for freight wagons the weight may even scale 
with load.

It looks me an unnecessary complication : if you calculate a 
decelaration for each wagon in a train, how will you calculate the whole 
train deceleration ? You can not apply a different deceleration to each 
wagon as this would dismantle the train.
I don't exactly know trains drivers use brakes but I guess it is not 
very different from braking a car : I adjust braking to stop where I 
intend to.

My proposition aims to adjust the positive or negative acceleration from 
the actual speed and the remaining distance to reach the expected speed 
(which may be zero to stop or the max speed to run).

 From what I understood, it does not change the way the speed and the 
position are presently calculated.

Sincerely yours.
Hi Tanavit,

Am 09.04.22 um 20:39 schrieb Tanavit:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~gpcf/advtrains/patches/27777/mbox | git am -3
Learn more about email & git

[PATCH] Proposal for an other train acceleration calculation : NOT to be included in "doc" branch without discussion Export this patch

# Following a discussion on Li-Fo about trains acceleration calculation 
# Here is a proposal whom the author is not sure it could be used in advtrains
# The proposal is written in the A appendix

---
 assets/manual/manual.tex | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/assets/manual/manual.tex b/assets/manual/manual.tex
index bf46e75..5a487d0 100644
--- a/assets/manual/manual.tex
+++ b/assets/manual/manual.tex
@@ -18,7 +18,7 @@

\usepackage{imakeidx}
\makeindex[columns=1,title=Alphabetical Index,intoc]

\usepackage{textcomp} % Needed for \textdegree with T1
% Font substitution: taken from https://ctan.org/tex-archive/macros/latex/contrib/beton/beton.pdf
\ifx\HCode\undefined
\AtBeginDocument{
@@ -1234,7 +1234,7 @@ The speed restriction table for trains includes the speed limits for a train, wh

\section{Physics}\label{s:physics}

\subsection{Train acceleration}
\subsection{Actual Train acceleration}

The acceleration of a train is calculate as follows:
\[a = a_{\text{all}} + a_{\text{locomotive}}\cdot\frac{n_{\text{locomotives}}}{n_{\text{wagons}}}\]
@@ -1261,8 +1261,38 @@ The time needed to accelerate from $v_0$ to $v_1$ can be calculated as follows:
The distance needed to accelerate from $v_0$ to $v_1$ can be calculated as follows:
\[ s = \frac{v_1^2 - v_0^2}{2a} \]

\subsection{Proposed acceleration calculation}

\subsubsection{The problem}

Considering that at $t=t_I$ the train is at position $x_I$ with a velocity $v_I$, that the train must reach the velocity $v_F$ at position $x_F$ at $ t=t_F$, what should be the acceleration $\gamma$ under the hypothesis of an uniform accelerated move ?

\subsubsection{One possible answer}
The move equations are : 
\[v(t)=v_I+ \gamma t\]
\[x(t)=x_I+v_It+\frac{1}{2}\gamma t^2\]

Solving this for ($x_F$,$v_F$,$t_F$) leads to :
\[\gamma=\dfrac{v_F^2-v_I^2}{2(x_F-x_I)}\]
\[t_F=t_I+\dfrac{x_F-x_I}{\dfrac{v_I+v_F}{2}}\]

\subsubsection{Practical use}
Considering that the animation of the train is discretized with a time step $\delta t$, a simple calculation schema could come from the \textsc{Euler}'s method for solving differential equations.

In the following description, the $C$ subscript should be understood as current, and is equivalent to $I$.

\begin{enumerate}
	\item Calculate $\gamma(x_C, v_C, x_F, v_F)$
	\item $x_C=x_C+v_C\delta t$
	\item $v_C=v_C+1.05\gamma \delta t$
	\item Go to step 1
\end{enumerate}

Note : the $1.05$ factor in step 3 is not mandatory : it is aimed to accelerate convergence, and could be a parameter.

\ifx\HCode\undefined
\printindex
\fi


\end{document}
-- 
2.20.1
Hi Tanavit,

True, the acceleration, velocity and movement distance calculation in advtrains is currently very trivial and not mathematically accurate.
For completeness (and also to be included in the documentation), here is the current implementation:

1. Under the assumption that the current speed v_c of the train does not change, calculate x_n = x_c + (v_c * dt).
Between x_c and x_n, the path_speed table is queried for the maximum speed allowed within the next few path items.
(path_speed is essentially a pre-calculated braking curve to reach all speed limits set by LZB)
2. Acceleration is calculated as documented already
3. If (1) the upcoming speed limit from step 1 or (2) any other speed-limiting factor (like off-track) is smaller than v_c, then v_c is forcibly set to this limit
4. otherwise, if a<0, then v_c = v_c + a*dt (the velocity change is applied before the movement step when the train is braking)
5. The train position is updated in a simple linear manner x_n = x_c + v_c*dt
6. if a>0, then v_c = v_c + a*dt (velocity change is applied after movement when the train is accelerating)

This mechanism is the result of a lot of experimentation and the current best solution. Especially, it is made in a way that the velocity and delta-position at any given time are guaranteed to be always less or equal to the "ideal" case, never higher. This is crucial for the LZB stuff to work properly, and it has cost me much time to get right and bug-free.

It also means that I am unwilling to change the movement logic at this time, unless there is a real benefit in doing so.

What we can talk about is step 2, the calculation of a. Especially for braking it is pretty unrealistic, since all wagons are assumed to have the same weight (1) and the same braking capability (-3m/s²). The weight and acceleration/braking capabilities should be settable for each wagon type, and for freight wagons the weight may even scale with load.

Thank you a lot for your french translation though. I wish you a happy new year!

Regards,
orwell

Am 29.12.21 um 16:26 schrieb Tanavit: