Scale a Joint Velocity Command to Its Limits

~12 mincode completion

Implement scale_to_limits(q_dot, q_dot_max) returning the scaled velocity array, the same length as the input.

Examples

Already legal: the command passes through untouched, not sped up

Input
scale_to_limits([0.5, -0.5], [1, 1])
Output
[0.5, -0.5]

One joint over the limit: both are halved, so the direction survives

Input
scale_to_limits([2, 1], [1, 1])
Output
[1, 0.5]

A stationary joint must not cause a division by zero

Input
scale_to_limits([4, 0], [2, 1])
Output
[2, 0]

Hints

Hint 1

Convert the input with before doing elementwise work.

Hint 2

Watch for this: clipped each joint independently which changes the direction of travel.

Requirements

  • q_dot: (n,) commanded joint velocities

  • q_dot_max: (n,) per-joint speed limits, all positive

  • Return (n,) scaled command, parallel to q_dot

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~12 min

6 employers weight this skill

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

Python
import numpy as np


def scale_to_limits(q_dot, q_dot_max):
    """
    Uniformly slow a joint velocity command until every joint is legal.

    Args:
        q_dot:     (n,) commanded joint velocities
        q_dot_max: (n,) per-joint speed limits, all positive

    Returns:
        (n,) scaled command, parallel to q_dot
    """
    # 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.