<!-- This file is generated by Daniel Morgan & Haiyang Chao for using Xsens Mti-g IMU + gumstix + pprz_twog-->

<airframe name="OSAMUGEAR">

  <firmware name="fixedwing">
    <target name="ap"                  board="tiny_2.11">
      <define name="AGR_CLIMB"/>
      <define name="LOITER_TRIM"/>
      <define name="ALT_KALMAN"/>
      <define name="WIND_INFO"/>
      <define name="UGEAR"/>
      <define name="UGEAR_LED" value="2"/>
      <define name="UGEAR_LINK" value="Uart0"/>
      <define name="USE_UART0"/>
      <define name="UART0_BAUD" value="B115200"/>
    </target>

    <target name="sim"                 board="pc">
      <define name="AGR_CLIMB"/>
      <define name="LOITER_TRIM"/>
      <define name="ALT_KALMAN"/>
    </target>

    <subsystem name="radio_control"    type="ppm"/>

    <!-- Communication -->
    <subsystem name="telemetry"        type="transparent">
      <configure name="MODEM_BAUD"         value="B38400"/>
    </subsystem>

    <!-- Actuators are automatically chosen according to board-->
    <subsystem name="control"/>
    <!-- Sensors -->
    <!--subsystem name="ahrs"         type="infrared"/-->
    <subsystem name="gps"              type="ugear"/>
    <subsystem name="navigation"/>
  </firmware>

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

  <!-- modules -->
  <modules>
    <load name="ins_osam_ugear.xml"/>
  </modules>
<!-- commands section -->
  <servos>
    <servo name="AILEVON_RIGHT" no="3" min="1900" neutral="1450" max="1000"/>
    <servo name="AILEVON_LEFT"  no="4" min="1050" neutral="1450" max="1900"/>
    <servo name="THROTTLE"      no="0" min="1003" neutral="1003" max="1875"/>
  </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.8"/>
    <define name="AILEVON_ELEVATOR_RATE" value="0.7"/>
  </section>

  <command_laws>
    <let var="aileron"         value="- @ROLL  * AILEVON_AILERON_RATE"/>
    <let var="elevator"        value="- @PITCH * AILEVON_ELEVATOR_RATE"/>

    <set servo="THROTTLE"      value="@THROTTLE"/>
    <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="45" unit="deg"/>
    <define name="MAX_PITCH" value="45" unit="deg"/>
  </section>

  <section name="adc" prefix="ADC_CHANNEL_">
    <define name="IR1" value="ADC_0"/>
    <define name="IR2" value="ADC_1"/>
    <define name="IR_TOP" value="ADC_2"/>
    <define name="IR_NB_SAMPLES" value="16"/>
 <!--   <define name="GYRO_ROLL" value="ADC_3"/>
    <define name="GYRO_NB_SAMPLES" value="16"/> DL
-->
  </section>

  <section name="INFRARED" prefix="IR_">
    <define name="ADC_IR1_NEUTRAL" value="516"/>
    <define name="ADC_IR2_NEUTRAL" value="518"/>
    <define name="ADC_TOP_NEUTRAL" value="513"/>

    <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="LATERAL_CORRECTION" value="1.253"/>
    <define name="LONGITUDINAL_CORRECTION" value="1.16"/>
    <define name="VERTICAL_CORRECTION" value="1.0"/>

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

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

  <section name="INS" prefix="INS_">
    <define name="ROLL_NEUTRAL_DEFAULT" value="-5.73" unit="deg"/>
    <define name="PITCH_NEUTRAL_DEFAULT" value="5.73" unit="deg"/>
  </section>

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

  <section name="MISC">
    <define name="CARROT" value="5." unit="s"/>
    <define name="NOMINAL_AIRSPEED" value="15." unit="m/s"/>
    <define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
    <define name="CONTROL_FREQUENCY" value="60" unit="Hz"/>
    <define name="ALT_KALMAN_ENABLED" value="TRUE"/>

    <define name="UNLOCKED_HOME_MODE" value="TRUE"/>
    <define name="RC_LOST_MODE" value="PPRZ_MODE_AUTO2"/>

    <define name="DEFAULT_CIRCLE_RADIUS" value="75."/>
  </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.03"/>
    <!-- outer loop saturation -->
    <define name="ALTITUDE_MAX_CLIMB" value="2."/>

    <!-- auto throttle inner loop -->
    <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.70"/>
    <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.55"/>
    <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="-4000"/>
    <define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.15" unit="%/(m/s)"/>
    <define name="AUTO_THROTTLE_PGAIN" value="0.01"/>
    <define name="AUTO_THROTTLE_IGAIN" value="0.1"/>
    <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.05"/>

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

  </section>

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

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

    <define name="PITCH_PGAIN" value="4639.1"/>
    <define name="PITCH_DGAIN" value="0"/>
   <define name="ROLL_PGAIN" value="4123.71"/>
    <define name="ELEVATOR_OF_ROLL" value="1250"/>

   </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=".99"/><!-- Gaz for Aggressive Climb -->
    <define name="CLIMB_PITCH" value="0.3"/><!-- Pitch for Aggressive Climb -->
    <define name="DESCENT_THROTTLE" value="0.1"/><!-- Gaz for Aggressive Decent -->
    <define name="DESCENT_PITCH" value="-0.25"/><!-- 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="2" 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"/>
  </section>

</airframe>
