Sunteți pe pagina 1din 78

CSCE 441: Computer Graphics

Forward/Inverse kinematics
Jinxiang Chai
Outline
Animation basics:
– Forward kinematics
– Inverse kinematics
Kinematics
The study of movement without the consideration
of the masses or forces that bring about the
motion
Animation
• Robot arm animation (click here)

• Pixar lamp animation (click here)


Degrees of Freedom (Dofs)
The set of independent displacements that
specify an object’s pose
Degrees of Freedom (Dofs)
The set of independent displacements that
specify an object’s pose
• How many degrees of
freedom when flying?
Degrees of Freedom (Dofs)
The set of independent displacements that
specify an object’s pose
• How many degrees of
freedom when flying?

• So the kinematics of this • Six


airplane permit • x, y, and z positions
movement anywhere in • roll, pitch, and yaw
three dimensions
Degrees of Freedom
• How about this robot arm? Click (here)

• Six
• 2-shoulder, 1-elbow, 3-wrist
Configuration Space vs. Work Space

• Configuration space
– The space that defines the possible object
configurations
– Degrees of Freedom
• The number of parameters that are necessary and sufficient
to define position in configuration

• Work space
– The space in which the object exists
– Dimensionality
• R3 for most things, R2 for planar arms
Forward vs. Inverse Kinematics
• Forward Kinematics
– Compute configuration (pose) given individual
DOF values

• Inverse Kinematics
– Compute individual DOF values that result in
specified end effector’s position
Example: Two-link Structure
• Two links connected by rotational joints

θ2
l2
l1

θ1 X=(x,y)
End Effector
Base
Example: Two-link Structure
• Animator specifies the joint angles: θ1θ2
• Computer finds the position of end-effector: x

θ2
l2
l1

θ1 X=(x,y)
End Effector
Base (0,0)

x=f(θ1, θ2)
Example: Two-link Structure
• Animator specifies the joint angles: θ1θ2
• Computer finds the position of end-effector: x

θ2
l2
l1

θ1 X=(x,y)
End Effector
Base (0,0)
x = (l1cosθ1+l2cos(θ2+ θ2)
y = l1sinθ1+l2sin(θ2+ θ2))
Forward Kinematics
• Create an animation by specifying the joint angle
trajectories
θ2
l2
l1

θ1 X=(x,y)
End Effector
Base (0,0) θ1
θ2
Forward Kinematics
• A 2D lamp with 6 degrees of freedom
3 lower arm

c3
middle arm
2 p0

c2
Upper arm

1
c1
base

c0 ( x, y, 0 )
f ( x, y,0 ,1,2 ,3 )  T ( x, y ) R(0 )T (0, l0 ) R(1 )T (l1,0) R(2 )T (l2 ,0) R(3 ) p0
Inverse Kinematics
• What if an animator specifies position of end-
effector?

θ2
l2
l1
End Effector
θ1 X=(x,y)

Base (0,0)
Inverse Kinematics
• Animator specifies the position of end-effector: x
• Computer finds joint angles: θ1θ2

θ2
l2
l1
End Effector
θ1 X=(x,y)

Base (0,0)

(θ1, θ2)=f-1(x)
Inverse Kinematics
• Animator specifies the position of end-effector: x
• Computer finds joint angles: θ1θ2

θ2
l2
l1
End Effector
θ1 X=(x,y)

Base (0,0)
Why Inverse Kinematics?
• Motion capture
• Basic tools in character animation
- key frame generation
- animation control
- interactive manipulation
• Computer vision (video-based mocap)
• Robotics
• Bioinfomatics (Protein Inverse Kinematics)
• Etc.
Inverse Kinematics
• Given end effector’s positions, compute
required joint angles

• In simple case, analytic solution exists


– Use trig, geometry, and algebra to solve
Inverse Kinematics
• Analytical solution only works for a fairly
simple structure

• Numerical/iterative solution needed for a


complex structure
Numerical Approaches
• Inverse kinematics can be formulated as
an optimization problem
Function Optimization
• Finding the minimum for nonlinear
functions

F(x)

x
Optimization As a Tool
• How to use optimization to solve the
following linear system?
3x + 2y = 5;
4x – 5y = 6
Optimization As a Tool
• How to use optimization to solve the
following linear system?
3x + 2y = 5;
4x – 5y = 6

Define a function:
F(x,y) = (3x+2y-5)2+(4x-5y-6)2
Optimization As a Tool
• How to use optimization to solve the
following linear system?
3x + 2y = 5;
Could be nonlinear equations!
4x – 5y = 6

Define a function:
F(x,y) = (3x+2y-5)2+(4x-5y-6)2

Finding the minimum for F(x,y) :


x+,y+= argminx,y (3x+2y-5)2+(4x-5y-6)2
Optimization As a Tool
• How to use optimization to solve the
following linear system?
f(x, y) = 0;
Could be nonlinear equations!
g(x,y) = 0

Define a function:
F(x,y) = f(x,y)2+g(x,y)2

Finding the minimum for F(x,y) :


x+,y+= argminx,y f(x,y)2+g(x,y)2
Formulation
• So how to convert the IK process into an
optimization function?

arg min F ( )

Find the pose satisfying:


f i ( )  Ci
θ2
l2
l1

θ1 C=(Cx,Cy)

Base (0,0)
Iterative Approaches
Find the joint angles θ that minimizes the distance between
the hypothesized character position and user specified
position
arg min

 i
||  f ( )  Ci  || 2

hypothesized specified
position position
θ2
l2
l1

θ1 C=(Cx,Cy)

Base (0,0)
Iterative Approaches
Find the joint angles θ that minimizes the distance between
the hypothesized character position and user specified
position

arg min (l1 cos 1  l2 cos(1   2 )  c1 ) 2  (l1 sin 1  l2 sin( 1   2 )  c2 ) 2


1 , 2

θ2
l2
l1

θ1 C=(c1,c2)

Base (0,0)
Iterative Approaches
Mathematically, we can formulate this as an
optimization problem:

arg min


 if ( )  ci 2

The above problem can be solved by many


nonlinear optimization algorithms:
- Steepest descent
- Gauss-newton
- Levenberg-marquardt, etc
Gradient-based Optimization
Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles until the solution


converges:
 k 1   k   k
Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles until the solution


converges:
 k 1   k   k

How can we decide the amount


of update?
Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles:  k 1   k   k

  f (   k )  ci 
k 2
arg min i

i
Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles:  k 1   k   k

  f (   k )  ci 
k 2
arg min i

i

Known!
Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles:  k 1   k   k

  f (   k )  ci 
2
arg mink i
k Taylor series expansion

i
Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles:  k 1   k   k

  f (   k )  ci 
2
arg mink i
k Taylor series expansion

i

f
2
 
 arg mink   f i ( k )  ik  k  ci  rearrange

i   
Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles:  k 1   k   k

  f (   k )  ci 
2
arg mink i
k Taylor series expansion:

i linear approximation
f
2
 
 arg mink   f i ( k )  ik  k  ci  rearrange

i   

Can you solve this optimization problem?


Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles:  k 1   k   k

  f (   k )  ci 
2
arg mink i
k Taylor series expansion

i

f
2
 
 arg mink   f i ( k )  ik  k  ci  rearrange

i   
 f
2

 arg mink   ik  k  (ci  f i ( k )) 
i   


This is a quadratic function of 


Gauss-Newton Approach
• Optimizing an quadratic function is easy
 f
2

arg mink   ik  k  (ci  f i ( k )) 
i   


• It has an optimal value when the gradient is


zero f f
1
...
f
1 1
1  2  N 1 c1  f i (1 ,..., N )
f 2 f 2 f 2  c  f 2 (1 ,..., N )
...
 N   2
2
1  2
 
   
f M f M f M  N cN  f i (1 ,..., N )

 N  2  N
Gauss-Newton Approach
• Optimizing an quadratic function is easy
 f
2

arg min   ik  k  (ci  f i ( k )) 
i   


• It has an optimal value when the gradient is


zero f1f
...1f 1
1  2  N 1 c1  f i (1 ,..., N )
f 2 f 2 f 2  c  f 2 (1 ,..., N )
...
 N   2
2
1  2
  J 
Δθ b 
f M f M f M  N cN  f i (1 ,..., N )

 N  2  N

Linear equation!
Gauss-Newton Approach
• Optimizing an quadratic function is easy
 f
2

arg min   ik  k  (ci  f i ( k )) 
i   


• It has an optimal value when the gradient is


zero f1f
...1f 1
1  2  N 1 c1  f i (1 ,..., N )
f 2 f 2 f 2  c  f 2 (1 ,..., N )
...
 N   2
2
1  2
  J 
Δθ b 
f M f M f M  N cN  f i (1 ,..., N )

 N  2  N
Gauss-Newton Approach
• Optimizing an quadratic function is easy
 f
2

arg min   ik  k  (ci  f i ( k )) 
i   


• It has an optimal value when the gradient is


zero f1f
...1f 1
1  2  N 1 c1  f i (1 ,..., N )
f 2 f 2 f 2  c  f 2 (1 ,..., N )
...
 N   2
2
1  2
  J  
Δθ b 
f M f M f M  N cN  f i (1 ,..., N )

 N  2  N

  ( J T J ) 1 J T b
Jacobian Matrix
• Jacobian maps the velocity in joint angle space to
velocities in Cartesian space

(x,y)
A small change of θ1 and θ2 results in how
much change of end-effector position (x,y)
θ2

θ1
f1 f1
 x  1  2  1 
    
 y  f 2 f1   2 
1  2
Jacobian Matrix
• Jacobian maps the velocity in joint angle space to
velocities in Cartesian space

(x,y)
A small change of θ2 results in how much
change of end-effector position f=(x,y)
θ2
2 2  2
θ1

x x  x
y y  y
Jacobian Matrix: 2D-link Structure
θ2
l2
l1

θ1 C=(c1,c2)

Base (0,0)

arg min (l1 cos 1  l2 cos(1   2 )  c1 ) 2  (l1 sin 1  l2 sin( 1   2 )  c2 ) 2


1 , 2
Jacobian Matrix: 2D-link Structure
θ2
l2
l1

θ1 C=(c1,c2)

Base (0,0)

arg min (l1 cos 1  l2 cos(1   2 )  c1 ) 2  (l1 sin 1  l2 sin( 1   2 )  c2 ) 2


1 , 2

f1 f2
Jacobian Matrix: 2D-link Structure
θ2
l2
l1

θ1 C=(c1,c2)

Base (0,0)

arg min (l1 cos 1  l2 cos(1   2 )  c1 ) 2  (l1 sin 1  l2 sin( 1   2 )  c2 ) 2


1 , 2

f1 f1 f1


...
f1  l1 cos 1  l2 cos(1   2 ) 1  2  N
f 2  l1 sin 1  l2 sin( 1   2 ) f 2 f 2 f 2
...
1  2  N
   
f M f M f M

1  2  N
Jacobian Matrix: 2D-link Structure
θ2
l2
l1

θ1 C=(c1,c2)

Base (0,0)

arg min (l1 cos 1  l2 cos(1   2 )  c1 ) 2  (l1 sin 1  l2 sin( 1   2 )  c2 ) 2


1 , 2

 l1 sin 1  l2 sin( 1   2 )  l2 sin( 1   2 )


J
l1 cos1  l2 cos(1   2 ) l2 cos(1   2 )
Jacobian Matrix: 2D-link Structure
θ2
l2
l1

θ1 C=(c1,c2)

Base (0,0)

arg min (l1 cos 1  l2 cos(1   2 )  c1 ) 2  (l1 sin 1  l2 sin( 1   2 )  c2 ) 2


1 , 2

 l1 sin 1  l2 sin( 1   2 )  l2 sin( 1   2 )


J
l1 cos1  l2 cos(1   2 ) l2 cos(1   2 )
Jacobian Matrix: 2D-link Structure
θ2
l2
l1

θ1 C=(c1,c2)

Base (0,0)

arg min (l1 cos 1  l2 cos(1   2 )  c1 ) 2  (l1 sin 1  l2 sin( 1   2 )  c2 ) 2


1 , 2

f1  (l1 cos 1  l2 cos(1   2 ))



1 1

 l1 sin 1  l2 sin( 1   2 )  l2 sin( 1   2 )


J
l1 cos1  l2 cos(1   2 ) l2 cos(1   2 )
Jacobian Matrix: 2D-link Structure
θ2
l2
l1

θ1 C=(c1,c2)

Base (0,0)

arg min (l1 cos 1  l2 cos(1   2 )  c1 ) 2  (l1 sin 1  l2 sin( 1   2 )  c2 ) 2


1 , 2
f 2  (l1 sin 1  l2 sin( 1   2 ))

 2  2
 l1 sin 1  l2 sin( 1   2 )  l2 sin( 1   2 )
J
l1 cos 1  l2 cos(1   2 ) l2 cos(1   2 )
Gauss-Newton Approach
Step 1: initialize the joint angles with  0

Step 2: update the joint angles:

 k 1   k   k

Step size: specified by the user


When to stop
Option #1: When the change of solution from previous
iteration to the current one is below a user-specified
threshold.

Option #2: When the number of iteration reaches a


user-specified threshold.

Option #3: either #1 or #2 is satisfied.


Iterative Approaches for IK
Mathematically, we can formulate this as an
optimization problem:

arg min


 if ( )  ci 2

The above problem can be solved by many


nonlinear optimization algorithms:
- Steepest descent
- Gauss-newton
- Levenberg-marquardt, etc
C/C++ Optimization Library
• levmar : Levenberg-Marquardt nonlinear least
squares algorithms in C/C+
- Works with/without analytical Jacobian matrix
- Speeds up the optimization process with analytical
Jacobian matrix.

• http://www.ics.forth.gr/~lourakis/levmar/
Another Example
• A 2D lamp character 3

c3
2 A

c2

1
c1

c0 ( x, y, 0 )

62
Another Example
• A 2D lamp character l3

l2 A

l1

l0

63
Forward Kinematics
• A 2D lamp character 3

c3
2 A

? c2

1
c1

c0 ( x, y, 0 )
Given ( x, y,0 ,1 , 2 ,,3 ) , how to compute the global position
of the point A? 64
Forward Kinematics
• A 2D lamp with 6 degrees of freedom
3 lower arm

c3
middle arm
2 p0

?
Upper arm
c2

1
c1
base

c0 ( x, y, 0 )
f ( x, y,0 ,1,2 ,3 )  T ( x, y ) R(0 )T (0, l0 ) R(1 )T (l1,0) R(2 )T (l2 ,0) R(3 ) p0
Inverse Kinematics
• A 2D lamp with 6 degrees of freedom
3 lower arm

c3
middle arm
2 p0

c2 If you do inverse kinematics with


Upper arm
position of this point
1
c1
base What’s the size of Jacobian matrix?

c0 ( x, y, 0 )
f ( x, y,0 ,1,2 ,3 )  T ( x, y ) R(0 )T (0, l0 ) R(1 )T (l1,0) R(2 )T (l2 ,0) R(3 ) p0
Inverse Kinematics
• A 2D lamp with 6 degrees of freedom
3 lower arm

c3
middle arm
2 p0

c2 If you do inverse kinematics with


Upper arm
position of this point
1
c1
base What’s the size of Jacobian matrix?

c0 ( x, y, 0 ) 2-by-6 matrix

f ( x, y,0 ,1,2 ,3 )  T ( x, y ) R(0 )T (0, l0 ) R(1 )T (l1,0) R(2 )T (l2 ,0) R(3 ) p0
Human Characters

f  T ( x0 , y0 , z0 ) R( 0 ) R(0 ) R( 0 )T10 R(1 ) R(1 ) R(1 )T21 R( 2 )T32 R( 3 ) R(3 ) x
68
Inverse Kinematics
• Analytical solution only works for a fairly
simple structure

• Iterative approach needed for a complex


structure
Inverse Kinematics
• Is the solution unique?
• Is there always a good solution?
Ambiguity of IK
• Multiple solutions
Ambiguity of IK
• Infinite solutions
Failures of IK
• Solution may not exist
Inverse Kinematics
• Generally ill-posed problem when the number of
Dofs is higher than the number of constraints
Inverse Kinematics
• Generally ill-posed problem when the number of
Dofs is higher than the number of constraints

• Additional objective
– Minimal Change from a reference pose θ0
Inverse Kinematics
• Generally ill-posed problem when the number of
Dofs is higher than the number of constraints

• Additional objective
– Minimal Change from a reference pose θ0

 f i ( )  ci     0
2 2
arg min

i
Inverse Kinematics
• Generally ill-posed problem when the number of
Dofs is higher than the number of constraints

• Additional objective
– Minimal Change from a reference pose θ0

 f i ( )  ci     0
2 2
arg min

i

Satisfy the constraints Minimize the difference between the


solution and a reference pose
Inverse Kinematics
• Generally ill-posed problem when the number of
Dofs is higher than the number of constraints

• Additional objective
– Minimal Change from a reference pose θ0
– Naturalness g(θ) (particularly for human characters)
Inverse Kinematics
• Generally ill-posed problem when the number of
Dofs is higher than the number of constraints

• Additional objective
– Minimal Change from a reference pose θ0
– Naturalness g(θ) (particularly for human characters)

 f i ( )  ci  g ( )
2
arg min

i
Inverse Kinematics
• Generally ill-posed problem when the number of
Dofs is higher than the number of constraints

• Additional objective
– Minimal Change from a reference pose θ0
– Naturalness g(θ) (particularly for human characters)

 f i ( )  ci  g ( )
2
arg min

i

Satisfy the constraints How natural is the solution pose?


Interactive Human Character Posing
• Video (click here)
Summary of IK
• Very simple structure allows an analytic
solution

• Most of complex articulated figures


requires a numerical solution

• May not always get the “right” solution


- need additional objectives

S-ar putea să vă placă și