One PID Step

~12 mincode completion

Implement pid_step(error, prev_error, integral, kp, ki, kd, dt) returning the array [u, new_integral].

Examples

Proportional only: u = 1.5 * 2, integral still accumulates

Input
pid_step(2, 0, 0, 1.5, 0, 0, 0.1)
Output
[3, 0.2]

Integral only: the updated integral, not the old one, drives u

Input
pid_step(1, 1, 0.5, 0, 2, 0, 0.5)
Output
[2, 1]

Derivative only: (1 - 0.5) / 0.1 = 5, times 0.2

Input
pid_step(1, 0.5, 0, 0, 0, 0.2, 0.1)
Output
[1, 0.1]

Hints

Hint 1

Convert the input with before doing elementwise work.

Hint 2

Watch for this: used the old integral in the output.

Requirements

  • error: current error e_k

  • prev_error: previous error e_{k-1}

  • integral: accumulated integral before this step

  • : time step

  • Return array [u, new_integral]

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 pid_step(error, prev_error, integral, kp, ki, kd, dt):
    """
    One discrete PID update.

    Args:
        error:      current error e_k
        prev_error: previous error e_{k-1}
        integral:   accumulated integral before this step
        kp, ki, kd: gains
        dt:         time step

    Returns:
        array [u, new_integral]
    """
    # 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.