<s>[INST] How to evaluate $\int_0^{2\pi} \frac{d\theta}{A+B\cos\theta}$? I'm having a trouble with this integral expression:
$$\int_0^{2\pi} \frac{d\theta}{A+B \cos\theta}$$
I've done this substitution: $t= \tan(\theta/2)$
and get: $\displaystyle \cos\theta= \frac{1-t^2}{1+t^2}$ and $\displaystyle d\theta=\frac{2}{1+t^2}dt$ where $\displaystyle \cos^2\theta/2=\frac{1}{1+t^2}$
then the integral becomes:
$$\int\frac{2 \, dt}{(A-B)t^2+(A+B)}= \sqrt\frac{A+B}{A-B} \arctan \left(\left(\sqrt\frac{A+B}{A-B} \right) t\right)$$ 
However, I'm not sure about the new limits since $\tan$ has period $\pi$ so what I have to do at this point to decide the new limits? And of course if you find some mistake in what I've done before, please let me know!
 [/INST] To avoid confusion with limits, note that
$$\int_0^{\pi} \dfrac{dx}{a+b \cos(x)} = \int_{\pi}^{2\pi} \dfrac{dx}{a+b \cos(x)}$$
Hence, we have
$$I = \int_0^{2\pi} \dfrac{dx}{a+b \cos(x)} = 2\int_0^{\pi} \dfrac{dx}{a+b \cos(x)}$$
Now use your substitution $t = \tan(x/2)$ and note that $t$ goes from $0$ to $\infty$ as $x$ goes from $0$ to $\pi$.
EDIT
An easier way if you are familiar with a little bit of complex analysis is as follows.
Let $z = e^{ix}$. Then we have that $dz = iz dx$. Hence,
\begin{align}
I & = \int_0^{2 \pi} \dfrac{dx}{a+b \cos(x)} = \oint_{\vert z \vert = 1} \dfrac{dz}{iz \left( a + \dfrac{b}2 \left(z+ \dfrac1z \right)\right)}\\
& = \dfrac1i \oint_{\vert z \vert = 1} \dfrac{dz}{az + \dfrac{b}2 \left(z^2+1 \right)} = \dfrac2{ib} \oint_{\vert z \vert = 1}\dfrac{dz}{z^2 + \dfrac{2a}b z + 1}\\
& = \dfrac2{ib} \oint_{\vert z \vert = 1} \dfrac{dz}{\left(z + \dfrac{a}b \right)^2 + 1 - \dfrac{a^2}{b^2}} = \dfrac2{ib} \oint_{\vert z \vert = 1} \dfrac{dz}{\left(z + r + \sqrt{r^2-1} \right)\left(z + r - \sqrt{r^2-1} \right)}
\end{align}
where $r = \dfrac{a}b \in \mathbb{R}$.
First note that if $\vert r \vert \leq 1$, then $\left \vert r \pm \sqrt{r^2-1} \right \vert = 1$. Hence, the integral doesn't exist.
If $r > 1$, then $ \left \vert r + \sqrt{r^2 - 1} \right \vert > 1$ and $\left \vert r - \sqrt{r^2-1} \right \vert < 1$. Hence, by Cauchy integral formula, we have that
$$I = \dfrac{2}{ib} 2 \pi i \dfrac1{2 \sqrt{r^2-1}} = \dfrac{2 \pi \, \text{sign}(a)}{\sqrt{a^2 - b^2}}$$
If $r < -1$, then $\left \vert r - \sqrt{r^2 - 1} \right \vert > 1$ and $\left \vert r + \sqrt{r^2-1} \right \vert < 1$. Hence, by Cauchy integral formula, we have that
$$I = \dfrac{2}{ib} 2 \pi i \dfrac{-1}{2 \sqrt{r^2-1}} = \dfrac{2 \pi \, \text{sign}(a)}{\sqrt{a^2 - b^2}}$$
Hence, to summarize,
$$I = \begin{cases} \dfrac{2 \pi \, \text{sign}(a)}{\sqrt{a^2 - b^2}} & \text{if } \vert a \vert > \vert b\\ \text{Does not exists} & \text{if } \vert a \vert \leq \vert b\end{cases}$$
</s>