I want to solve for a 3dof planar arm using gradient descent to approximate end position. Now I am a little confused about the formula and was wondering if someone can help me out.
This is my thought process:
First start about using the forward kinematic solution mapping angles to euclidean space:
$x = l_1 * cos\theta_1 + l_2 * \cos(\theta_1 + \theta_2) + l_3 * \cos(\theta_1 + \theta_2 + \theta_3)$
$y = l_1 * sin\theta_1 + l_2 * \sin(\theta_1 + \theta_2) + l_3 * \sin(\theta_1 + \theta_2 + \theta_3)$
$\phi = (\theta_1 + \theta_2 + \theta_3)$
Now to I need to define a cost function ( that is where I get a little stuck), I know from a 2dof example, that I need to minimize the distance from the endpoint of my arm $x_{ep} $ to the target in euclidean space $x_{tg}$. defined as: $|| x_{ep} - x_{tg}||^2$ using gradient descent. Now, for a 3dof arm, obviously I would have an unlimited amount of solutions with this solution, so that I need to add one additional constraint, namely the angle $\phi$ for my endeffector too. Here I am not quite sure on how to add the angle to the cost function as a parameter.
Then I would find the gradient function $\nabla f_{cost} $ for each $\theta$, in respect to my cost function, specified above using partial derivatives. $\frac{\partial f_{cost}}{\partial \theta_{1}}(|| \begin{bmatrix} x_{ep} \\ y_{ep} \\ \phi_{ep} \end{bmatrix} - \begin{bmatrix} x_{tg} \\ y_{tg} \\ \phi_{tg} \end{bmatrix}||^2)$, $\frac{\partial f_{cost}}{\partial \theta_{2}} ...$ , $\frac{\partial f_{cost}}{\partial \theta_{3}} ...$
Then we simply try to iteratively minimize the cost function until we are below a tolerance $tol$.
I know there is a missing piece, but I am not quite sure where, I believe it lies the cost function. Maybe I am wrong, thank you for your suggestions!