The general case of what you want is to take the integral of velocity with respect to time, which gives you distance. Of course, that is using calculus which is above the level of mathematics you mention in your question, so we'll have to break it down further. However, I think the reason you're having trouble finding the equations you want on Google is because the more general version of this problem is a classic calculus problem, so most people would approach it with calculus. Let's see if we can break it down into algebra.
The key to this is that you've got what we call a "piecewise equation" for velocity, so naturally the distance traveled is going to be a piecewise equation as well. Your velocity curve has 3 segments, so we can expect the distance to be 3 segments as well. There won't be 1 equation, but 3 equations governing the 3 different regions.
We'll start off with the example you show, where you hit maximum speed, and then we'll handle the corner case where you don't reach maximum speed on that segment.
During the first period, accelerating, we can use the formula $x=\frac{1}{2}at^2 + v_0t + x_0$ to show how far we went, where $a$ is our acceleration, $t$ is time, $v_0$ is our velocity at the start of the segment, and $x_0$ is the position at the start of the segment. Since we start off with no velocity and at our starting point, this simplifies to a much shorter equation, $x=\frac{1}{2}at^2$.
During the second phase, where we maintain a speed, the distance we have traveled is simply $x=v_{max}(t-t_1) + x_1$ where $v_{max}$ is our maximum velocity, $t_1$ is the time we reached that maximum velocity, and $x_1$ is the position we reached that velocity. How do we find these? Well, we know we got there by accelerating at $a$ from an initial velocity $v_0=0$ to a maximum velocity $v_1=v_{max}$. Clearly this will take $\frac{v_{max}}{a}$ time (its simply the definition of a constant acceleration), so $t_1=\frac{v_{max}}{a}$. Once we have this, we can plug that time into the first equation to determine $x_1$, which is the distance we traveled while accelerating for $t_1$ seconds.
The third phase is similar to the first, except we have a negative acceleration. I'm going to assign this the letter $d$, for deceleration. Now there can be some confusion as to whether we should have a positive or negative value for $d$, but you wisely chose to make it a negative number ($d=-3.8$). Either way works, but your way is more consistent, so I'm more than happy to do it that way! Our equation for position in the third phase is $x=\frac{1}{2}d(t-t_2)^2 + v_2(t-t_2) + x_2$, where $t_2$ $x_2$ and $v_2$ are the time, position, and velocity when we start decelerating. If we can find these three variables, we've characterized the entire 3 part curve! Of course, we save the best for last. These are a little trickier than $t_1$ and $x_1$ were.
The first thing we will want to note is that we already know $v_2$, because $v_2=v_{max}$. We know this because I mentioned at the start that we were only looking at the case where you hit maximum speed. We'll handle the other case, where you never reach maximum speed, in a second part. The next thing we know is that we have to decelerate to a stop. If we call the stopping point $x_3$, which occurs at $t_3$, we can figure out how early we have to start applying the brakes. Hopefully it should be easy to see that we will need to brake for $\frac{-d}{v_{max}}$ seconds to go from max velocity to stopped. Using the variables we've been using all along, we can write that as $(t_3-t_2)=\frac{-d}{v_{max}}$. I point this out because the above equation for where we are during the third phase has that $(t-t_2)$ term everywhere, which looks kinda scary, but we can see the same pattern here.
We're almost done! The final step we need to finish characterizing the curve is to figure out $t_2$ and $x_2$. Presumably we know $x_3$, because its the stopping point for that segment. We can use the equation for the decelerating period to solve for $x_2$, given that we know $(t_3-t_2)$, $v_2$, and $x_3$. Once we have $x_2$, we can plug that into either the steady state equation or the decelerating equation to find $t_2$ (the steady state one will be easier!).
Phew after all that math, we have several triplets of times, positions, and velocities. We have:
- $t_0$, $x_0$, and $v_0$ which are the starting time position and velocity (and all have the value of 0, since we're just starting)
- $t_1$, $x_1$ and $v_1$, which are the time, position and velocity where the truck finishes accelerating ($v_1=v_{max}$, and the other two are solved for)
- $t_2$, $x_2$ and $v_2$, which are the time, position and velocity when the truck begins decelerating ($v_2=v_{max}$, and the other two are solved for)
- $t_3$, $x_3$ and $v_3$, which are the time, position and velocity when the truck finishes stopping ($x_3$ is the length of your segment, and $v_3$ = 0. $t_3$ is solved for)
Now for the final step, you don't care about how far you can travel in a given amount of time, you care about how long it takes to travel a given distance. You want the inverse of this equation. Fortunately, this is easy enough to do with a piece wise equation. By comparing your desired distance, $x$ to $x_1$ and $x_2$, you can figure out which of the three regions you are in. Once you know that, you can simply invert that one equation to solve for time given a distance!
Well, that was the second to last step. All of that assumed you had enough time to accelerate to full speed. What if the segment is short? We need a different set of equations for that. Fortunately, they're not all that different. In fact, they're easier. We only have two regions: $t_0$ to $t_1$ where the truck is accelerating, followed by $t_1$ to $t_2$ where it is decelerating. All we have to do is find that midpoint where the truck lets off the gas and hits the brakes, and we're set!
Because you have a constant acceleration, we can easily relate the lengths of the two duration. We know that $v_1=a(t_1-t_0)+v_0$ from the acceleration curve, and $v_2=d(t_2-t_1)+v_1$. Dropping all of the terms which we know to be zero, we get $v_1=at_1$ and $0=d(t_2-t_1)+v_1$. With a little bit of rearranging we get $at_1=-d(t_2-t_1)$ or $t_2=\frac{a+d}{d}t_1$. This is a really nice equation to know: there's a clear relationship between $t_1$ and $t_2$ that we can exploit!
Okay, so how do we use this. Well, we know the length of the segment, $x_2$ because that's a given. Let's look at the equation for the second half: $x_2=\frac{1}{2}d(t_2-t_1)^2+v_1(t_2-t_1)+x_1$. There's lots of unknowns here, but we can fill some of them in. We can replace $t_2$ using the equation above, and we can get $v_1$ and $x_1$ from the acceleration curve. Putting all of these together we get $x_2=\frac{1}{2}d(\frac{a+d}{d}t_1-t_1)^2+(at_1)(\frac{a+d}{d}t_1-t_1)+(\frac{1}{2}at_1^2)$. That equation looks obnoxious, but if you look closely, there's only one unknown left: $t_1$. You can solve for it!
After solving, we have the following triples:
- $t_0$, $x_0$, and $v_0$ which are the starting time position and velocity (and all have the value of 0, since we're just starting)
- $t_1$, $x_1$ and $v_1$, which are the time, position and velocity where the truck finishes accelerating and starts decelerating (all must be solved for)
- $t_2$, $x_2$ and $v_2$, which are the time, position and velocity when the truck finishes stopping ($x_2$ is the length of your segment, and $v_2$ = 0. $t_2$ is solved for)
From there it's all the same!
Now, after all of this, you should be able to see why it was hard to Google for! None of these steps are particularly fancy, but they are all very specialized to your particular rules for acceleration and deceleration. You also have two cases, one where you reach a max speed, and one where you do not. There's just a lot of little steps, and it's not obvious that the steps are moving your forward!
Please check my math when you implement this. I'd hate to misguide our first responders!