All problems
MPC Constraint Projection
Problem
Project a control sequence onto box and rate constraints.
First clamp every control into [lo, hi], then enforce the slew-rate limit |u_i - u_{i-1}| <= rate sequentially from left to right. Return the projected list.
Hint
Box clipping comes first; rate limiting then sees the clipped values.
Test cases
case 1
in: [[0,5,-5],-1,1,0.5]
expected: [0,0.5,0]
case 2
in: [[0,0.1,0.2],-1,1,0.05]
expected: [0,0.05,0.1]
case 3
in: [[0],-1,1,0.5]
expected: [0]
Starter codePython
def mpc_project(u, lo, hi, rate):
# Your code here
pass3 test cases · run your code against them in the editor