# Switching function for Bang-Bang nagivation

I'm attempting to develop an equation to determine the "switching time" for a control system. I've managed to work out a specific solution for when starting and ending velocities are are the same, yet am unable to adapt this for determining the switching time given an arbitrary starting velocity, and an arbitrary ending velocity.

More formally, given the acceleration of an object:

$a(t) = \left\\{ \begin{array}{lr} MaxAccel & : 0 \lt t \le switchTime\\\ -MaxAccel & : switchTime \lt t \lt stopTime\\\ 0 & : otherwise \end{array} \right.$

determine $switchTime$, such that the object starting at $velocityInitial$, will travel $distance$, and arrive there travelling at $velocityFinal$. The calculation of $stopTime$ is trivial.

My current specific solution for starting and ending at the same velocity is:

$-velocityInitial + \sqrt{velocityInitial^2+MaxAccel*distance} \over a$

Sorry for the lack of a more formalized mathematical definition, I'm doing my best. =)

For those curious, yes this is related to my other navigation question. I'm trying to now integrate proportional navigation for small facing adjustments, and a limited bang-bang algorithm for increasing velocity towards the object. I'll post the whole algorithm once I get it working.

(Side note: This is the first time I'm actually using LaTeX for something "real" instead of fiddling around. Awesome!)

-

Let $a$ be the acceleration, $v_i$ the initial velocity, $v_f$ the final velocity, $v(t)$ the velocity at time $t$, $d$ the distance, $T_s$ the switch time and $T_f$ the final (stopping) time. Then it is easily seen that

$$d=-\frac{a}{2}(T_f^2 - 4T_fT_s + 2Ts^2)+ T_f v_i,\quad v(T_f)=v_i+2aT_s-aT_f=v_f.$$

This is a system of two equations and two unknowns, whose solution is

$$T_s=\frac{2v_i+\sqrt{4ad+2(v_i^2+v_f^2)}}{2a},\quad T_f=\frac{v_i+v_f+\sqrt{4ad+2(v_i^2+v_f^2)}}{a}.$$

This is an edit in answer to your comments. Define $acc(t)=a$ if $0\le t\le T_s$, $acc(t)=-a$ if $t>T_s$ (I am implicitely assuming that $T_f>T_s$. Then $$v(t)=\int_0^t acc(s)ds=v_i+aT_s-a(t-T_s)\hbox{ for } t>T_s.$$ Thus, $v_f=v(T_f)=v_i+2aT_s-aT_f$. Similarly, $$d=\int_0^{T_f}v(t)dt.$$ My solution agrees with yours when $v_i=v_f$. And by the way, I used Mathematica for the computations.

-
Ooo, This looks promising. I don't suppose you have the time to show how you derived the first two equations? Once I get home (at a friends house currently), I'll plug this into Mathematica to make sure I didn't miscommunicate what I was going for. (I tend to be terrible at explaining what it is I'm actually trying to achieve. ^^) – Quantumplation Jan 19 '10 at 15:10
Hm, your solutions work only when v_i and v_f are 0, and rapidly explode for even low values. :-S – Quantumplation Jan 19 '10 at 18:50
=/ I must be doing something wrong then. In Mathematica, I define d, a, vi, and vf as 5, 1, 1, 1 respectively. I then Plot[{d, position[t)]},{t, 0, tf}]. If vi and vf are both zero, the solution is a nice curve from position zero, landing perfectly on d. If vi and vf are anything else, however, ts comes out way higher than it needs to be. The equation for tf, though, is fine. :-S Sorry for all the hassle. Thank you so much for taking the time to help. :) – Quantumplation Jan 21 '10 at 10:47