// Generated by EML-lang Java backend
// Source module: aerospace_actuator_guard_band
// Kernel digest: sha256:0b0ef5a5baecb59acc7d28dc64bc959d9f3378cfbc278204c737cef5bc755aaa
// Functions:     1
// Constants:     0

public final class AerospaceActuatorGuardBand {

    private AerospaceActuatorGuardBand() {}  // utility class -- no instances

    /**
     * actuator_command_within_band
     * <p>Pfaffian profile: pfaffian_r=0, cost_class=p0-d4-w0-c0, drift_risk=LOW.</p>
     *
     * @param error (type Real)
     * @param integral (type Real)
     * @param deriv (type Real)
     * @param kp (type Real)
     * @param ki (type Real)
     * @param kd (type Real)
     * @param u_min (type Real)
     * @param u_max (type Real)
     * @return Real
     * @forge.requires (u_min <= u_max)
     * @forge.ensures (u_min <= result)
     * @forge.ensures (result <= u_max)
     *  source obligations for actuator_command_within_band: {O1, O2}
     *    O1 [43d7c3ff9568] -> PRESERVED (equivalent)  IllegalStateException before return
     *         build: unconditional -- a thrown IllegalStateException, NOT `assert` -- so no `-ea` and no default-off switch
     *    O2 [ca2e303109b7] -> PRESERVED (equivalent)  IllegalStateException before return
     *         build: unconditional -- a thrown IllegalStateException, NOT `assert` -- so no `-ea` and no default-off switch
     * @forge.verify lean theorem=actuator_command_within_band
     */
    public static double actuator_command_within_band(double error, double integral, double deriv, double kp, double ki, double kd, double u_min, double u_max) {
        if (!((u_min <= u_max))) throw new IllegalArgumentException("actuator_command_within_band: requires violated: (u_min <= u_max)");
        double result = Math.max(u_min, Math.min((((kp * error) + (ki * integral)) + (kd * deriv)), u_max));
        if (!((u_min <= result))) throw new IllegalStateException("actuator_command_within_band: ensures violated");
        if (!((result <= u_max))) throw new IllegalStateException("actuator_command_within_band: ensures violated");
        return result;
    }

}
