Skip to content

Kinematics

Peter Corke edited this page Oct 22, 2026 · 12 revisions

Forward kinematics

Forward kinematics (FK) is the pose of the end-effector given the joint coordinates. It can be computed for robots of the DHRobot or ERobot class

T = robot.fkine(q)

where T is an SE3 instance.

T = robot.fkine_all(q)

where T is an SE3 instance with multiple values, the pose of each link frame, from the base T[0] to the end-effector T[-1].

Inverse kinematics

Inverse kinematics (IK) is the joint coordinates required to achieve a given end-effector pose. The function is not unique, and there may be no solution.

RTB's numerical IK solvers are implemented as classes in roboticstoolbox/robot/IK.py (IK_NR, IK_LM, IK_GN, IK_QP), each with a .solve(ets, Tep) method. Robot and ERobot also expose a convenience method per solver, so you don't need to import and instantiate the class yourself for the common case:

Method Solver class Type Joint limits Description
ikine_analytic AnalyticIK analytic yes (rejects solutions outside) Any six-joint DHRobot with revolute joints, see below. Needs [ik] extra
ikine_a — analytic no For specific DHRobots only (the Puma 560), see below
ikine_NR IK_NR numeric yes Newton-Raphson
ikine_LM IK_LM numeric yes Levenberg-Marquadt, with a choice of damping-matrix method (chan/wampler/sugihara)
ikine_GN IK_GN numeric yes Gauss-Newton
ikine_QP IK_QP numeric yes Quadratic-programming based (requires the qp optional dependency, qpsolvers/quadprog)

Equivalently, construct the solver class directly and reuse it across multiple calls:

solver = rtb.IK_LM()
sol = solver.solve(robot.ets(), Tep)

All methods return an IKSolution dataclass (roboticstoolbox/robot/IK.py):

Attribute Type Description
q ndarray(n) Joint coordinates for the solution — not valid unless success is True
success bool True if a solution was found
iterations int Number of iterations performed
searches int Number of searches performed (a search restarts from a fresh initial guess after ilimit iterations without convergence)
residual float Final value of the cost function
reason str Reason for failure, if applicable

IKSolution also supports tuple-unpacking (q, success, iterations, searches, residual, reason = sol) for backward compatibility with the older named-tuple return.

Numerical solutions

These IK solvers minimise a scalar measure of error between the current and the desired end-effector pose. The measure is the squared-norm of a 6-vector comprising:

  • translational error (a 3-vector)
  • the orientation error as an Euler vector (angle/axis form encoded as a 3-vector)

Each solver supports joint-limit avoidance and a secondary manipulability-maximisation objective via the kq/km gain parameters — see the solver classes' docstrings (IK_NR, IK_LM, IK_GN, IK_QP in roboticstoolbox/robot/IK.py) for the full parameter list and the underlying maths.

There's no current relative-performance comparison across solvers/methods/joint-limit settings on this page — the one that used to be here measured the now-removed SciPy-minimize-based ikine_min solver (and hasn't been replaced with numbers for the current IK_NR/IK_LM/IK_GN/IK_QP classes). If you need real numbers, benchmark against your own robot/use case — the relative cost differences (e.g. ikine_a being much faster than any numerical solver when it's available) are still qualitatively true.

Fast C++ solvers, ik_XX

ETS also has ik_NR, ik_LM and ik_GN, the same algorithms written in C++. They are much faster, but they have limits: they need the compiled extension, so they are not available in the browser (JupyterLite, Pyodide), and they cannot be used for a sequence that has SymPy parameters or a joint with an offset (see below). They raise an error that says so. The ikine_XX methods are Python, have no such limits, and are the ones to use in those cases.

Analytical solutions

robot.ikine_analytic(T) solves a six-joint DHRobot in closed form, with no starting guess and with all the solutions found, returning the one nearest q0. The equations are derived symbolically the first time for each robot and then kept.

  • An arm with a spherical wrist, or with three parallel axes, has a closed-form solution.
  • Any other six-axis arm with revolute joints (a Kinova Jaco, say) is solved by the method of Raghavan and Roth, which gives up to 16 solutions.

It needs SymPy: pip install roboticstoolbox-python[ik] (which adds python-flint to make the derivation much faster). Solutions that violate the joint limits are rejected unless joint_limits=False. robot.analytic_ik() returns the solver itself, which can also write the solution out as source code. The notebook ik-symbolic is a worked example.

A hand-written solution for a spherical-wrist arm

The older route is still there. The DH/Puma560 model has an analytic solution method ikine_a(T, config), and one can be added to any other robot class, including any custom class that you might write.

For the class of robots that have 6 joints and a spherical wrist, the Toolbox provides additional support. First define a method in your class

def ikine_a(self, T, config):
    return self.ikine_6s(T, config, func)

where:

  • ikine_6s is a method of the DHRobot class
  • func is a local function func(robot, T, config) that solves for the first three joints, given T which is the pose of the wrist centre with respect to the base.
  • config is a pose configuration string. For example, the Puma robot defines this as
Letter Meaning
l Choose the left-handed configuration
r Choose the right-handed configuration
u Choose the elbow up configuration
d Choose the elbow down configuration
n Choose the wrist not-flipped configuration
f Choose the wrist flipped configuration

but you can choose whatever is appropriate for your robot.

Base and tool transforms

All robot classes support a base transform. This defines the pose of the robot's base with respect to the world frame and is by default null transform (identity matrix).

DHRobot objects support a tool transform. This defines the tip of the robot's end-effector with respect to the final link frame, which is typically inside the spherical wrist. By default this is a null transform (identity matrix). Note that some robot models describe the tool transform using DH parameters, see Section 5 of this tutorial.

Joint offsets

DHRobot support a joint offset which is important since often the required zero-angle configuration is not what the user or robot controller considers the zero-angle configuration, due to the constraints imposed by DH notation.

For forward kinematics the joint offsets are added to yield the "kinematic" joint angles, and then the forward kinematics are computed. This occurs within the A method of the DHLink class. This means that the offsets are the kinematic joints angles corresponding to the user's zero-angle configuration.

Jacobian calculation use the A method so joint offsets are taken into consideration.

Numerical inverse kinematics use the fkine method so joint offsets are taken into consideration. Analytical inverse kinematics explicitly subtract the offset in the ikine_6s method.

Joint offsets in an ETS

An ET that is a joint can also carry an offset, so that the angle (or displacement) is q + offset, or -q + offset if the joint is flipped. Merging a joint with an adjacent constant of the same kind, Rz(0.5) * Rz(q), gives Rz(q + 0.5). fkine and the Jacobian handle it; the C++ ik_XX solvers do not (see above).

Editing an ETS

An ETS can be rearranged without changing the robot it describes. Each of these has a form that returns a new ETS (merged, swapped, replaced) and one that changes it in place.

  • merge(i) combines term i with the next, if they are the same kind on the same axis: Rx(a) * Rx(b) becomes Rx(a + b). A term that comes to exactly zero (for SymPy, a whole number of turns of a rotation) is removed.
  • swap(i) exchanges two adjacent terms when they commute. It also moves a term across a constant quarter or half turn, changing the other term to suit.
  • replace(i, axis) re-expresses a term on another axis using a quarter turn, for example Rx(q) as Ry(pi/2) * Rz(q) * Ry(-pi/2).

These are the building blocks for converting an ETS to DH parameters.

Robots with multiple end effectors

For a branched robot (or one with a gripper attached as a named end effector), fkine and the ikine_* solvers accept end/start keyword arguments to select which branch to compute:

T = robot.fkine(q, end=link, start=None)

where link is a Link/Gripper object, or its name as a string. q in this case is compact: only the joint values for that one branch, ordered from start to end — not the whole robot's q. See the fkine docstring in roboticstoolbox/robot/RobotKinematics.py for the full parameter semantics, and ikine_NR/ikine_LM/ikine_GN/ikine_QP above, which take the same end/start arguments.

Clone this wiki locally