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

<!-- this is a custom hexa Lisa/L#3 and mikrokopter controllers -->
<airframe name="booz2_a6">

  <section name="ACTUATORS_MKK" prefix="ACTUATORS_MKK_">
    <define name="NB" value="6"/>
    <define name="ADDR" value="{ 0x52, 0x54, 0x56, 0x58, 0x5A, 0X5C }"/>
  </section>

  <servos driver="Mkk">
    <servo name="BACK_RIGHT"   no="0" min="0" neutral="2" max="210"/>
    <servo name="BACK_LEFT"    no="1" min="0" neutral="2" max="210"/>
    <servo name="CENTER_RIGHT" no="2" min="0" neutral="2" max="210"/>
    <servo name="CENTER_LEFT"  no="3" min="0" neutral="2" max="210"/>
    <servo name="FRONT_RIGHT"  no="4" min="0" neutral="2" max="210"/>
    <servo name="FRONT_LEFT"   no="5" min="0" neutral="2" max="210"/>
  </servos>

  <commands>
    <axis name="PITCH"  failsafe_value="0"/>
    <axis name="ROLL"   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="6"/>
    <define name="SCALE" value="256"/>
    <define name="ROLL_COEF"   value="{  -69,   69, -256,  256, -186,  186 }"/>
    <define name="PITCH_COEF"  value="{ -256, -256,    0,    0,  256,  256 }"/>
    <define name="YAW_COEF"    value="{ -153,  153,  256, -256, -115,  115 }"/>
    <define name="THRUST_COEF" value="{  256,  256,  256,  256,  256,  256 }"/>
  </section>

  <command_laws>
    <call fun="motor_mixing_run(autopilot_motors_on,FALSE,values)"/>
    <set servo="BACK_RIGHT"   value="motor_mixing.commands[0]"/>
    <set servo="BACK_LEFT"    value="motor_mixing.commands[1]"/>
    <set servo="CENTER_RIGHT" value="motor_mixing.commands[2]"/>
    <set servo="CENTER_LEFT"  value="motor_mixing.commands[3]"/>
    <set servo="FRONT_RIGHT"  value="motor_mixing.commands[4]"/>
    <set servo="FRONT_LEFT"   value="motor_mixing.commands[5]"/>
  </command_laws>

  <section name="IMU" prefix="IMU_">

    <define name="GYRO_P_NEUTRAL" value="31948"/>
    <define name="GYRO_Q_NEUTRAL" value="31834"/>
    <define name="GYRO_R_NEUTRAL" value="32687"/>

    <define name="GYRO_P_SENS" value=" 1.101357422" integer="16"/>
    <define name="GYRO_Q_SENS" value=" 1.122670898" integer="16"/>
    <define name="GYRO_R_SENS" value=" 1.104890137" integer="16"/>


    <define name="ACCEL_X_SENS" value=" 2.58273701242" integer="16"/>
    <define name="ACCEL_Y_SENS" value=" 2.54076215332" integer="16"/>
    <define name="ACCEL_Z_SENS" value=" 2.57633620646" integer="16"/>

    <define name="ACCEL_X_NEUTRAL" value="32857"/>
    <define name="ACCEL_Y_NEUTRAL" value="32429"/>
    <define name="ACCEL_Z_NEUTRAL" value="32593"/>

    <define name="MAG_X_SENS" value=" 5.32718104135" integer="16"/>
    <define name="MAG_Y_SENS" value=" 4.87857821202" integer="16"/>
    <define name="MAG_Z_SENS" value=" 3.11986612709" integer="16"/>

    <define name="MAG_X_NEUTRAL" value="-43"/>
    <define name="MAG_Y_NEUTRAL" value=" 49"/>
    <define name="MAG_Z_NEUTRAL" value="-66"/>

    <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="90." unit="deg"/>

  </section>

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

 <section name="BAT">
   <define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
 </section>


  <section name="STABILIZATION_RATE" prefix="STABILIZATION_RATE_">

    <define name="SP_MAX_P" value="10000"/>
    <define name="SP_MAX_Q" value="10000"/>
    <define name="SP_MAX_R" value="10000"/>

    <define name="GAIN_P" value="400"/>
    <define name="GAIN_Q" value="400"/>
    <define name="GAIN_R" value="350"/>

  </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_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="300." unit="deg/s"/>
    <define name="REF_MAX_PDOT" value="RadOfDeg(7000.)"/>

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

    <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="400"/>
    <define name="PHI_DGAIN"  value="300"/>
    <define name="PHI_IGAIN"  value="100"/>

    <define name="THETA_PGAIN"  value="400"/>
    <define name="THETA_DGAIN"  value="300"/>
    <define name="THETA_IGAIN"  value="100"/>

    <define name="PSI_PGAIN"  value="380"/>
    <define name="PSI_DGAIN"  value="320"/>
    <define name="PSI_IGAIN"  value="75"/>

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

  </section>

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

 <section name="GUIDANCE_V" prefix="GUIDANCE_V_">
   <define name="HOVER_KP"    value="500"/>
   <define name="HOVER_KD"    value="200"/>
   <define name="HOVER_KI"    value="100"/>
   <define name="NOMINAL_HOVER_THROTTLE" value="0.4"/>
  </section>


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

  <firmware name="rotorcraft">
    <target name="ap" board="lisa_l_1.0">
<!--      <define name="ACTUATORS_START_DELAY" value="1"/> -->
      <subsystem name="radio_control" type="spektrum"/>
      <subsystem name="motor_mixing"/>
      <subsystem name="actuators"     type="mkk"/>
    </target>
    <subsystem name="telemetry"     type="transparent"/>
<!--    <subsystem name="imu"           type="b2_v1.1"/> -->
    <subsystem name="imu"           type="aspirin_v1.0"/>
    <subsystem name="gps"           type="ublox"/>
    <subsystem name="stabilization"   type="int_euler"/>
    <subsystem name="ahrs"          type="int_cmpl_euler"/>
    <subsystem name="ins"/>
  </firmware>



  <firmware name="test_progs">
    <target name="test_telemetry"           board="lisa_l_1.0"/>
    <target name="test_baro_board"          board="lisa_l_1.0"/>
    <target name="test_adc"                 board="lisa_l_1.0"/>
  </firmware>

</airframe>
