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

<!-- Delfly (http://www.delfly.nl/home.html)
     Lisa/S v0.1 board (http://wiki.paparazziuav.org/wiki/Lisa/S)
     Using Lisa/S V1.0 board file as it is software compatible.
-->

<airframe name="Delfly Lisa/S 0.1">
  <description>DelFly Outdoor Auto2
  </description>

  <firmware name="fixedwing">
    <target name="ap"   board="lisa_s_1.0">
      <module name="radio_control" type="spektrum">
        <define name="RADIO_MODE" value="RADIO_FLAP"/>
        <define name="RADIO_KILL_SWITCH" value="RADIO_GEAR"/>
        <configure name="USE_SECONDARY_SPEKTRUM_RECEIVER" value="0"/>
      </module>

      <configure name="AHRS_PROPAGATE_FREQUENCY" value="500"/>
    </target>

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

    <!-- Communication -->
    <module name="telemetry" 	type="transparent">
      <!--<configure name="MODEM_BAUD" value="B57600"/>
      <configure name="MODEM_PORT" value="UART1"/>-->
    </module>

    <!-- Sensors -->
    <module name="imu"           type="lisa_s_v1.0"/>
    <module name="gps"           type="ublox"/>

    <module name="actuators" type="pwm">
      <define name="SERVO_HZ" value="50"/>
      <define name="USE_SERVOS_1AND2"/>
    </module>

    <module name="actuators" type="dualpwm">
      <define name="DUAL_PWM_ON"/>
    </module>

    <!--<module name="ahrs"          type="int_cmpl_quat"/>-->
    <module name="control"/>
    <module name="navigation"/>
    <module name="ins" type="alt_float">
      <define name="USE_BAROMETER" value="TRUE"/>
    </module>

    <!--<configure name="SYS_TIME_LED" value="none"/>-->
  </firmware>

  <modules>
    <module name="baro_sim"/>
    <module name="switch" type="servo"/>
    <module name="gps" type="ubx_ucenter"/>
  </modules>

  <servos driver="Pwm">
    <servo name="MOTOR"         no="0" min="1290" neutral="1290" max="1810"/>
    <!--<servo name="SWITCH"  no="2" min="1100" neutral="1500" max="1900"/>
    <servo name="SWITCH2"  no="3" min="1100" neutral="1500" max="1900"/>-->
  </servos>

  <!-- comboPWM / mergedPWM /  -->
  <servos driver="Dualpwm">
    <servo name="SWITCH"  no="3" min="1100" neutral="1500" max="1900"/>
    <servo name="pitchator"  no="2" min="1100" neutral="1500" max="1900"/>
  </servos>

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

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

  <command_laws>
    <set servo="MOTOR"         value="@THROTTLE"/>
    <set servo="pitchator"         value="@PITCH"/>
  </command_laws>

  <section name="IMU" prefix="IMU_">
    <!-- ACCEL and GYRO calibration left out to take default datasheet values -->

    <!-- replace this with your own mag calibration -->
    <define name="MAG_X_NEUTRAL" value="-45"/>
    <define name="MAG_Y_NEUTRAL" value="334"/>
    <define name="MAG_Z_NEUTRAL" value="7"/>
    <define name="MAG_X_SENS" value="4.47647816128" integer="16"/>
    <define name="MAG_Y_SENS" value="4.71085671542" integer="16"/>
    <define name="MAG_Z_SENS" value="4.41585354498" integer="16"/>

    <define name="BODY_TO_IMU_PHI"   value="0." unit="deg"/>
    <define name="BODY_TO_IMU_THETA" value="0." unit="deg"/>
    <define name="BODY_TO_IMU_PSI"   value="0." unit="deg"/>
  </section>

  <section name="AHRS" prefix="AHRS_">
    <!-- replace this with your local magnetic field -->
    <define name="H_X" value="0.3770441"/>
    <define name="H_Y" value="0.0193986"/>
    <define name="H_Z" value="0.9259921"/>
  </section>

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

  <section name="VERTICAL CONTROL" prefix="V_CTL_">
    <define name="POWER_CTL_BAT_NOMINAL" value="7.3" 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.0"/>
    <define name="COURSE_DGAIN" value="0.3"/>

    <define name="ROLL_MAX_SETPOINT"  value="35"  unit="deg"/>
    <define name="PITCH_MAX_SETPOINT" value="30"  unit="deg"/>
    <define name="PITCH_MIN_SETPOINT" value="-30" unit="deg"/>

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

    <define name="ELEVATOR_OF_ROLL" value="1250"/>

    <define name="ROLL_SLEW" value="0.1"/>

    <define name="ROLL_ATTITUDE_GAIN" value="7500"/>
    <define name="ROLL_RATE_GAIN" value="1500"/>
  </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="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>

  <section name="AUTO1" prefix="AUTO1_">
    <define name="MAX_ROLL" value="40." unit="deg"/>
    <define name="MAX_PITCH" value="35." unit="deg"/>
  </section>

  <section name="BAT">
    <define name="MILLIAMP_AT_FULL_THROTTLE" value="1000"/>
    <define name="CATASTROPHIC_BAT_LEVEL" value="2.9" unit="V"/>
    <define name="CRITIC_BAT_LEVEL" value="3.1" unit="V"/>
    <define name="LOW_BAT_LEVEL" value="3.4" unit="V"/>
    <define name="MAX_BAT_LEVEL" value="4.2" unit="V"/>
    <!--<define name="VoltageOfAdc(adc)" value ="8"/>-->
  </section>

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

    <define name="UNLOCKED_HOME_MODE" value="TRUE"/>
    <!--<define name="RC_LOST_MODE" value="mode_auto2"/>-->
  </section>

</airframe>
