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

<airframe name="A1000 LISA">

  <modules main_freq="512">
    <load name="deploy_sonar_buoy.xml"/>
  </modules>

  <servos>

    <servo name="BACK"   no="0" min="2000" neutral="1500" max="1000"/>
    <servo name="LEFT"   no="1" min="2000" neutral="1500" max="1000"/>
    <servo name="FRONT"  no="2" min="2000" neutral="1500" max="1000"/>
    <servo name="RIGHT"  no="3" min="2000" neutral="1500" max="1000"/>
    <servo name="ESC"    no="4" min="1000" neutral="1000" max="2000"/>
  </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>
<!--
  <command_laws>
    <set servo="ESC"        value="motors_on?ESC_HOVER:ESC_STOPPED"/>
    <set servo="FRONT"      value="-(@PITCH + @YAW + (1.3 * (@THRUST<<5)))"/>
    <set servo="BACK"       value="-(-@PITCH + @YAW + (1.3 *(@THRUST<<5)))"/>
    <set servo="LEFT"       value="-(@ROLL  - @YAW + (1.3 *(@THRUST<<5)))"/>
    <set servo="RIGHT"      value="-(-@ROLL  - @YAW + (1.3 *(@THRUST<<5)))"/>
  </command_laws>
-->
  <command_laws>
    <set servo="ESC"        value="motors_on?ESC_HOVER:ESC_STOPPED"/>
    <set servo="FRONT"      value="@PITCH + @YAW + @THRUST"/>
    <set servo="BACK"       value="-@PITCH + @YAW + @THRUST"/>
    <set servo="LEFT"       value="@ROLL  - @YAW + @THRUST"/>
    <set servo="RIGHT"      value="-@ROLL  - @YAW + @THRUST"/>
  </command_laws>
  <section name="IMU" prefix="IMU_">

    <define name="GYRO_P_NEUTRAL" value="33550"/>
    <define name="GYRO_Q_NEUTRAL" value="33500"/>
    <define name="GYRO_R_NEUTRAL" value="32500"/>
    <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"/>

    <!-- accelerations done on 18/10/2010 -->
    <define name="ACCEL_X_NEUTRAL" value="32093"/>
    <define name="ACCEL_Y_NEUTRAL" value="32301"/>
    <define name="ACCEL_Z_NEUTRAL" value="32293"/>
    <define name="ACCEL_X_SENS" value="2.53098065315" integer="16"/>
    <define name="ACCEL_Y_SENS" value="2.52055255767" integer="16"/>
    <define name="ACCEL_Z_SENS" value="2.57032707747" integer="16"/>

<define name="MAG_X_NEUTRAL" value="-9"/>
<define name="MAG_Y_NEUTRAL" value="-4"/>
<define name="MAG_Z_NEUTRAL" value="14"/>
<define name="MAG_X_SENS" value="3.61018203965" integer="16"/>
<define name="MAG_Y_SENS" value="4.13471628028" integer="16"/>
<define name="MAG_Z_SENS" value="2.07762920804" integer="16"/>

    <define name="BODY_TO_IMU_PHI"   value="0.53 " unit="deg"/>
    <define name="BODY_TO_IMU_THETA" value="-1.24 " unit="deg"/>
    <define name="BODY_TO_IMU_PSI"   value="0" unit="deg"/>

  </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"/>
 </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="800" 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="800" 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="500" 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="5000"/>
    <define name="PHI_DGAIN"  value="400"/>
    <define name="PHI_IGAIN"  value="200"/>

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

    <define name="PSI_PGAIN"  value="2000"/>
    <define name="PSI_DGAIN"  value="350"/>
    <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"/> -->

    <!-- feedback -->
    <define name="PHI_PGAIN"  value="1500"/>
    <define name="PHI_DGAIN"  value="30"/>
    <define name="PHI_IGAIN"  value="100"/>

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

    <define name="PSI_PGAIN"  value="1000"/>
    <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="INS" prefix="INS_">
    <define name="BARO_SENS" value="15." integer="16"/>
  </section>

 <section name="GUIDANCE_V" prefix="GUIDANCE_V_">
   <define name="MIN_ERR_Z"   value="POS_BFP_OF_REAL(-10.)"/>
   <define name="MAX_ERR_Z"   value="POS_BFP_OF_REAL( 10.)"/>
   <define name="MIN_ERR_ZD"  value="SPEED_BFP_OF_REAL(-10.)"/>
   <define name="MAX_ERR_ZD"  value="SPEED_BFP_OF_REAL( 10.)"/>
   <define name="MAX_SUM_ERR" value="2000000"/>
   <define name="HOVER_KP"    value="500"/>
   <define name="HOVER_KD"    value="200"/>
   <define name="HOVER_KI"    value="100"/>
   <!-- 1.5m/s for full stick : BOOZ_SPEED_I_OF_F(1.5) / (MAX_PPRZ/2) -->
   <define name="RC_CLIMB_COEF" value ="163"/>
   <!-- BOOZ_SPEED_I_OF_F(1.5) * 20% -->
   <define name="RC_CLIMB_DEAD_BAND" value ="160000"/>
   <define name="INV_M" value ="0.2"/>
  </section>


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

 <section name="MISC">
   <define name="FACE_REINJ_1"  value="1024"/>
 </section>


  <firmware name="rotorcraft">
    <target name="ap" board="lisa_l_1.0">
      <define name = "RADIO_CONTROL_MODE" value = "RADIO_AUX1"/>
      <define name = "RADIO_KILL_SWITCH" value = "RADIO_GEAR"/>
      <define name = "HELI"/>
 <!--     <define name = "KILL_MOTORS" />-->
 <!-- if we want a secondary spektrum reciever we need to set the board to be
      lisa_l_1.1 and rewired accordingly then set the following.
      <define name = "RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT" value = "UART5"/>
      <define name = "OVERRIDE_UART5_IRQ_HANDLER"/> -->
    </target>
    <subsystem name="radio_control" type="spektrum"/>
    <subsystem name="telemetry"     type="transparent"/>
    <subsystem name="actuators"     type="heli"/>
    <subsystem name="imu"           type="b2_v1.1"/>
    <subsystem name="gps"           type="ublox"/>
    <subsystem name="stabilization"   type="euler"/>
    <subsystem name="ahrs"          type="int_cmpl_euler"/>
  </firmware>

  <firmware name="lisa_test_progs">
    <target name="test_telemetry" board="lisa_l_1.0"/>
    <target name="test_baro"      board="lisa_l_1.0"/>
    <target name="test_spektrum"  board="lisa_l_1.0"/>
  </firmware>

  <firmware name="lisa_passthrough">
    <target name="stm_passthrough" board="lisa_l_1.0"/>
      <subsystem name="radio_control" type="spektrum"/>
      <subsystem name="imu" type="b2_v1.1"/>
 </firmware>

</airframe>
