Differential Drive Forward Kinematics

~10 mincode completion

Implement diff_drive_velocity(r, L, omega_left, omega_right) returning the array [v, omega].

Examples

Both wheels at the same speed: straight ahead, no turn

Input
diff_drive_velocity(0.1, 0.5, 10, 10)
Output
[1, 0]

Equal and opposite: a spin on the spot, no forward motion

Input
diff_drive_velocity(0.1, 0.5, -10, 10)
Output
[0, 4]

Left wheel stopped: the base pivots about it

Input
diff_drive_velocity(0.1, 0.5, 0, 10)
Output
[0.5, 2]

Hints

Hint 1

Convert the input with before doing elementwise work.

Hint 2

A common slip here: divided the turn rate by 2L instead of L.

Requirements

  • r: wheel radius

  • L: distance between the wheels

  • omega_left: left wheel angular velocity, rad/s

  • omega_right: right wheel angular velocity, rad/s

  • Return (2,) array [v, omega]: forward speed and turn rate

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

6 employers weight this skill

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

Python
import numpy as np


def diff_drive_velocity(r, L, omega_left, omega_right):
    """
    Body velocity of a differential-drive base from its wheel speeds.

    Args:
        r:           wheel radius
        L:           distance between the wheels
        omega_left:  left wheel angular velocity, rad/s
        omega_right: right wheel angular velocity, rad/s

    Returns:
        (2,) array [v, omega]: forward speed and turn rate
    """
    # 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.