Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For...

32
Robotics: Science and Systems Zhibin Li School of Informatics University of Edinburgh Optimization II

Transcript of Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For...

Page 1: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Robotics: Science and Systems

Zhibin LiSchool of Informatics

University of Edinburgh

Optimization II

Page 2: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Content

2

❏ Constrained optimization❏ Constrained least square❏ Quadratic Optimization (QP)

❏ Nonlinear optimization❏ Application for dynamic walking❏ Application for task space planning of a robot arm

Page 3: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Recap: What Tools Do We Need?

3Optimisation:

General: How do I minimise some cost function?QP: How do I move the whole body?

Page 4: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Constrained linear least squares

4

Page 5: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Least squares with constraintsSimple least squares with equality constraints:

where is the objective function, and is the equality constraint.Additional constraints may also exist:Inequality constraint, must satisfyThe vector must satisfy the vector inequalities andare lower and upper bounds.

5

Page 6: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Matlab exerciseFunction: lsqlin

Solve constrained linear least-squares problems with bounds or linear constraints.Exercise with the examples here.

6

Page 7: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Comparison with Tikhonov regularisationConstrained Least Squares explicitly specifies the constraints, while Tikhonov regularisation only minimize the deviation from a nominal.When the range of solution is large, and boundary limits are far away to “hit”, both may yield the same results. However, if constraints are hard, then explicit constraints are necessary.

7

Page 8: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Quadratic Programming (QP)

8

Page 9: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Quadratic Programming (QP)QP is quadratic optimization problem that optimizes (minimizes or maximizes) a quadratic function of variables subject to linear constraints on these variables.The objective of QP is to find vector , that will

where means that every element of the vector is less than or equal to the corresponding element of vector . (All vectors are column vectors by default) 9

Page 10: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Quadratic Programming (QP)The objective of QP is to find vector , that will

: m-dimensional real number column vector : Hessian matrix, symmetric* and positive (semi-)definite : real matrix A : m-dimensional real number column vector* In linear algebra, a symmetric matrix is a square matrix that is equal to its transpose, so 10

Page 11: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Quadratic Programming (QP)Note that every equality constraint can be equivalently replaced by a pair of inequality constraints

Therefore, equality constraints are somewhat redundant mathematically. However, the concept of equality constraints are useful when it maps the real world problems into mathematical formulations.

11

Page 12: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Quadratic Programming (QP)Common methods for QP solutions:1. Interior-point2. Active-set3. Trust-region-reflective

Matlab: quadprogC++: qpOASES

12

Page 13: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Non-negative least squares (NNLS) is a constrained version of the least squares problem. The NNLS problem is equivalent to a quadratic programming problem.

An example how to transform a minimization problem (LS) into a QP form.Quiz: whiteboard exercise: quadratic multiplication of vectors.

LS and QP

13

Page 14: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Non-negative least squares (NNLS) is a constrained version of the least squares problem. The NNLS problem is equivalent to a quadratic programming problem.

Note that , since this is dot product of two vectors: multiply corresponding elements of each element, then add up the products. The result is a scalar value.

LS and QP

14

Page 15: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

LS and QP

Since is a non-negative quantity, so minimizing is equal to minimizing , treating as a non-negative offset. Hence, it is equivalent to a QP problem:

where and 15

Page 16: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Applications of QPUsing optimization to coordinate all joints (whole body control) of a humanoid robot. (Detailed formulation will be covered by Robot Learning and Sensorimotor Control, semester 2 )

16

Page 17: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Nonlinear optimization

17

Page 18: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Nonlinear optimizationOften, there are problems that are nonlinear, thus require nonlinear optimizers.

Cost function J can be more complex, and are not necessarily the norm of vectors, eg forward kinematics.

❏ Matlab: optimization toolbox has solvers for linear, quadratic, integer, and nonlinear optimization problems. For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon can find the solution.

❏ C++: NLopt

18

Page 19: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Matlab functions for unconstrained optimizationFunctions1. fminsearch: Find minimum of unconstrained multivariable function

using derivative-free method2. fminunc: Find minimum of unconstrained multivariable function

Note: these are actually nonlinear programming solvers.

19

Page 20: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Matlab functions for constrained optimizationFunctions1. fminbnd: find minimum of single-variable function on fixed

interval2. fmincon: find minimum of constrained nonlinear multivariable

function3. fseminf: find minimum of semi-infinitely constrained multivariable

nonlinear function

20

Page 21: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Formulating constraints: QP caseUsually qpOASES expects QPs to be formulated in the following standard form:

where we can express the equality constraint by setting lbA and ubA the same.

21

Page 22: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Formulating constraints: fmincon caseHowever, fmincon has different interface or formalization of the constraints, as shown below:

Quiz: how to formulate inequality constraints in the form ?

22

Page 23: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Application of nonlinear optimization (fmincon)

23

Page 24: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Task space control using optimization

Question: how to formulate inverse kinematics problem considering the constraints, eg joint angle limit?

24

AUTOMATICA

Problem Formulation?

Page 25: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Application of nonlinear optimization (fmincon)Fmincon example: task space control, eg inverse kinematics, using optimizationProblem Formulation

Recall Tikhonov regularization:

Our problem formulation of inverse kinematics problem considering the constraints is somewhat similar.

25

Page 26: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Problem Formulation

q: joint configurationq0, qmin, qmax: initial, minimum, maximum joint configurationsF(q), O(q): forward kinematics, returns end effector position and orientationyd, vecd: desired task space or workspace position, orientationQp, Qr, Qj are the weighting matrices for workspace position, rotation, and joint/configuration space respectively.

Application of nonlinear optimization (fmincon)

26

Page 27: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Application of nonlinear optimization (fmincon)

Initial configuration of robot arm at q0

V shape is the workspace trajectory

27

Page 28: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Application of nonlinear optimization (fmincon)Optimization only over end-effector position and minimum change of joint angles.

Qp = 1;Qr = 0; (orientation is NOT controlled)Qj = 1e-6; qmin : -pi/2qmax : pi/2

28

Page 29: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Application of nonlinear optimization (fmincon)Optimization only over end-effector position and minimum change of joint angles.

Qp = 1;Qr = 0; (orientation is NOT controlled)Qj = 5e-3; ⇐ Increase weight for q0qmin : -pi/2qmax : pi/2

29Close to initial configuration

Page 30: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Application of nonlinear optimization (fmincon)

30

Optimization of all terms:

Qp = 1;Qr = 1; (note: orientation is controlled)Qj = 1e-6; qmin : -pi/2qmax : pi/2

What is the problem here?

Page 31: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Application of nonlinear optimization (fmincon)

31

Optimization of all terms:

Qp = 1;Qr = 1; (note: orientation is controlled)Qj = 1e-6; qmin : [-150; -90; -90; 0; -90; -150]/180*piqmax : [150; 90; 90; 150; 90; 150]/180*pi

Singularity

Page 32: Robotics: Science and Systemswcms.inf.ed.ac.uk/ipab/rss/lecture-notes-2018-2019/15 RSS...For example, fmincon is a very powerful tool, if the problem is well formulated, usually fmincon

Application of nonlinear optimization (fmincon)

32

Same setting for optimization, only change the task space V trajectory to be within workspace.The optimization scheme works nicely, considering the minimum deviation from its home position, minimum error of pose (position & orientation), as well as the joint limits!