Based on your comment in Teams: @ Qd = 450 in your data set... ~8 seconds spent between drain and fill that suggests maybe our just-in-time is a bit off - maybe should have started fill immediately.
5% seems like a reasonable max step. I don't think we want to go to ramp up/down states if > 5% change. I think we just want to limit the change to max 5% for a single control interval.
Who would call this function? DD is calling handle function below, not this one. I think that handle function is only one calling this, so should be private (static).