This section of the library contains useful mathematical functions.
- Backward Substitution
- Forward Substitution
- Positive Definite Matrices
- QR Decomposition
- Simple QP Solver
- Skew Symmetric Class
For a system of equations:
instead of directly inverting
Eigen::VectorXd x = backward_subsitution(y,U, tolerance);
which is faster and more numerically stable. The tolerance
argument is the level of precision for handling singularities.
Eigen can also solve triangular systems, but this function was written for more precise control over singularities.
For a system of equations:
instead of directly inverting
Eigen::VectorXf x = forward_subsitution(y,L, tolerance);
which is faster and more numerically stable. The tolerance
argument is the level of precision for handling singularities.
Eigen can also solve triangular systems, but this function was written for more precise control over singularities.
Many control and optimisation problems are predicated on the fact that a matrix
- It is symmetric:
$\mathbf{A = A^\mathrm{T}}$ , and - Its determinant is positive:
$det(\mathbf{A}) > 0$ (i.e. not singular). For example, the inertia matrix of a robot arm$\mathbf{M(q)}\in\mathbb{R}^{n\times n}$ must be positive definite which follows from the fact that kinetic energy is always positive:
where
A simple function is defined in Math.h
that can be used to check a matrix during runtime. For example:
Eigen::MatrixXd A; \\ Declare a matrix.
...
if(is_positive_definite(A))
{
\\ Do something
}
A matrix
where:
-
$\mathbf{Q}\in\mathbb{O}(m)$ is an orthogonal matrix:$\mathbf{Q^\mathrm{T}Q = I}$ , and -
$\mathbf{R}\in\mathbb{R}^{n\times n}$ is an upper-triangular matrix:
Eigen already has several QR decomposition aglorithms available. A function utilizing the Schwarz-Rutishauser algorithm is provided in this library. It returns only
QRdecomposition decomp<float> = schwarz_rutishauser(A);
Eigen::MatrixXf Q = decomp.Q;
Eigen::MatrixXf R = decomp.R;
or alternatively:
const auto &[Q, R] = schwarz_rutishauser(A);
This was done deliberately for more precise handling of singularities in Math.h
.
Many control problems in robotics can be solved using quadratic programming (QP), or convex optimisation of the form:
where:
-
$\mathbf{x}\in\mathbb{R}^\mathrm{n}$ is the decision variable, -
$\mathbf{H = H^\mathrm{T}}\in\mathbb{R}^\mathrm{n\times n}$ is a weighting matrix, -
$\mathbf{f}\in\mathbb{R}^\mathrm{n}$ is the linear component of the quadratic equation, -
$\mathbf{B}\in\mathbb{R}^\mathrm{c\times n}$ is a constraint matrix, and -
$\mathbf{z}\in\mathbb{R}^\mathrm{c}$ is a constraint vector.
SimpleQPSolver is a single header file that is automatically downloaded in to RobotLibrary. It contains useful functions for solving QP problems, both constrained and uncontrained.
The cross-product of two vectors
where
Eigen
has an in-built function for the cross-product of 3D vectors: a.cross(b)
, but does not have a skew-symmetric matrix representation. A skew-symmetric class is available in this library for convenient multiplication of a skew-symmetric matrix and another matrix
For example, if we have a 3D vector we convert it to a skew-symmetric matrix object for use:
Eigen::Vector3d a = ...; // Declaration of a 3d vector.
SkewSymmetric<double> S(a); // Create skew-symmetric matrix object.
...
Eigen::Matrix<double,3,Eigen::Dynamic> product = S * someOtherMatrix; // Matrix multiplication of skew-symmetric matrix with another.