<!-- Modified Multiplex Xeno (http://www.multiplex-rc.de/)
     TWOG1  (http://paparazziuav.org/wiki/index.php/)
     With modified power routing by a cut PCB trace

     DEVICES:
     * CHIMU on SPI
     * XBee XSC 868/900Mhz
     * uBlox LEA5H and Sarantel helix GPS antenna flat in wing
     * Eagletree Airspeed sensor via I2C
     * Eagletree Height (Baro) sensor via I2C
     * Current sensor on analog port
     * RPM sensor for brushless measurments on ESC
     * Tilted Infrared sensor for X,Y,Z still on board for fun to compare with CHIIMU values, not for attitude in AP mode
     * DSMX receiver with CPPM out OR615X

     * SOON: Magnetometer, ESP8263WiFi telemetry

BUILDLINE
make -C $PAPARAZZI_HOME -f Makefile.ac AIRCRAFT=Moksha ap.compile

     NOTES:
     To ins_chimu_spi.c modified a line to this one below, since somehow roll and pitch setting where not getting through correctly:

       EstimatorSetAtt(CHIMU_DATA.m_attitude.euler.phi+ins_roll_neutral, CHIMU_DATA.m_attitude.euler.psi, CHIMU_DATA.m_attitude.euler.theta+ins_pitch_neutral);

     To test the "hatch" function we use bright lights, easy to spot from the
     ground, e.g for a droptest without dropping a thing...
     Ofcourse, also the log will show where a payload would have been released
     but lights are much more fun, and good for instant human feedback without the payload retrieval walk.

     NOTES:
     + Using Total Energy control as control loop
     + Make sure v5.5x master or higher of PPRZ sourcecode is used
     + Used mac06a.xml airframe as starting point for payload release settings

    Modules to activate:
     + Current sensor on battery wires going to motor
     + geo_mag module fixedwing

* -->
<!DOCTYPE airframe SYSTEM "../airframe.dtd">
<airframe name="Moksha">
<!-- ******************************* FIRMWARE ****************************** -->
  <firmware name="fixedwing">
    <target name="ap" board="twog_1.0">
      <!-- <define name="ADC_CHANNEL_VSUPPLY" value="4"/> -->
      <define name="SENSOR_SYNC_SEND"/>
    <!--  <configure name="PERIODIC_FREQUENCY" value="120"/>-->
<!--
      <configure name="AHRS_PROPAGATE_FREQUENCY" value="100"/>
      <configure name="AHRS_CORRECT_FREQUENCY" value="100"/>
      <define name="AHRS_TRIGGERED_ATTITUDE_LOOP"/>-->
      <define name="USE_I2C1"/>
      <define name="USE_UART1"/>
  <!--    <define name="USE_AHRS_GPS_ACCELERATIONS"/>-->
      <!--<define name="USE_BARO_ETS"/>-->
      <!-- obsolete with ABI ?-->
     <!-- <configure name="USE_BARO_BOARD" value="TRUE"/>-->
      <!--   <define name="USE_BAROMETER" value="TRUE"/> -->
      <configure name="AHRS_ALIGNER_LED" value="1"/>
      <configure name="CPU_LED" value="1"/>
      <define name="BAT_CHECKER_DELAY" value="80"/><!-- amount of time it take for the bat to check --><!-- to avoid bat low spike detection when strong pullup withch draws short sudden power-->
      <!-- <define name="LOW_BATTERY_KILL_DELAY" value="80"/>-->
      <define name="CATASTROPHIC_BATTERY_KILL_DELAY" value="80"/>
      <!--  <module name="current_sensor">-->
      <!-- <define name="USE_ADC_1"/>??-->
      <!--  <configure name="ADC_CURRENT_SENSOR" value="ADC_1"/>-->
      <!--</module>-->
      <module name="radio_control" type="ppm">
        <!-- for debugging PPM value the one below -->
         <!--<define name="TELEMETRY_MODE_FBW" value="1"/> -->
      </module>
   </target>

    <!-- ****************************** SIM *********************************-->
<!--
    <target name="sim" board="pc">
      <module name="radio_control" type="ppm"/>
    </target>
-->
    <!-- **************************** set for all *******************************-->
    <define name="USE_AIRSPEED"/><!-- set USE_AIRSPEED to use ets_airspeed in control loop -->
   <!-- <define name="AIRSPEED_ETS_SYNC_SEND"</define> --><!-- To get raw data for calibration of sensor, disable later on -->
    <!--  <define name="AGR_CLIMB"/> -->
    <!-- <define name="TUNE_AGRESSIVE_CLIMB"/>-->
    <define name="STRONG_WIND"/>
    <define name="WIND_INFO"/>
    <define name="WIND_INFO_RET"/>

    <module name="telemetry" type="transparent">
      <configure name="MODEM_BAUD" value="B9600"/>
      <configure name="MODEM_PORT" value="UART1"/>
    </module>

    <module name="control" type="energy"/>
    <module name="spi_slave_hs"/>

    <module name="ins" type="alt_float"/>
    <module name="gps" type="ublox">
      <configure name="GPS_BAUD" value="B38400"/>
      <configure name="GPS_PORT" value="UART0"/>
<!--
      <configure name="GPS_BAUD" value="B115200"/>
      <define name="GPS_UBX_UCENTER_RATE" value="200"/>
      <define name="USE_GPS_UBX_RXM_RAW"/>
      <define name="USE_GPS_UBX_RXM_SFRB"/>
      <define name="LOG_RAW_GPS"/>-->
    </module>
    <module name="navigation"/>
  </firmware>

  <modules main_freq="120">
<!-- ******************************* MODULES ******************************* -->
    <!-- <module name="gps" type="ubx_ucenter"/>--> <!-- Disable uCenter in the future, setup the hardware itself -->
    <module name="ahrs_chimu_spi"/>
       <!--    <define name="CHIMU_BIG_ENDIAN"/> -->
   <!--  </module>-->
    <!-- Navigation modules-->
    <module name="nav" type="drop"/>
    <module name="nav" type="line"/>
    <module name="nav" type="line_border"/>
    <module name="nav" type="line_osam"/>
    <module name="nav" type="survey_polygon"/>
    <module name="nav" type="survey_poly_osam"/>
    <module name="nav" type="smooth"/>
    <module name="nav" type="vertical_raster"/>
    <module name="nav" type="flower"/>
    <module name="nav" type="bungee_takeoff"/>
    <module name="nav" type="catapult"/>
    <!-- to test, analyze performance etc.-->
    <!-- module name="sys_mon"/> -->
    <!--
   <module name="flight_benchmark">
     <define name="BENCHMARK_TOLERANCE_AIRSPEED" value="2" unit="m/s"/>
     <define name="BENCHMARK_TOLERANCE_ALTITUDE" value="3" unit="m"/>
     <define name="BENCHMARK_TOLERANCE_POSITION" value="6" unit="m"/>
   </module>
   -->

    <!-- Airspeed sensor -->
    <module name="airspeed_ets">
      <define name="AIRSPEED_ETS_START_DELAY" value="1" unit="s"/>
      <define name="AIRSPEED_ETS_SYNC_SEND"/> <!-- TODO: SYNCSENDcan be commented out if it all works well no need to send debug data anymore-->
      <configure name="AIRSPEED_ETS_I2C_DEV" value="i2c1"/>
      <define name="AIRSPEED_ETS_SCALE" value="1.44"/> <!-- default 1.8 -->
      <define name="AIRSPEED_ETS_OFFSET" value="0"/>  <!-- default 0 -->
    </module>

<!--
    <module name="baro_board">
      <define name="BARO_ABS_EVENT" value="BaroEtsUpdate"/>
    </module>
-->
    <!--  <module name="adc_generic">-->
    <!-- If we want to read the voltage of battery voltage main engine over AP board via V_BATT -->
    <!-- To display the value,e.g. make a papget scale to 0.0048? and set 8.7 min 12.6max for a 3cell -->
    <!-- <configure name="ADC_CHANNEL_GENERIC1" value="4"/>-->
    <!-- Or if you like test. -->
    <!-- <configure name="ADC_CHANNEL_GENERIC1" value="BOARD_ADC_CHANNEL_4" /> -->
    <!-- On V_BAT_MEAS  on STM  Pin 24 PC4 adc14-->
    <!--
      <configure name="ADC_CHANNEL_GENERIC1" value="BOARD_ADC_CHANNEL_4"/>
      <configure name="ADC_CHANNEL_GENERIC2" value="13"/>
-->
    <!-- If an External analog Voltage and Amps sensor is connected use this -->
    <!--  <configure name="ADC_CHANNEL_GENERIC1" value="ADC_3"/>-->
    <!--   <configure name="ADC_CHANNEL_GENERIC2" value="ADC_4"/>-->
    <!--    </module>-->

    <!-- Set launch to 1 and place your bets ;) not in use at the moment -->
    <!-- <module name="nav" type="catapult"/> -->

    <module name="baro_sim"/>
  </modules>

<!-- ****************************** ACTUATORS ****************************** -->
  <servos>
    <!-- Define here to which CONNECTOR NUMBER the servo is connected to, on the autopilot cicuit board -->
    <servo name="MOTOR"         no="0" min="1050" neutral="1100" max="1900"/>
    <servo name="ELEVON_LEFT"   no="2" min="1900" neutral="1550" max="1100"/>
    <servo name="ELEVON_RIGHT"  no="6" min="1100" neutral="1460" max="1900"/>
    <!-- hatch is removable in this airframe, also handy if defined for fake drop with blinklight-->
    <servo name="HATCH"         no="7" min="1100" neutral="1110" max="1900"/>
    <servo name="LIGHTS"        no="5" min="1100" neutral="1110" max="1900"/>
  </servos>

<!-- ***************************** COMMANDS ******************************** -->
  <commands>
    <axis name="THROTTLE"        failsafe_value="0"/>
    <axis name="ROLL"            failsafe_value="0"/>
    <axis name="PITCH"           failsafe_value="0"/>
    <axis name="HATCH"           failsafe_value="-9599"/>
    <axis name="CLICKSHUTTER"    failsafe_value="-9599"/>
    <axis name="ACTIVELIGHTS"    failsafe_value="0"/>
    <!--
    <axis name="GAIN1"		failsafe_value="0"/>
    <axis name="CALIB"		failsafe_value="0"/>
    -->
  </commands>

<!-- *************************** RC COMMANDS ******************************* -->
  <rc_commands>

    <set command="THROTTLE"      value="@THROTTLE"/>
    <set command="ROLL"          value="@ROLL"/>
    <set command="PITCH"         value="@PITCH"/>
    <set command="HATCH"         value="@MANUALRELEASE"/>
    <set command="CLICKSHUTTER"  value="@MANUALRELEASE"/>
    <set command="ACTIVELIGHTS"  value="@MANUALRELEASE"/>
    <!--
    <set command="GAIN1"    value="@GAIN1"/>
    <set command="CALIB"    value="@CALIB"/>
    -->
  </rc_commands>

<!-- ************************ AUTO RC COMMANDS ***************************** -->
  <auto_rc_commands>

<!--For manual testing hatch triggering  <set command="HATCH"    value="@MANUALRELEASE"/> -->
    <set command="ACTIVELIGHTS" value="@MANUALRELEASE"/>
    <!--
    <set command="GAIN1"        value="@GAIN1"/>
    <set command="CALIB"        value="@CALIB"/>
    -->
  </auto_rc_commands>

  <section name="AUTO1" prefix="AUTO1_">
<!-- Do not set MAX_ROLL, MAX_PITCH to small of a value, otherwise one can NOT control the plane very well manually -->
<!-- If you have dual rate swith it of with same swtch as mode switch thus auto1 means dualrate is switched off also -->
    <define name="MAX_ROLL" value="85." unit="deg"/>
    <define name="MAX_PITCH" value="60." unit="deg"/>
  </section>

  <section name="MIXER">
    <define name="ELEVON_AILERON_RATE" value="0.60"/>
    <define name="ELEVON_ELEVATOR_RATE" value="0.50"/>
<!--    <define name="AILERON_DIFF" value="0.66"/> -->
  </section>

<!-- *************************** COMMAND-LAWS ****************************** -->
  <command_laws>
    <let var="aileron"          value="@ROLL  * ELEVON_AILERON_RATE"/>
    <let var="elevator"         value="@PITCH * ELEVON_ELEVATOR_RATE"/>
    <set servo="MOTOR"          value="@THROTTLE"/>
    <set servo="ELEVON_LEFT"   value="$elevator - $aileron"/>
    <set servo="ELEVON_RIGHT"  value="$elevator + $aileron"/>
<!-- Alternative way for actuator movement setup, not used at the moment -->
<!-- <set servo="ELEVON_LEFT"  value="(@ROLL*0.8f) + (@PITCH)"/> -->
<!-- <set servo="ELEVON_RIGHT" value="(@ROLL*0.8f) - (@PITCH)"/> -->
    <set servo="LIGHTS"         value="@ACTIVELIGHTS"/>
<!--   <set servo="LIGHTS"         value="(AP_MODE_AUTO2 ? MAX_PPRZ : @ACTIVELIGHTS)"/> -->
   <!-- TODO test if  tuning by RC still works -->
<!--  <let var="roll_neutral" value="@GAIN1"/> -->
<!--  <let var="ir_roll_neutral" value="@GAIN1"/> -->
<!--  <let var="ROLL_NEUTRAL_DEFAULT" value="@GAIN1"/> -->
  </command_laws>

<!--  activate fro comparison test -->
<!--
  <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="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"/>
    <define name="LATERAL_CORRECTION" value="1.45"/>
    <define name="LONGITUDINAL_CORRECTION" value="1.45"/>
    <define name="VERTICAL_CORRECTION" value="1.0"/>
    <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="5" unit="deg"/>
    <define name="PITCH_NEUTRAL_DEFAULT" value="0.5" unit="deg"/>
  </section>
-->

<!-- ******************************* TRIM ********************************** -->
  <section name="TRIM" prefix="COMMAND_">
    <define name="ROLL_TRIM" value="0"/>
    <define name="PITCH_TRIM" value="0"/>
  </section>

<!-- ***************************** FAILSAFE ******************************** -->
  <section name="FAILSAFE" prefix="FAILSAFE_">
    <define name="DEFAULT_THROTTLE" value="0.0" unit="%"/>
    <define name="DEFAULT_ROLL" value="0.2" unit="rad"/>
    <define name="DEFAULT_PITCH" value="-0.1" unit="rad"/>
    <define name="HOME_RADIUS" value="100" unit="m"/>
    <define name="KILL_MODE_DISTANCE" value="(MAX_DIST_FROM_HOME*1.5)"/>
    <define name="DELAY_WITHOUT_GPS" value="5" unit="s"/>
  </section>

<!-- ****************************IMU SENSOR ******************************** -->
  <section name="IMU" prefix="IMU_">

    <!-- Calibration Neutral -->
    <!-- ***************** ACCELO *****************-->
    <!--
    <define name="ACCEL_X_NEUTRAL" value="0"/>
    <define name="ACCEL_Y_NEUTRAL" value="0"/>
    <define name="ACCEL_Z_NEUTRAL" value="0"/>
-->
    <!-- SENS = 2048 LSB/g / 9.81 ms2/g = 208.766564729 LSB/ms2 / 10bit FRAC: 1024 / 208.7665 -->
    <!-- For newer MPU6000 set to 9.81 -->
    <!--    <define name="ACCEL_X_SENS" value="4.905" integer="16"/> -->
    <!-- For newer MPU6000 set to 9.81 -->
    <!--    <define name="ACCEL_Y_SENS" value="4.905" integer="16"/> -->
    <!-- For newer MPU6000 set to 9.81 -->
    <!--    <define name="ACCEL_Z_SENS" value="4.905" integer="16"/> -->
    <!--
<define name="ACCEL_X_SENS" value="4.905" integer="16"/>
<define name="ACCEL_Y_SENS" value="4.905" integer="16"/>
<define name="ACCEL_Z_SENS" value="4.905" integer="16"/>-->
    <define name="ACCEL_X_SIGN" value="1"/>
    <define name="ACCEL_Y_SIGN" value="1"/>
    <define name="ACCEL_Z_SIGN" value="1"/>
    <!-- ***************** GYRO *****************-->
    <!--
    <define name="GYRO_P_NEUTRAL" value="0"/>
    <define name="GYRO_Q_NEUTRAL" value="0"/>
    <define name="GYRO_R_NEUTRAL" value="0"/>-->
    <!-- SENS = 16.4 LSB/(deg/sec) * 57.6 deg/rad = 939.650 LSB/rad/sec / 12bit FRAC: 4096 / 939.65 -->
    <!--
      <define name="GYRO_P_SENS" value="4.359" integer="16"/>
      <define name="GYRO_Q_SENS" value="4.359" integer="16"/>
      <define name="GYRO_R_SENS" value="4.359" integer="16"/>
-->
    <define name="GYRO_P_SIGN" value="1"/>
    <define name="GYRO_Q_SIGN" value="1"/>
    <define name="GYRO_R_SIGN" value="1"/>
    <!-- ***************** MAGNETO *****************-->
    <!-- TODO: Calibrate, AND RE-CALIBRATE after aircraft changes !-->
    <define name="MAG_X_NEUTRAL" value="-136"/>
    <define name="MAG_Y_NEUTRAL" value="-130"/>
    <define name="MAG_Z_NEUTRAL" value="141"/>
    <define name="MAG_X_SENS" value="3.51854936936" integer="16"/>
    <define name="MAG_Y_SENS" value="3.48065294671" integer="16"/>
    <define name="MAG_Z_SENS" value="4.08548845489" integer="16"/>
    <define name="MAG_X_SIGN" value="1"/>
    <define name="MAG_Y_SIGN" value="1"/>
    <define name="MAG_Z_SIGN" value="1"/>
    <!-- Set body to IMU here -->
    <!--
Phi -1.6
Theta -2.2
Psi -109
-->
    <!--Switched -90deg axis, thus ** set Phi = Theta!! and Theta = Phi!! **-->
    <define name="BODY_TO_IMU_PHI" value="0.0" unit="rad"/>
    <!-- e.g. -0.085 rad from messages -->
    <define name="BODY_TO_IMU_THETA" value="0.0" unit="rad"/>
    <!-- e.g. 0.09 rad from messages -->
    <define name="BODY_TO_IMU_PSI" value="0.0" unit="deg"/>
    <!-- -90. is pins to tail of airfame -->
  </section>

<!--
  <section name="AHRS" prefix="AHRS_">-->
<!-- ****************************** AHRS *********************************** -->
    <!--TODO: start using geo_mag module, else replace the values with your local magnetic field -->
    <!-- Local Magnetic field NL Testfield 2010-->
    <!--
     <define name="H_X" value="0.382478"/>
     <define name="H_Y" value="0.00563406"/>
     <define name="H_Z" value="0.923948"/>
   -->
    <!-- Local Magnetic field DE Testfield 2010 -->
  <!--  <define name="H_X" value="0.51562740288882"/>
    <define name="H_Y" value="-0.05707735220832"/>
    <define name="H_Z" value="0.85490967783446"/>
  </section>-->

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

<!-- ******************************** GAINS ******************************** -->

  <section name="HORIZONTAL CONTROL" prefix="H_CTL_">
<!-- ******************* HORIZONTAL CONTROL ******************************** -->
    <define name="COURSE_PGAIN" value="0.8"/>
    <define name="COURSE_DGAIN" value="0.15"/>
    <!-- The prebank is an adjustment to the roll setting which is done when the aircraft is trying to do a circle and when it is close to the circumference of the circle. This way it does not fly straight into the circumference but instead it starts to make a roll as the one needed to fly in circles.
There is a value in the airframe file COURSE_PRE_BANK_CORRECTION which can be used to increase o decrease the effect. If set to 1 then the normal prebank is done. If set to 0.5 then half of the additional roll is done. This causes the aircraft to not roll enough in order to fly the intended circle and it ends up flying in a larger circle.  A value > 1 makes it fly a smaller circle.

https://github.com/paparazzi/paparazzi/blob/master/sw/airborne/modules/nav.c#L132
-->
    <define name="COURSE_PRE_BANK_CORRECTION" value="1.0"/>
    <!-- TODO: Tune value -->
    <define name="ROLL_MAX_SETPOINT" value="60.0" unit="deg"/>
    <define name="ROLL_ATTITUDE_GAIN" value="11000"/>
    <define name="ROLL_RATE_GAIN" value="1400"/>
    <define name="ROLL_IGAIN" value="20"/>
    <define name="ROLL_KFFA" value="0"/>
    <define name="ROLL_KFFD" value="0"/>
    <!-- PITCH -->
    <define name="PITCH_MAX_SETPOINT" value="60" unit="deg"/>
    <define name="PITCH_MIN_SETPOINT" value="-60" unit="deg"/>
    <define name="PITCH_PGAIN" value="10000."/>
    <define name="PITCH_DGAIN" value="5"/>
    <!-- <define name="PITCH_IGAIN" value="10."/>-->
    <define name="PITCH_KFFA" value="0."/>
    <define name="PITCH_KFFD" value="0."/>
    <!-- TODO: solve without ELEVATOR_OF_ROLL etc. needs to be set still taking great smooth corners-->
    <define name="ELEVATOR_OF_ROLL" value="0"/>
    <!-- TODO: Make testflight with log of radical manual flight-->
    <!--   <define name="PITCH_OF_ROLL" value="RadOfDeg(1.0)"/>-->
    <define name="AILERON_OF_THROTTLE" value="0.0"/>
    <!-- DON'T USE unnless you know what you are doing-->
    <define name="ROLL_SLEW" value="0.2"/>
    <!--TODO: Describe why we would need it-->
  </section>

  <section name="VERTICAL CONTROL" prefix="V_CTL_">
<!-- ******************* VERTICAL CONTROL ********************************** -->
    <define name="POWER_CTL_BAT_NOMINAL" value="11.2" unit="volt"/>
    <!-- HUH to throttle? -->
    <!-- outer loop proportional gain -->
    <define name="ALTITUDE_PGAIN" value="0.15"/>
    <!-- outer loop saturation -->
    <define name="ALTITUDE_MAX_CLIMB" value="3." unit="m/s"/>
    <!--  <define name="ALTITUDE_PRE_CLIMB_CORRECTION" value="0.1"/> -->
    <!-- auto throttle inner loop -->
    <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.6"/>
    <define name="AUTO_THROTTLE_NOMINAL_CRUISE_PITCH" value="0."/>
    <!-- default 0 -->
    <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.3"/><!--{TODO} TWOG need this define?-->
    <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="1.0"/>
    <!-- TODO add limit for airspeed based on 13m/s max wind + cameaaspeed max 0.25hz max ans lens  o max GS 21m/s>
    <define name="AIRSPEED_MAX" value="31" unit=""m/s"/> -->
    <!--21+13 -->
    <!-- TODO add limit
    <define name="AIRSPEED_MIN" value="10" unit=""m/s"/> -->
    <!-- Only set to a value in initial flight until airspeed is proven to work well, else set to 0 -->
    <define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0." unit="%/(m/s)"/>
    <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0."/>
    <define name="AIRSPEED_PGAIN" value="0.15"/>
    <define name="AUTO_THROTTLE_OF_AIRSPEED_PGAIN" value="0.0"/>
    <define name="AUTO_THROTTLE_OF_AIRSPEED_IGAIN" value="0.0"/>
    <!--UNKN-->
    <define name="AUTO_PITCH_OF_AIRSPEED_PGAIN" value="0.0"/>
    <define name="AUTO_PITCH_OF_AIRSPEED_IGAIN" value="0.0"/>
    <define name="AUTO_PITCH_OF_AIRSPEED_DGAIN" value="0.0"/>
    <!-- TODO: unknown values yet, see MORA camscan documentation -->

    <define name="AUTO_GROUNDSPEED_SETPOINT" value="16." unit="m/s"/>
    <define name="AUTO_GROUNDSPEED_PGAIN" value="0.7"/>
    <define name="AUTO_GROUNDSPEED_IGAIN" value="0."/>

    <define name="AUTO_THROTTLE_PGAIN" value="0.7"/>
    <define name="AUTO_THROTTLE_IGAIN" value="0."/>

    <define name="AUTO_AIRSPEED_SETPOINT" value="13." unit="m/s"/>
    <define name="AUTO_AIRSPEED_PGAIN" value="0.7"/>
    <define name="AUTO_AIRSPEED_IGAIN" value="0."/>

    <define name="AUTO_PITCH_MAX_PITCH" value="60.0" unit="deg"/>
    <define name="AUTO_PITCH_MIN_PITCH" value="60.0" unit="deg"/>

    <define name="THROTTLE_SLEW_LIMITER" value="0.5" unit="m/s/s"/>
    <define name="GLIDE_RATIO" value="10"/>
    <!-- TODO: testfly with AOW full weight to get value, now unknown -->
    <!-- ENERGY_TOT="" unknown -->
    <define name="ENERGY_TOT_PGAIN" value="0.3"/>
    <define name="ENERGY_TOT_IGAIN" value="0.25"/>
    <define name="ENERGY_DIFF_PGAIN" value="0.3"/>
    <define name="ENERGY_DIFF_IGAIN" value="0.25"/>
  </section>

<!--
  <section name="AGGRESSIVE" prefix="AGR_">
    <define name="BLEND_START" value="20"/>
    <define name="BLEND_END" value="10"/>
    <define name="CLIMB_THROTTLE" value="0.99"/>
    <define name="CLIMB_PITCH" value=".4" unit="rad"/>
    <define name="DESCENT_THROTTLE" value="0.2"/>
    <define name="DESCENT_PITCH" value="-0.3"/>
    <define name="CLIMB_NAV_RATIO" value="0.8"/>
    <define name="DESCENT_NAV_RATIO" value="0.99"/>
  </section>
-->

  <section name="BAT">
<!-- ****************************** BAT ************************************ -->

<!-- If current-volts sensor is installed use line below-->
<!-- <define name="ADC_CHANNEL_CURRENT" value="ADC_3" /> -->
<!-- <define name="MilliAmpereOfAdc(adc)" value="(adc*88)"/> -->

<!-- <define name="ADC_CHANNEL_VOLTAGE" value="ADC_4" /> -->
<!-- The real multiplier is unknown we take 2 as test example -->
<!--  <define name="VoltageOfAdc(adc)" value ="(adc*2)"/>  -->

<!-- If NO current-volts sensor installed uncomment below -->
    <define name="MILLIAMP_AT_FULL_THROTTLE" value="17000" unit="mA"/>

<!--
    <define name="VOLTAGE_ADC_A" value="0.0177531"/>
    <define name="VOLTAGE_ADC_B" value="0.173626"/>
    <define name="VoltageOfAdc(adc)" value ="(VOLTAGE_ADC_A * adc + VOLTAGE_ADC_B)"/>
-->

    <define name="CATASTROPHIC_BAT_LEVEL" value="9.1" unit="V"/> <!-- 3S lipo 3.1*3=9.3 -->
    <define name="CRITIC_BAT_LEVEL" value="9.6" unit="V"/>
    <define name="LOW_BAT_LEVEL" value="10.2" unit="V"/>
    <define name="MAX_BAT_LEVEL" value="12.6" unit="V"/> <!-- 3S lipo 4.2*3=12.6 -->
  </section>

  <section name="MISC">
<!-- ****************************** MISC *********************************** -->
    <!-- Values here are only referred to by the flightplan m*_s*_airspeed.xml -->
    <define name="CLIMB_AIRSPEED" value="13." unit="m/s"/>
    <define name="NOMINAL_AIRSPEED" value="14." unit="m/s"/>
    <define name="GLIDE_AIRSPEED" value="11." unit="m/s"/>
    <define name="RACE_AIRSPEED" value="22." unit="m/s"/>
    <define name="STALL_AIRSPEED" value="10." unit="m/s"/><!--TODO test -->
    <!-- to high now, H stall to test with full weight-->
    <define name="AIRSPEED_SETPOINT_SLEW" value="0.5" unit="m/s/s"/>
    <!--default is 1 -->
    <!--TODO:  mybe not needed anymore
    <define name="GLIDE_VSPEED" value="2." unit="m/s"/>
    <define name="GLIDE_PITCH" value="10." unit="deg"/>
-->
    <define name="NAV_GLIDE_PITCH_TRIM" value="-1.0" unit="deg"/>
    <define name="CARROT" value="5." unit="s"/>
    <define name="CONTROL_FREQUENCY" value="100." unit="Hz"/><!-- 60HZ ? -->
    <!--<define name="ALT_KALMAN_ENABLED" value="TRUE"/>-->
    <define name="DEFAULT_CIRCLE_RADIUS" value="110."/> <!--TODO determine best value -->
    <define name="MIN_CIRCLE_RADIUS" value="80."/><!-- Needed for spiral navigation function--> <!--TODO determine best value -->

    <!--UNLOCKED_HOME_MODE if set to TRUE means that HOME mode does not get stuck.
If not set before when you would enter home mode you had to flip a bit via the GCS to get out. -->
    <define name="UNLOCKED_HOME_MODE" value="TRUE"/>
    <!-- RC_LOST_MODE means that if your RC Transmitter signal is not received anymore in the autopilot, e.g. you switch it off
     or  fly a long range mission you define the wanted mode behaviour here.
     If you do not define it, it defaults to flying to the flightplan HOME -->
    <define name="RC_LOST_MODE" value="AP_MODE_AUTO2"/>
    <define name="NO_XBEE_API_INIT" value="TRUE"/>
  </section>

<!-- ********************* HAND AND CATAPULT LAUNCH ************************ -->

  <!-- the "CATAPULT" in some cases is a Human throwing the plane, and to protect the hands agains a prop strike
we have an option to use glovs, or start up spinning the prop after a throw. If this works out well, let's use it
 Makes the life of autotakeoff less scary -->
  <!--  <section name="CATAPULT" prefix="NAV_CATAPULT_"> -->
  <!--    <define name="MOTOR_DELAY" value=".1" unit="seconds"/> -->
  <!-- TODO:  determine best value, firs set to very small or 0 so engine start immidiatlely -->
  <!-- make sre you ESC has no startup delay -->
  <!-- 120 should be repalced by PERIODIC_FREQUENCY -->
  <!--    <define name="HEADING_DELAY" value="(120*3)" unit="seconds"/>-->
  <!-- 3 seconds, the -->
  <!--    <define name="ACCELERATION_THRESHOLD" value="1.75" />-->
  <!--TODO: unit and tune this with final weight in airframe not to high otherwise engine will not run-->
  <!--    <define name="INITIAL_PITCH" value="20.0" unit="deg"/>-->
  <!--TODO: tune this, look at graphs from manual flights-->
  <!--    <define name="INITIAL_THROTTLE" value="1.0"/>-->
  <!-- PCT from 0 to 1, where 1 is 100% -->
  <!--  </section>-->

<!-- ************************ GCS SPECIFICS ******************************** -->
  <section name="GCS">
    <define name="SPEECH_NAME" value="Moksha"/>
  </section>

<!-- ************************** GLS LANDING ******************************** -->
  <section name="GLS_APPROACH" prefix="APP_">
    <define name="ANGLE" value="7" unit="deg"/>
    <define name="INTERCEPT_AF_SD" value="80" unit="m"/>
    <define name="TARGET_SPEED" value="13" unit="m/s"/>
  </section>

    <section name="SIMU">
    <define name="YAW_RESPONSE_FACTOR" value="0.5"/> <!-- a to low of a value gives bad default build in simulation results -->
  </section>
 <!--
<firmware name="setup">
    <target name="tunnel" board="twog_1.0"/>   <!-  used for Ublox setup via uCenter under WINE ->
</firmware>
-->

</airframe>
