One PID Step
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_kprev_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
Try similar problems(4)
Industrial Robotics: Kinematics and Control · ~12 min
Industrial Robotics: Kinematics and Control · ~12 min
Industrial Robotics: Kinematics and Control · ~10 min
Industrial Robotics: Kinematics and Control · ~14 min
Where this shows up
6 employers weight this skill
4 autonomy companies, 2 defense companies. Top match scores 93.
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