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

<!-- Twinjet Multiplex (http://www.multiplex-rc.de/)
     Tiny 2.12 board (http://paparazzi.enac.fr/wiki/index.php/Tiny_v2)
     Tilted infrared sensor
-->

<airframe name="Twinjet 2 Tiny 2.12">

  <modules>
    <!--load name="adp_roll.xml"/-->
    <!--load name="ins_vn100.xml"/-->
    <!--load name="ets_module_sensors.xml"/-->
    <!--load name="infrared_i2c.xml"/-->
    <!--load name="max3100.xml"/>
    <load name="gsm.xml"/-->
    <!--load name="demo_module.xml">
      <define name="TEST" value="1"/>
      <define name="TEST_FLAG"/>
    </load-->
    <!--load name="enose.xml"/-->
    <load name="light.xml"/>
    <load name="infrared_adc.xml"/>
  </modules>

  <firmware name="fixedwing">
    <define name="PITCH_TRIM"/>
    <define name="ALT_KALMAN"/>
    <define name="USE_I2C0"/>

    <target name="ap" 			board="tiny_2.11"/>
    <target name="sim" 			board="pc"/>

    <subsystem name="radio_control" type="ppm"/>
    <subsystem name="telemetry"     type="xbee_api"/>
    <subsystem name="control"       type="adaptive"/>
    <subsystem name="ahrs"          type="infrared"/>
    <subsystem name="ins"           type="alt_float"/>
    <subsystem name="gps"           type="ublox"/>
    <subsystem name="navigation"/>
  </firmware>

  <firmware name="setup">
    <target name="tunnel" 		      board="tiny_2.11" />
    <target name="setup_actuators" 	board="tiny_2.11" />
  </firmware>

  <!-- commands section -->
  <servos>
    <servo name="MOTOR_LEFT" no="3" min="1000" neutral="1000" max="2000"/>
    <servo name="MOTOR_RIGHT" no="4" min="1000" neutral="1000" max="2000"/>
    <servo name="AILEVON_LEFT" no="6" min="1900" neutral="1515" max="1100"/>
    <servo name="AILEVON_RIGHT" no="7" min="1100" neutral="1500" max="1900"/>
  </servos>

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

  <rc_commands>
    <set command="THROTTLE" value="@THROTTLE"/>
    <set command="ROLL" value="@ROLL"/>
    <set command="PITCH" value="@PITCH"/>
    <set command="YAW" value="@YAW"/>
  </rc_commands>

  <section name="MIXER">
    <define name="AILEVON_AILERON_RATE" value="0.75"/>
    <define name="AILEVON_ELEVATOR_RATE" value="0.75"/>
    <define name="MOTOR_YAW_RATE" value="0.0"/>
  </section>

  <command_laws>
    <let var="aileron" value="@ROLL  * AILEVON_AILERON_RATE"/>
    <let var="elevator" value="@PITCH * AILEVON_ELEVATOR_RATE"/>
    <let var="yaw" value="@YAW   * MOTOR_YAW_RATE"/>
    <set servo="MOTOR_LEFT" value="@THROTTLE - $yaw"/>
    <set servo="MOTOR_RIGHT" value="@THROTTLE + $yaw"/>
    <set servo="AILEVON_LEFT" value="$elevator + $aileron"/>
    <set servo="AILEVON_RIGHT" value="$elevator - $aileron"/>
  </command_laws>

  <section name="AUTO1" prefix="AUTO1_">
    <define name="MAX_ROLL" value="0.85"/>
    <define name="MAX_PITCH" value="0.6"/>
  </section>

  <section name="INFRARED" prefix="IR_">
    <define name="ADC_IR1_NEUTRAL" value="512"/>
    <define name="ADC_IR2_NEUTRAL" value="512"/>
    <define name="ADC_TOP_NEUTRAL" value="512"/>

    <define name="LATERAL_CORRECTION" value="1."/>
    <define name="LONGITUDINAL_CORRECTION" value="1."/>
    <define name="VERTICAL_CORRECTION" value="1.25"/>

    <define name="HORIZ_SENSOR_TILTED" value="1"/>
    <define name="IR1_SIGN" value="-1"/>
    <define name="IR2_SIGN" value="1"/>
    <define name="TOP_SIGN" value="1"/>

    <define name="ROLL_NEUTRAL_DEFAULT" value="-1.146" unit="deg"/>
    <define name="PITCH_NEUTRAL_DEFAULT" value="0.15" unit="deg"/>

    <define name="I2C_DEFAULT_CONF" value="1"/>
  </section>

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

  <section name="MISC">
    <define name="MINIMUM_AIRSPEED" value="10." unit="m/s"/>
    <define name="NOMINAL_AIRSPEED" value="12." unit="m/s"/>
    <define name="MAXIMUM_AIRSPEED" value="20." unit="m/s"/>
    <define name="CARROT" value="5." unit="s"/>
    <define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
<!--    <define name="XBEE_INIT" value="&quot;ATPL2\rATRN1\rATTT80\r&quot;"/> -->
<!--    <define name="NO_XBEE_API_INIT" value="TRUE"/> -->
    <define name="ALT_KALMAN_ENABLED" value="TRUE"/>
    <define name="DEFAULT_CIRCLE_RADIUS" value="80."/>
    <define name="LIGHT_LED_1" value="3"/>
    <define name="LIGHT_LED_2" value="5"/>
  </section>

  <section name="VERTICAL CONTROL" prefix="V_CTL_">

    <define name="POWER_CTL_BAT_NOMINAL" value="11.1" unit="volt"/>
    <!-- outer loop proportional gain -->
    <define name="ALTITUDE_PGAIN" value="0.0450000017881"/>
    <!-- outer loop saturation -->
    <define name="ALTITUDE_MAX_CLIMB" value="2."/>

    <!-- auto throttle inner loop -->
    <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.319999992847"/>
    <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.25"/>
    <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.80"/>
    <define name="AUTO_THROTTLE_LOITER_TRIM" value="1500"/>
    <define name="AUTO_THROTTLE_DASH_TRIM" value="-1000"/>
    <define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.1" unit="%/(m/s)"/>
    <define name="AUTO_THROTTLE_PGAIN" value="0.035000000149"/>
    <define name="AUTO_THROTTLE_IGAIN" value="0.01"/>
    <define name="AUTO_THROTTLE_DGAIN" value="0"/>
    <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.12"/>

    <!-- auto pitch inner loop -->
    <define name="AUTO_PITCH_PGAIN" value="0.035000000149"/>
    <define name="AUTO_PITCH_IGAIN" value="0.01"/>
    <define name="AUTO_PITCH_DGAIN" value="0"/>
    <define name="AUTO_PITCH_MAX_PITCH" value="0.35"/>
    <define name="AUTO_PITCH_MIN_PITCH" value="-0.35"/>
    <define name="AUTO_PITCH_CLIMB_THROTTLE_INCREMENT" value="0.15"/>

    <!-- pitch trim -->
    <define name="PITCH_LOITER_TRIM" value="RadOfDeg(5.)"/>
    <define name="PITCH_DASH_TRIM" value="RadOfDeg(-5.)"/>

   <define name="THROTTLE_SLEW" value="0.3"/>

  </section>

  <section name="HORIZONTAL CONTROL" prefix="H_CTL_">
    <define name="COURSE_PGAIN" value="0.995000004768"/>

    <define name="ROLL_MAX_SETPOINT" value="0.6" unit="rad"/>
    <define name="PITCH_MAX_SETPOINT" value="0.5" unit="rad"/>
    <define name="PITCH_MIN_SETPOINT" value="-0.5" unit="rad"/>

    <define name="ROLL_ATTITUDE_GAIN" value="3553.89208984"/>
    <define name="ROLL_RATE_GAIN" value="0."/>
    <define name="ROLL_IGAIN" value="500"/>
    <define name="ROLL_KFFA" value="500"/>
    <define name="ROLL_KFFD" value="500"/>

    <define name="PITCH_PGAIN" value="14522.4716797"/>
    <define name="PITCH_DGAIN" value="0."/>
    <define name="PITCH_IGAIN" value="500"/>
    <define name="PITCH_KFFA" value="0."/>
    <define name="PITCH_KFFD" value="0."/>

    <!--define name="ELEVATOR_OF_ROLL" value="1541."/-->
    <define name="PITCH_OF_ROLL" value="RadOfDeg(0.2)"/>

  </section>

  <section name="NAV">
    <define name="NAV_GLIDE_PITCH_TRIM" value="0"/>
    <define name="NAV_CROSS_TRACK_ERROR_IGAIN" value="0."/>
    <define name="NAV_CROSS_TRACK_ERROR_MAX" value="10." unit="deg"/>
  </section>

  <section name="AGGRESSIVE" prefix="AGR_">
    <define name="BLEND_START" value="20"/><!-- Altitude Error to Initiate Aggressive Climb CANNOT BE ZERO!!-->
    <define name="BLEND_END" value="10"/><!-- Altitude Error to Blend Aggressive to Regular Climb Modes  CANNOT BE ZERO!!-->
    <define name="CLIMB_THROTTLE" value="0.7"/><!-- Gaz for Aggressive Climb -->
    <define name="CLIMB_PITCH" value="0.25"/><!-- Pitch for Aggressive Climb -->
    <define name="DESCENT_THROTTLE" value="0.1"/><!-- Gaz for Aggressive Decent -->
    <define name="DESCENT_PITCH" value="-0.15"/><!-- Pitch for Aggressive Decent -->
    <define name="CLIMB_NAV_RATIO" value="0.8"/><!-- Percent Navigation for Altitude Error Equal to Start Altitude -->
    <define name="DESCENT_NAV_RATIO" value="1.0"/>
    </section>

  <section name="FAILSAFE" prefix="FAILSAFE_">
    <define name="DELAY_WITHOUT_GPS" value="1" unit="s"/>
    <define name="DEFAULT_THROTTLE" value="0.3" unit="%"/>
    <define name="DEFAULT_ROLL" value="0.3" unit="rad"/>
    <define name="DEFAULT_PITCH" value="0.5" unit="rad"/>
    <define name="HOME_RADIUS" value="100" unit="m"/>
  </section>

  <section name="SIMU">
    <define name="YAW_RESPONSE_FACTOR" value="1."/>
  </section>

</airframe>
