<!DOCTYPE airframe SYSTEM "../airframe.dtd">

<!-- this is a quadrotor frame equiped with
     * Autopilot:   Lisa/M 1.0             http://wiki.paparazziuav.org/wiki/Lisa/M_v10
     * IMU:         Aspirin 1.5            http://wiki.paparazziuav.org/wiki/AspirinIMU
     * Actuators:   MKK motor controllers  http://wiki.paparazziuav.org/wiki/Subsystem/actuators#MKK
     * GPS:         Ublox                  http://wiki.paparazziuav.org/wiki/Subsystem/gps
     * RC:          any PPM system         http://wiki.paparazziuav.org/wiki/Subsystem/radio_control#PPM
-->

<airframe name="Quadrotor LisaM_1.0 mkk">

  <firmware name="rotorcraft">
    <target name="ap" board="lisa_m_1.0">
      <define name="ACTUATORS_START_DELAY" value="3"/>
    </target>
    <target name="nps" board="pc">
      <module name="fdm"           type="jsbsim"/>
    </target>

    <module name="radio_control" type="ppm"/>
    <module name="telemetry"     type="transparent"/>
    <module name="motor_mixing"/>
    <module name="actuators"     type="mkk"/>
    <module name="imu"           type="aspirin_v1.5"/>
    <module name="gps"           type="ublox"/>
    <module name="stabilization" type="int_quat"/>
    <module name="ahrs"          type="int_cmpl_quat"/>
    <module name="ins"/>
  </firmware>

  <section name="ACTUATORS_MKK" prefix="ACTUATORS_MKK_">
    <define name="NB" value="4"/>
    <!-- FRONT, BACK, RIGHT, LEFT -->
    <define name="ADDR" value="{ 0x52, 0x54, 0x56, 0x58 }"/>
  </section>

  <servos driver="Mkk">
    <servo name="FRONT"  no="0"    min="0" neutral="2" max="200"/>
    <servo name="BACK"   no="1"    min="0" neutral="2" max="200"/>
    <servo name="RIGHT"  no="2"    min="0" neutral="2" max="200"/>
    <servo name="LEFT"   no="3"    min="0" neutral="2" max="200"/>
  </servos>

  <commands>
    <axis name="ROLL"   failsafe_value="0"/>
    <axis name="PITCH"  failsafe_value="0"/>
    <axis name="YAW"    failsafe_value="0"/>
    <axis name="THRUST" failsafe_value="0"/>
  </commands>

  <section name="MIXING" prefix="MOTOR_MIXING_">
    <define name="TRIM_ROLL" value="0"/>
    <define name="TRIM_PITCH" value="0"/>
    <define name="TRIM_YAW" value="0"/>
    <define name="NB_MOTOR" value="4"/>
    <define name="SCALE" value="256"/>
    <!-- front/back turning CW, left/right CCW -->
    <define name="ROLL_COEF"   value="{    0,    0, -256,  256 }"/>
    <define name="PITCH_COEF"  value="{  256, -256,    0,    0 }"/>
    <define name="YAW_COEF"    value="{ -256, -256,  256,  256 }"/>
    <define name="THRUST_COEF" value="{  256,  256,  256,  256 }"/>
  </section>

  <command_laws>
    <call fun="motor_mixing_run(autopilot_get_motors_on(),FALSE,values)"/>
    <set servo="FRONT"  value="motor_mixing.commands[0]"/>
    <set servo="BACK"   value="motor_mixing.commands[1]"/>
    <set servo="RIGHT"  value="motor_mixing.commands[2]"/>
    <set servo="LEFT"   value="motor_mixing.commands[3]"/>
  </command_laws>

  <section name="IMU" prefix="IMU_">
    <define name="ACCEL_X_NEUTRAL" value="11"/>
    <define name="ACCEL_Y_NEUTRAL" value="11"/>
    <define name="ACCEL_Z_NEUTRAL" value="-25"/>

    <define name="MAG_X_NEUTRAL" value="-152"/>
    <define name="MAG_Y_NEUTRAL" value="-51"/>
    <define name="MAG_Z_NEUTRAL" value="10"/>
    <define name="MAG_X_SENS" value="4.04042714046" integer="16"/>
    <define name="MAG_Y_SENS" value="3.95350991963" integer="16"/>
    <define name="MAG_Z_SENS" value="3.83055079257" integer="16"/>

    <define name="BODY_TO_IMU_PHI"   value="0." unit="deg"/>
    <define name="BODY_TO_IMU_THETA" value="0." unit="deg"/>
    <define name="BODY_TO_IMU_PSI"   value="-45." unit="deg"/>
  </section>

  <section name="AHRS" prefix="AHRS_">
    <define name="H_X" value="0.3770441"/>
    <define name="H_Y" value="0.0193986"/>
    <define name="H_Z" value="0.9259921"/>
  </section>

  <section name="INS" prefix="INS_">
  </section>



  <section name="STABILIZATION_ATTITUDE" prefix="STABILIZATION_ATTITUDE_">
    <!-- setpoints -->
    <define name="SP_MAX_PHI"     value="45." unit="deg"/>
    <define name="SP_MAX_THETA"   value="45." unit="deg"/>
    <define name="SP_MAX_R"       value="90." unit="deg/s"/>
    <define name="DEADBAND_A"     value="0"/>
    <define name="DEADBAND_E"     value="0"/>
    <define name="DEADBAND_R"     value="250"/>

    <!-- reference -->
    <define name="REF_OMEGA_P"  value="400" unit="deg/s"/>
    <define name="REF_ZETA_P"   value="0.85"/>
    <define name="REF_MAX_P"    value="400." unit="deg/s"/>
    <define name="REF_MAX_PDOT" value="RadOfDeg(8000.)"/>

    <define name="REF_OMEGA_Q"  value="400" unit="deg/s"/>
    <define name="REF_ZETA_Q"   value="0.85"/>
    <define name="REF_MAX_Q"    value="400." unit="deg/s"/>
    <define name="REF_MAX_QDOT" value="RadOfDeg(8000.)"/>

    <define name="REF_OMEGA_R"  value="250" unit="deg/s"/>
    <define name="REF_ZETA_R"   value="0.85"/>
    <define name="REF_MAX_R"    value="180." unit="deg/s"/>
    <define name="REF_MAX_RDOT" value="RadOfDeg(1800.)"/>

    <!-- feedback -->
    <define name="PHI_PGAIN"  value="1000"/>
    <define name="PHI_DGAIN"  value="400"/>
    <define name="PHI_IGAIN"  value="200"/>

    <define name="THETA_PGAIN"  value="1000"/>
    <define name="THETA_DGAIN"  value="400"/>
    <define name="THETA_IGAIN"  value="200"/>

    <define name="PSI_PGAIN"  value="500"/>
    <define name="PSI_DGAIN"  value="300"/>
    <define name="PSI_IGAIN"  value="10"/>

    <!-- feedforward -->
    <define name="PHI_DDGAIN"   value="300"/>
    <define name="THETA_DDGAIN" value="300"/>
    <define name="PSI_DDGAIN"   value="300"/>
  </section>

  <section name="GUIDANCE_V" prefix="GUIDANCE_V_">
    <define name="HOVER_KP"    value="150"/>
    <define name="HOVER_KD"    value="80"/>
    <define name="HOVER_KI"    value="20"/>
    <define name="NOMINAL_HOVER_THROTTLE" value="0.5"/>
    <define name="ADAPT_THROTTLE_ENABLED" value="TRUE"/>
  </section>

  <section name="GUIDANCE_H" prefix="GUIDANCE_H_">
    <define name="MAX_BANK" value="20" unit="deg"/>
    <define name="PGAIN" value="100"/>
    <define name="DGAIN" value="100"/>
    <define name="IGAIN" value="0"/>
  </section>

  <section name="SIMULATOR" prefix="NPS_">
    <define name="ACTUATOR_NAMES"  value="front_motor, back_motor, right_motor, left_motor" type="string[]"/>
    <define name="JSBSIM_MODEL" value="simple_quad" type="string"/>
    <define name="SENSORS_PARAMS" value="nps_sensors_params_default.h" type="string"/>
  </section>

  <section name="AUTOPILOT">
    <define name="MODE_MANUAL" value="AP_MODE_ATTITUDE_DIRECT"/>
    <define name="MODE_AUTO1"  value="AP_MODE_ATTITUDE_Z_HOLD"/>
    <define name="MODE_AUTO2"  value="AP_MODE_HOVER_Z_HOLD"/>
  </section>

  <section name="BAT">
    <define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
    <define name="CRITIC_BAT_LEVEL" value="9.6" unit="V"/>
    <define name="LOW_BAT_LEVEL" value="9.7" unit="V"/>
    <define name="MAX_BAT_LEVEL" value="12.4" unit="V"/>
  </section>

</airframe>
