Forward Kinematics of a DH Chain

~16 mincode completion

Implement dh_chain(params), where params is an array of rows , returning the 4x4 base-to-tool transform.

Examples

One link, a = 1: a pure translation along x

Input
dh_chain([[0, 0, 1, 0]])
Output
[[1, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]

Two straight links: the reach adds up

Input
dh_chain([[0, 0, 1, 0], [0, 0, 1, 0]])
Output
[[1, 0, 0, 2], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]

First joint at 90 degrees: the tip is at (0, 2), not (2, 0)

Input
dh_chain([[1.5707963267948966, 0, 1, 0], [0, 0, 1, 0]])
Output
[[0, -1, 0, 0], [1, 0, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]

Hints

Hint 1

Use a matrix product rather than nested loops, and check which operand transposes.

Hint 2

Watch for this: multiplied the link transforms in reverse order.

Requirements

  • params: (n, 4) array, row i is [theta, d, a, alpha] for link i

  • Return (4, 4) product A_1 A_2 ... A_n

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~16 min

6 employers weight this skill

4 autonomy companies, 2 defense companies. Top match scores 92.

Python
import numpy as np


def dh_chain(params):
    """
    Base-to-tool transform of a Denavit-Hartenberg chain.

    Args:
        params: (n, 4) array, row i is [theta, d, a, alpha] for link i

    Returns:
        (4, 4) product A_1 A_2 ... A_n
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.