dilevin / computer-graphics-kinematics

Computer Graphics Assignment about Kinematics
3 stars 5 forks source link

Functions in 'end_effectors_objective_and_gradient' #39

Open NPTP opened 4 years ago

NPTP commented 4 years ago

Hi! I have a number of questions about what's going on here. To make it simple I'll do my best to lay them all out numbered in one post.

1. What is the max_step used in line_search()? Is that just our sigma?


2. So we perform max_iters of projected_gradient_descent. Inside of this, we are calling line_search. As I understand it, line search needs to keep halving its sigma if it doesn't find a lower value of f, so it takes smaller and smaller steps in the negative direction of ∇f until it has made a step that reduces the value of f. Does the halving of sigma happen inside line search? If so, we would have max_iters of the external loop (the gradient descent function) and then ??? (potentially infinite?) iterations inside line search?


3. I don't understand how to use x(a) and variants of it, as described on the assignment page. image So db is the rest tip position of xb? And Tb is the transformation required to take db to xb? I'm not sure how to use this. For example when calculating the Jacobian approximately using finite differencing, we have the following: image But I don't understand how to deal with image or image. Doesn't this give us a vector? How do we go from there to get a scalar to put into position (i, j) in the matrix J? Basically I'm trying to construct the Jacobian and getting quite stuck with what the matrix actually looks like, its size, and its contents.


4. In end_effectors_objective_and_gradient we have the function handle grad_f. In here we are meant to compute the "least squares objective gradient". Does this mean the part highlighted in red here? image If so, how do we go about this? As I understand it, E(x) is: image where q is the desired end position. x is referred to as tip positions - are these for ALL bones or just the tips of end effectors? Are these positions just 3D xyz coordinates then, not Euler angles? The closest analogue I see in end_effectors_objective_and_gradient is the vector xb0, which contains 3D xyz coordinates, but only for end effector positions.


5. Following from (4.), I have the same confusion about the function handle f in the same .cpp file. All we need to do is computes the least-squares objective value given the vector a of all 3*#bones Euler angles. So I want to compute the following: image If xb0 is equal to the desired position q, but xb0 is in xyz coordinates, and all I have as inputs to end_effectors_objective_and_gradient is a list of bones and a list of indices into them of end-effector constraints (which does not contain xyz coordinates of current positions, only Euler angles), how am I supposed to make this computation?


As you can probably tell I am pretty lost, so thank you for your time!

dilevin commented 4 years ago
  1. It's the maximum (i.e the initial) value of sigma. The initial line search guess should use this value for sigma.

  2. Yes, you halve sigma inside of linesearch. You should have a mechanism to prevent infinite iterations in the line search (for instance stop when sigma < some tiny tolerance)

  3. The kinematic Jacobian is the derivative of end-effector position with respect to the joint angles. If we put joint angles in the columns and position in the rows of that matrix it will be 3 (size of position vector) by 3*num_joints (3 euler angles per joint).

  4. grad_f should compute df/da so the vector which is the gradient of the scalar cost function. This is equal to J'*dE/dx

5.These are equivalent, x_b is always the position of the end-effector as determined by the skeleton of the model. The dependence on a is implied rather than written out explicitly, in the first equation. (TLDR x_b is always x_b(a))

NPTP commented 4 years ago

Thanks for quick answers! Very helpful.

I should clarify for (5.), what I meant to say is:


image If the vector xb0 in end_effectors_objective_and_gradient is equal to q above , but xb0 is in xyz coordinates, and all I have as inputs to end_effectors_objective_and_gradient is a list of bones and a list of indices into them of end-effector constraints (which does not contain xyz coordinates of current positions, only Euler angles), how am I supposed to make this computation?

Essentially, does the variable xb0 in the .cpp file map to q in the given equation (the desired location of the end-effector), or does it map to x_b in the given equation (the position of the end-effector as determined by the skeleton)? And in either case, if I have only the equivalent of x_b or q, but not both, then how do I get the other from bones & Euler angles alone, to complete the computation?

dilevin commented 4 years ago

Correct, xb0 in the code == q in this equation. You can use the variable xb0 inside of the lambda functions f and grad_f even though it isn't an explicit parameter.

Given a set of Euler angles (A) you can compute the transforms for each bone using your forward kinematics code. Once you know where all the bones are you can compute the world space position of the end effector point, x_b.

NPTP commented 4 years ago

Given a set of Euler angles (A) you can compute the transforms for each bone using your forward kinematics code.

Oh right, duh! Staring at code too long and overthinking. Thank you.

NPTP commented 4 years ago

Hi, Still confused about one thing... I understand the structure of the Jacobian J, how J(i,j) = dx_i/da_j, and that we can get J(i,j) approximately, by using finite differencing.

But here is what that looks like...

image

I understand x is our end-effector tip position, in this case. But what is this highlighted function x_i(a)? I do not understand what this means, really. How are we getting a function from a particular component of x, which is just a scalar value representing a single component of a bone tip position? What does this function look like and what does it mean to plug in a or a + hd_j to this function?

Also, it looks like when constructing the Jacobian, if we do this to every column j, we'd be perturbing every single Euler angle in a. Is that really what we want?

dilevin commented 4 years ago

x_i(a) is the it's component of the end-effector position

i ranges from 0 to 2 where x = [x_0, x_1, x_2]. So, for instance x_1 is the y component of the position

x(a) is end-effector position computed using some particular euler angles a for really x_i(a) means to perform forward kinematics using angles, a, and then read of the i_th component of the result

yes you have to perturb every euler angle because every euler angle that likes on the same path from the root to the end-effector will affect the position of the end effector.

NPTP commented 4 years ago

Got it, thank you!