<!DOCTYPE module SYSTEM "module.dtd">

<module name="stabilization_indi" dir="stabilization">
  <doc>
    <description>
      Full INDI stabilization controller for rotorcraft
    </description>
    <section name="RC_SETPOINT" prefix="STABILIZATION_ATTITUDE_">
      <define name="SP_MAX_PHI"   value="45." description="max setpoint for roll angle" unit="deg"/>
      <define name="SP_MAX_THETA" value="45." description="max setpoint for pitch angle" unit="deg"/>
      <define name="SP_MAX_R"     value="90." description="max setpoint for yaw rate" unit="deg/s"/>
      <define name="DEADBAND_R"   value="250" description="deadband on yaw rate input"/>
    </section>
    <section name="STABILIZATION_ATTITUDE_INDI" prefix="STABILIZATION_INDI_">
      <define name="G1_ROLL" value="{20 , -20, -20 , 20 }" description="control effectiveness of every actuator on the roll axis"/>
      <define name="G1_PITCH" value="{14 , 14, -14 , -14 }" description="control effectiveness of every actuator on the pitch axis"/>
      <define name="G1_YAW" value="{-1, 1, -1, 1}" description="control effectiveness of every actuator on the yaw axis"/>
      <define name="G1_THRUST" value="{-.4, -.4, -.4, -.4}" description="control effectiveness of every actuator on the thrust axis"/>
      <define name="G2" value="{-60.0,   60.0,  -60.0,  60.0}" description="control effectiveness of every actuator derivative on the yaw axis (important for propellers with strong torque changes)"/>
      <define name="REF_ERR_P" value="600.0" description="reference acceleration"/>
      <define name="REF_ERR_Q" value="600.0" description="reference acceleration"/>
      <define name="REF_ERR_R" value="600.0" description="reference acceleration"/>
      <define name="REF_RATE_P" value="28.0" description="reference acceleration"/>
      <define name="REF_RATE_Q" value="28.0" description="reference acceleration"/>
      <define name="REF_RATE_R" value="28.0" description="reference acceleration"/>
      <define name="MAX_R" value="120.0" description="max yaw rate" unit="deg/s"/>
      <define name="FILT_CUTOFF" value="8.0" description="second order cutoff parameter"/>
      <define name="ESTIMATION_FILT_CUTOFF" value="8.0" description="second order cutoff parameter"/>
      <define name="ACT_DYN" value="{0.1, 0.1, 0.1, 0.1}" description="actuator dynamics"/>
      <define name="ACT_IS_SERVO" value="{0,0,0,0}" description="1 for every actuator that is a servo"/>
      <define name="ACT_RATE_LIMIT" value="{9600,9600,9600,9600}" description="rate limit in PPRZ units per timestep (depends on control frequency)"/>
      <define name="ACT_PREF" value="{0.0, 0.0, 0.0, 0.0}" description="preferred (low energy) actuator value. Important when the system is over-determined!"/>
      <define name="USE_ADAPTIVE" value="FALSE|TRUE" description="enable adaptive gains"/>
      <define name="ADAPTIVE_MU" value="0.0001" description="adaptation parameter"/>
    </section>
  </doc>
  <settings>
    <dl_settings>
      <dl_settings NAME="indi">
        <dl_setting var="reference_acceleration.err_p" min="0" step="1" max="2500" shortname="kp_p" param="STABILIZATION_INDI_REF_ERR_P"/>
        <dl_setting var="reference_acceleration.rate_p" min="0" step="0.1" max="100" shortname="kd_p" param="STABILIZATION_INDI_REF_RATE_P"/>
        <dl_setting var="reference_acceleration.err_q" min="0" step="1" max="2500" shortname="kp_q" param="STABILIZATION_INDI_REF_ERR_Q"/>
        <dl_setting var="reference_acceleration.rate_q" min="0" step="0.1" max="100" shortname="kd_q" param="STABILIZATION_INDI_REF_RATE_P"/>
        <dl_setting var="reference_acceleration.err_r" min="0" step="1" max="2500" shortname="kp_r" param="STABILIZATION_INDI_REF_ERR_R"/>
        <dl_setting var="reference_acceleration.rate_r" min="0" step="0.1" max="100" shortname="kd_r" param="STABILIZATION_INDI_REF_RATE_P"/>
        <dl_setting var="indi_use_adaptive" min="0" step="1" max="1" shortname="use_adaptive" values="FALSE|TRUE" param="STABILIZATION_INDI_USE_ADAPTIVE" type="uint8"/>
      </dl_settings>
    </dl_settings>
  </settings>
  <autoload name="stabilization" type="rotorcraft"/>
  <header>
    <file name="stabilization_indi.h"/>
  </header>
  <init fun="stabilization_indi_init()"/>
  <makefile target="ap|nps" firmware="rotorcraft">
    <file name="stabilization_indi.c" dir="$(SRC_FIRMWARE)/stabilization"/>
    <file name="stabilization_attitude_quat_indi.c" dir="$(SRC_FIRMWARE)/stabilization"/>
    <file name="stabilization_attitude_quat_transformations.c" dir="$(SRC_FIRMWARE)/stabilization"/>
    <file name="stabilization_attitude_rc_setpoint.c" dir="$(SRC_FIRMWARE)/stabilization"/>
    <file name="wls_alloc.c" dir="$(SRC_FIRMWARE)/stabilization/wls"/>
    <file name="qr_solve.c" dir="math/qr_solve"/>
    <file name="r8lib_min.c" dir="math/qr_solve"/>
    <define name="STABILIZATION_ATTITUDE_TYPE_INT"/>
    <define name="STABILIZATION_ATTITUDE_TYPE_H" value="stabilization/stabilization_attitude_quat_indi.h" type="string"/>
    <define name="STABILIZATION_ATTITUDE_INDI_FULL" value="true"/>
  </makefile>
</module>
