Calculate maximum velocity given accel, decel, initial v, final position I'm trying to calculate the maximum velocity of an object given:


*

*acceleration

*deceleration

*starting position (0)

*ending position

*initial velocity


I've been trying to use formulas from:
https://stackoverflow.com/questions/153507/calculate-the-position-of-an-accelerating-body-after-a-certain-time
http://easycalculation.com/physics/classical-physics/constant-acc-velocity.php
but I still can't seem to figure it out.
The closest I've gotten is:
$$t = \frac{V_{max} - V_0}{a} + \frac{0 - V_{max}}{d}$$
But even trying to solve that for Vmax leaves an unknown '$t$' in the equation, and doesn't take into account the ending position either.
A sort of real world example for this, if it helps, is of a car.  The car starts at p=0, with a rolling start (in either direction).  At the finish line (ending position) is a brick wall.  The car must stop with the front bumper touching the brick wall.  It must accelerate at a for as long as possible, then decelerate at d, ending at that brick wall, with v=0.
(I'm writing an Arduino library for controlling servos, with speed limits, acceleration and deceleration.  I need to know whether the max velocity it can reach given the acceleration and deceleration will ever exceed the max velocity the library user specifies, so I can calculate whether there needs to be any time spent "coasting" between acceleration and deceleration.)

We assume the object starts at time $t=0$ at position $x=0$ and ends at position $\ell$. It accelerates constantly with acceleration $a$ and then suddenly at time $t=t_1$ it decelerates constantly with deceleration $d$ (positive) until stopping at the point $\ell$. Let us call $t_2$ the deceleration time. 
Then $v_\max=v_0+at_1$. To find $t_1$, note that $$v_0+at_1-dt_2=0;$$ this is the condition that the speed at $x=\ell$ is zero. And the distance has to be $\ell$, so 
$$
v_0t_1+\frac12at_1^2+(v_0t_2+at_1t_2-\frac12dt_2^2)=\ell.
$$
The term between brackets comes from the fact that the speed during the deceleration process is $v_\max-dt$, so the distance covered during the deceleration process is $v_\max t_2-\frac12dt_2^2$.
From the first equation, we get $t_2=(v_0+at_1)/d$. Plugging this into the second equation and solving, 
$$
t_1=-\frac{v_0}a+\frac1a\sqrt{\frac{d v_0^2+2a\ell d}{a+d}}.
$$
So
$$
v_\max=v_0+at_1=\sqrt{\frac{d v_0^2+2a\ell d}{a+d}}.
$$
