Trapezoidal Velocity Profile

~16 mincode completion

Implement trapezoidal_profile(distance, v_max, a_max) for a non-negative , returning the array [total_time, cruise_time, peak_velocity].

Examples

A long move: ramp up, cruise for 3 s, ramp down

Input
trapezoidal_profile(10, 2, 1)
Output
[7, 3, 2]

A short move: triangular, and the speed limit is never reached

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

Exactly at the boundary: a trapezoid with no cruise phase

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

Hints

Hint 1

Take the square root at the end, not inside the sum.

Hint 2

Watch for this: assumed the cruise phase always exists and returned a negative cruise time.

Requirements

  • : move length, >= 0

  • v_max: speed limit

  • a_max: acceleration limit

  • Return (3,) array [total_time, cruise_time, peak_velocity]

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 trapezoidal_profile(distance, v_max, a_max):
    """
    Timing of a trapezoidal (or triangular) velocity profile.

    Args:
        distance: move length, >= 0
        v_max:    speed limit
        a_max:    acceleration limit

    Returns:
        (3,) array [total_time, cruise_time, peak_velocity]
    """
    # 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.