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

<!-- Twinjet Multiplex (http://www.multiplex-rc.de/)
     Twog v1 board (http://wiki.paparazziuav.org/wiki/Twog_v1)
     PerkinElmer TPS334 IR Sensors
     Aligned infrared sensor
     XBee modem with AT firmware
     LEA 5H GPS
-->

<airframe name="Twinjet">

  <firmware name="fixedwing">
    <target name="ap" 			board="twog_1.0"/>
    <target name="sim" 			board="pc"/>

    <define name="LOITER_TRIM"/>
    <define name="AGR_CLIMB"/>

    <subsystem name="radio_control" type="ppm"/>
    <subsystem name="telemetry"     type="transparent"/>
    <subsystem name="control"/>
    <subsystem name="imu"       type="analog">
      <configure name="GYRO_P" value="ADC_3"/>
    </subsystem>
    <subsystem name="gps"           type="ublox"/>
    <subsystem name="navigation"/>
    <subsystem name="ins" type="gps_passthrough"/>
  </firmware>

  <firmware name="setup">
    <target name="tunnel"           board="twog_1.0" />
    <target name="usb_tunnel"     board="twog_1.0">
      <configure name="TUNNEL_PORT" value="UART0"/>
    </target>
  </firmware>

  <modules>
    <load name="adc_generic.xml">
      <configure name="ADC_CHANNEL_GENERIC1" value="ADC_7" />
    </load>
    <load name="infrared_adc.xml"/>
    <load name="ahrs_infrared.xml"/>
    <load name="nav_line.xml"/>
  </modules>


  <servos>
    <servo name="THROTTLE"      no="0" min="1000" neutral="1000" max="2000"/>
    <servo name="AILEVON_RIGHT" no="1" min="1230" neutral="1710" max="2100"/>
    <servo name="AILEVON_LEFT"  no="2" min="2120" neutral="1785" max="1300"/>
  </servos>

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

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

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

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

  <section name="AUTO1" prefix="AUTO1_">
    <define name="MAX_ROLL" value="0.6"/>
    <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="HORIZ_SENSOR_ALIGNED" value="1"/>
    <define name="IR1_SIGN" value="1"/>
    <define name="IR2_SIGN" value="-1"/>

    <define name="ROLL_NEUTRAL_DEFAULT" value="5" unit="deg"/>
    <define name="PITCH_NEUTRAL_DEFAULT" value="10" unit="deg"/>

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

    <define name="CORRECTION_UP" value="1."/>
    <define name="CORRECTION_DOWN" value="1."/>
    <define name="CORRECTION_LEFT" value="1."/>
    <define name="CORRECTION_RIGHT" value="1."/>
  </section>

  <section name="IMU" prefix="IMU_">
    <define name="GYRO_P_SIGN"  value="1."/>
    <define name="GYRO_P_NEUTRAL" value="316"/>
    <define name="GYRO_P_SENS" value="1." integer="16"/>
  </section>

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

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

    <define name="PITCH_PGAIN" value="6000."/>
    <define name="PITCH_DGAIN" value="0."/>
    <define name="ELEVATOR_OF_ROLL" value="0"/>

    <!--  roll rate loop -->
    <define name="ROLL_ATTITUDE_GAIN" value="7500"/>
    <define name="ROLL_RATE_GAIN" value="1500"/>
  </section>


 <section name="VERTICAL CONTROL" prefix="V_CTL_">
    <!-- outer loop proportional gain -->
    <define name="ALTITUDE_PGAIN" value="0.05"/>
    <!-- outer loop saturation -->
    <define name="ALTITUDE_MAX_CLIMB" value="3."/>

    <!-- auto throttle inner loop -->
    <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.40"/>
    <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value=".3"/>
    <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.8"/>
    <define name="AUTO_THROTTLE_LOITER_TRIM" value="2000"/>
    <define name="AUTO_THROTTLE_DASH_TRIM" value="-1500"/>
    <define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.15" unit="%/(m/s)"/>
    <define name="AUTO_THROTTLE_PGAIN" value="0.008"/>
    <define name="AUTO_THROTTLE_IGAIN" value="0.25"/>
    <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.14"/>

    <define name="THROTTLE_SLEW_LIMITER" value="2" unit="s"/>
  </section>



  <section name="NAV">
    <define name="NAV_GLIDE_PITCH_TRIM" value="0"/>
    <define name="DEFAULT_CIRCLE_RADIUS" value="75."/>
  </section>

  <section name="BAT">
    <define name="MILLIAMP_AT_FULL_THROTTLE" value="1000"/>
    <define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
    <define name="CRITIC_BAT_LEVEL" value="10" unit="V"/>
    <define name="LOW_BAT_LEVEL" value="10.5" unit="V"/>
  </section>

  <section name="MISC">
    <define name="NOMINAL_AIRSPEED" value="12." unit="m/s"/>
    <define name="CARROT" value="5." unit="s"/>
    <define name="KILL_MODE_DISTANCE" value="(MAX_DIST_FROM_HOME*1.5)" unit="s"/>
  </section>

  <section name="FAILSAFE" prefix="FAILSAFE_">
    <define name="DELAY_WITHOUT_GPS" value="2" unit="s"/>
    <define name="DEFAULT_THROTTLE" value="V_CTL_AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE+0.05" unit="%"/>
    <define name="DEFAULT_ROLL" value="0.17" unit="rad"/>
    <define name="DEFAULT_PITCH" value="0.08" unit="rad"/>
    <define name="HOME_RADIUS" value="50" unit="m"/>
  </section>

  <section name="AGGRESSIVE" prefix="AGR_">
    <define name="CLIMB_THROTTLE" value="0.65"/><!-- Throttle for Aggressive Climb -->
    <define name="DESCENT_THROTTLE" value="0.1"/><!-- Throttle for Aggressive Decent -->
    <define name="CLIMB_PITCH" value="0.2"/><!-- Pitch for Aggressive Climb -->
    <define name="DESCENT_PITCH" value="-0.25"/><!-- Pitch for Aggressive Decent -->
    <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_NAV_RATIO" value="0.8"/><!-- Percent Navigation for Altitude Error Equal to Start Altitude -->
    <define name="DESCENT_NAV_RATIO" value="1.0"/>
  </section>

</airframe>
