I want to find Fourier Series coefficients ($a_n$ and $b_n$) for this signal:
$$f(t) = \frac{A}{t_s}t[u(t) - u(t-t_s)] + A[u(t-t_s) - u(t-(t_s + t_{on}))] + -\frac{A}{t_d}[t-(t_s+t_{on}+t_d)][u(t-(t_s+t_{on}))-u(t-(t_s+t_{on}+t_d))]$$
It's a trapezoidal signal where $A$ is the amplitude, $t_s$ is the rising time, $t_d$ is the fall time, $t_{on}$ is the time interval in which the signal has a constant value and $T$ is the period.
For instance, with $t_s=1, t_{on}=2, t_d=2, A=1$: graph
So I'm solving this expression ($b_n$ and $a_o$ are similar)
$$a_n = \frac{2}{T}( \int_0^{t_s} \frac{A}{t_s} t cos(n w t) dt+ \int_{t_s}^{t_s+t_{on}} A cos(n w t) dt+ \int_{t_s+{t_on}}^{t_s+t_{on}+t_d}-\frac{A}{t_d} (t-(t_s+t_{on}+t_d)) cos(n w t) dt)$$
and as result I get:
$$a_o = A(\frac{t_s}{2} + t_{on} + \frac{t_d}{2})$$
$$a_n = \frac{2A}{t_st_dTn^2\omega^2}[t_dcos(nt_s\omega)-t_d-t_scos(n\omega(t_s+t_{on}+t_d)) + t_scos(n\omega(t_s+t_{on}))]$$
$$b_n = \frac{2A}{t_st_dTn^2\omega^2}[t_dsin(nt_s\omega)-sin(n\omega(t_s+t_{on}+t_d)) + t_ssin(n\omega(t_s+t_{on}))]$$
My question is: how can I be sure these coefficients are correct? I wrote until $a_5$ and $b_5$ and I couldn't see my $f(t)$ so I suspect it isn't right..
These days, the answer is usually: by plotting a partial sum with a computer.
Maple agrees with your computation, except for one detail: in the formula for $b_n$, the term $\sin (n\omega(t_s+t_{on}+t_d))$ should have $t_s$ as a coefficient.
For a test, I used your data $t_{s}=1$, $t_{on}=2$, $t_d=2$, $A=1$. With $T=5$ (and of course $\omega=2\pi/T$), the partial sum up to $n=5$ looks pretty good:
If your $T$ is larger (i.e., the signal stays at $0$ for some time), you'll need more terms. For example, with $T=15$ the partial sum up to $n=5$ is no longer adequate.