/*
 * Generated by EML-lang C backend
 * Source module: aerospace_actuator_guard_band
 * Source file:   /home/monogate/monogate/forge/examples/actuator_guard.eml
 * Functions:     1
 * Constants:     0
 * Types:         0
 */

#include "libmonogate.h"
#include <stdint.h>
#include <math.h>
#include <assert.h>

/*
 * actuator_command_within_band
 * Chain order: 0     Cost class: p0-d4-w0-c0
 * EML depth:   4  Drift risk: LOW
 * Dynamics:    0 osc, 0 decay  (predicted_r=0)
 * FPGA est:   4 MAC, 0 exp, 0 ln, 0 trig -> 8 cy @ 32-bit
 */
double actuator_command_within_band(double error, double integral, double deriv, double kp, double ki, double kd, double u_min, double u_max) {
    assert(((u_min <= u_max)) && "actuator_command_within_band: requires ((u_min <= u_max))");
    return mg_clamp((((kp * error) + (ki * integral)) + (kd * deriv)), u_min, u_max);
}
