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

<!--
YAPA + XSens + XBee
-->

<airframe name="Yapa v1">

  <servos>
    <servo name="THROTTLE" no="0" min="1100" neutral="1000" max="1900"/>
    <servo name="RUDDER" no="2" min="1100" neutral="1500" max="1900"/>
    <servo name="ELEVATOR" no="6" min="1000" neutral="1500" max="2000"/>
    <servo name="CAM_TILT" no="7" min="700" neutral="1600" max="2500"/>
    <servo name="CAM_PAN" no="3" min="800" neutral="1650" max="2500"/>
  </servos>

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

  <ap_only_commands>
    <copy command="CAM_PAN"/>
    <copy command="CAM_TILT"/>
  </ap_only_commands>


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

  <command_laws>
    <set servo="CAM_PAN" value="@CAM_PAN"/>
    <set servo="CAM_TILT" value="@CAM_TILT"/>

    <!-- Differential Aileron Depending on Brake Value -->
    <set servo="RUDDER" value="@ROLL"/>

    <!-- Differential Thurst -->
    <set servo="THROTTLE" value="@THROTTLE"/>

    <!-- Pitch with Brake-Trim Function -->
    <set servo="ELEVATOR" value="@PITCH"/>
  </command_laws>

  <section name="INS" prefix="INS_">
    <define name="ROLL_NEUTRAL_DEFAULT" value="0" unit="rad"/>
    <define name="PITCH_NEUTRAL_DEFAULT" value="0" unit="rad"/>
  </section>

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

  <section name="PANTILT" prefix="CAM_">
    <!-- these are in degrees, either specify both unit and code_unit or none -->
    <define name="PAN_MIN" value="-45"/>
    <define name="PAN_NEUTRAL" value="33"/>
    <define name="PAN_MAX" value="156"/>
    <define name="PAN0" value="0"/>
    <define name="TILT_MIN" value="-62" unit="deg" code_unit="deg"/>
    <define name="TILT_NEUTRAL" value="47" unit="deg" code_unit="deg"/>
    <define name="TILT_MAX" value="122" unit="deg" code_unit="deg"/>
    <define name="TILT0" value="90" unit="deg" code_unit="deg"/>
    <define name="MODE0" value="1"/>
  </section>

  <section name="BAT">
    <define name="LOW_BAT_LEVEL" value="7" unit="V"/>
    <define name="CRITIC_BAT_LEVEL" value="6.5" unit="V"/>
    <define name="CATASTROPHIC_BAT_LEVEL" value="6.0" unit="V"/>
  </section>

  <section name="MISC">
    <define name="NOMINAL_AIRSPEED" value="13." unit="m/s"/>
    <define name="CARROT" value="5." unit="s"/>
    <!--   <define name="XBEE_INIT" value="&quot;ATPL2\rATRN5\rATTT80\r&quot;"/>
         <define name="NO_XBEE_API_INIT" value="TRUE"/> -->

    <define name="DEFAULT_CIRCLE_RADIUS" value="80."/>

    <define name="GLIDE_AIRSPEED" value="10"/>
    <define name="GLIDE_VSPEED" value="3."/>
    <define name="GLIDE_PITCH" value="45" unit="deg"/>
  </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.32"/>
    <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.25"/>
    <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.65"/>
    <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.20000004768"/>
    <define name="COURSE_DGAIN" value="0.3"/>
    <define name="COURSE_PRE_BANK_CORRECTION" value="0.2"/>

    <define name="ROLL_MAX_SETPOINT" value="0.9" unit="radians"/>
    <define name="PITCH_MAX_SETPOINT" value="0.5" unit="radians"/>
    <define name="PITCH_MIN_SETPOINT" value="-0.5" unit="radians"/>

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

    <define name="ELEVATOR_OF_ROLL" value="1000."/>

    <define name="ROLL_ATTITUDE_GAIN" value="11500"/>
    <define name="ROLL_RATE_GAIN" value="600."/>
  </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="1.00"/><!-- 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="DEFAULT_THROTTLE" value="0.35" unit="%"/>
    <define name="DEFAULT_ROLL" value="0.17" unit="rad"/>
    <define name="DEFAULT_PITCH" value="0.08" unit="rad"/>

    <define name="HOME_RADIUS" value="DEFAULT_CIRCLE_RADIUS" unit="m"/>
    <define name="KILL_MODE_DISTANCE" value="(MAX_DIST_FROM_HOME*1.5)"/>
    <define name="DELAY_WITHOUT_GPS" value="3" unit="s"/>
  </section>

  <section name="DIGITAL_CAMERA" prefix="DC_">
    <define name="AUTOSHOOT_QUARTERSEC_PERIOD" value="6" unit="quarter_second"/>
    <define name="AUTOSHOOT_DISTANCE_INTERVAL" value="50" unit="meter"/>
  </section>


  <modules>
    <load name="ahrs_chimu_spi.xml" >
      <define name="CHIMU_BIG_ENDIAN" />
    </load>
    <load name="cam_point.xml" />
    <load name="gps_ubx_ucenter.xml"/>
  </modules>

  <firmware name="fixedwing">

    <define name="STRONG_WIND"/>
    <define name="WIND_INFO"/>
    <define name="WIND_INFO_RET"/>
    <define name="LOITER_TRIM"/>
    <define name="POINT_CAM_PITCH_ROLL" />

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

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


    <!-- Communication -->
    <subsystem name="telemetry" type="xbee_api">
      <configure name="MODEM_BAUD" value="B9600"/>
    </subsystem>

    <!-- Actuators -->
    <subsystem name="control"/>
    <!-- Sensors -->
    <subsystem name="navigation"/>

    <subsystem name="spi_slave_hs"/>
    <subsystem name="ins" type="alt_float"/>
  </firmware>

</airframe>
