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

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

static const double NOISE_FLOOR = 0.25;
static const double RMS_MAX = 50.0;

/*
 * vibration_rms
 * Chain order: 1     Cost class: p1-d5-w1-c0
 * EML depth:   5  Drift risk: MEDIUM
 * Dynamics:    0 osc, 0 decay  (predicted_r=0)
 * FPGA est:   5 MAC, 0 exp, 0 ln, 0 trig -> 10 cy @ 32-bit
 */
double vibration_rms(double ax, double ay) {
    assert(((mg_abs(ax) <= 30.0)) && "vibration_rms: refinement violated on ax: (mg_abs(ax) <= 30.0)");
    assert(((mg_abs(ay) <= 30.0)) && "vibration_rms: refinement violated on ay: (mg_abs(ay) <= 30.0)");
    double mag = mg_sqrt((((ax * ax) + (ay * ay)) + NOISE_FLOOR));
    return mg_clamp(mag, 0.0, RMS_MAX);
}
