<!DOCTYPE airframe SYSTEM "../airframe.dtd">
<!-- Graupner Taxi III electro (http://www.graupner.de/)
     TINY (http://paparazzi.enac.fr/wiki/index.php/)
     * Aligned Infrared sensor for X,Y,Z
     * Various options to connect XBee XSC 900Mhz or RFD900A or RFD868+
     * GPS uBlox LEA5H
     * 35Mhz CPPM receiver

     Notes:
     * The two aileron servos are connected via a Y-split cable and on
     one actuator out connection on the board, no differential aileron possible :(
-->

<airframe name="TaxiIII">

  <firmware name="fixedwing">
    <target name="sim" 			        board="pc"/>

    <target name="ap" 			        board="tiny_2.11"/>
    <define name="STRONG_WIND"/>
    <define name="WIND_INFO"/>
    <define name="WIND_INFO_RET"/>
    <define name="AGR_CLIMB"/>
    <define name="TUNE_AGRESSIVE_CLIMB"/>
    <define name="USE_I2C0"/>
    <define name="PITCH_TRIM"/>

    <define name="USE_I2C0"/>

    <module name="radio_control" type="ppm">
       <!-- for debugging PPM value the one below -->
       <!-- <define name="TELEMETRY_MODE_FBW" value="1"/> -->
    </module>

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

    <module name="control"/>
    <module name="ins"           type="alt_float"/>
    <module name="gps"           type="ublox"/>
    <module name="navigation"/>
    <!-- for setting values e.g. IR tuning via RC Tranmitter -->
    <!-- <module name="settings" type="rc"/>-->

  </firmware>

  <modules>
    <module name="gps" type="ubx_ucenter"/>
    <module name="infrared_adc"/>
    <module name="ahrs_infrared"/>  

    <module name="digital_cam">
      <!-- <define name="DC_SHUTTER_GPIO" value="CAM_SWITCH_GPIO"/>--><!-- Not compiling ATM -->
      <define name="DC_SHUTTER_GPIO" value="GPIOB,GPIO22"/>
    </module>  
<!--
    <module name="sys_mon"/>
-->

<!--
    <module name="adc_generic">
-->
<!-- Voltage measuring sensor -->
<!--
      <configure name="ADC_CHANNEL_GENERIC1" value="ADC_3"/>
-->
<!-- RPM measuring sensor -->
<!--
      <configure name="ADC_CHANNEL_GENERIC2" value="ADC_4"/>
-->
<!-- Current measuring sensor -->
<!--
      <configure name="ADC_CHANNEL_GENERIC1" value="ADC_7"/>
    </module>
-->
    <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"/>
    
  </modules>

<!-- Define here to which CONNECTOR NUMBER the servo is connected to, on the autopilot cicuit board -->
  <servos>
  <!-- Make sure esc is set to fixed endpoints, e.g.CastleCreastions range fixed is 1250ms - 1800ms -->
    <servo name="MOTOR"         no="0" min="1250" neutral="1300" max="1850"/>
    <servo name="AILERON"       no="2" min="1900" neutral="1500" max="1100"/>
    <servo name="ELEVATOR"      no="3" min="1100" neutral="1500" max="1900"/>
    <servo name="RUDDER"        no="4" min="1100" neutral="1500" max="1900"/>
  </servos>

<!-- commands section -->
  <commands>
    <axis name="THROTTLE" 	failsafe_value="0"/>
    <axis name="ROLL"     	failsafe_value="0"/>
    <axis name="PITCH"    	failsafe_value="0"/>
    <axis name="YAW"      	failsafe_value="0"/>
<!-- for tuning via RC these ones below -->
<!--
    <axis name="GAIN1"		failsafe_value="0"/>
    <axis name="CALIB"		failsafe_value="0"/>
    -->
  </commands>

  <rc_commands>
    <set command="THROTTLE" value="@THROTTLE"/>
    <set command="ROLL"     value="@ROLL"/>
    <set command="PITCH"    value="@PITCH"/>
    <set command="YAW"      value="@YAW"/>
    <!-- for tuning via RC these ones below -->
<!--
    <set command="GAIN1"    value="@GAIN1"/>
    <set command="CALIB"    value="@CALIB"/>
-->
  </rc_commands>

  <auto_rc_commands>
  <!-- To still be able to use rudder, which is needed with sidewind landing in auto1 stabilization mode only YAW -->
    <set command="YAW"      value="@YAW"/>
    <!-- for tuning via RC these ones below -->
<!--
    <set command="GAIN1"    value="@GAIN1"/>
    <set command="CALIB"    value="@CALIB"/> -->
  </auto_rc_commands>

<!--For mixed controlflaps -->
  <section name="MIXER">
     <!-- just a tiny bit works well-->
     <define name="ASSIST_ROLL_WITH_RUDDER" value="0.09"/>
  </section>

  <command_laws>
    <set servo="MOTOR"         value="@THROTTLE"/>
    <set servo="AILERON"       value="@ROLL"/>
    <set servo="ELEVATOR"      value="@PITCH"/>
    <set servo="RUDDER"        value="@YAW - @ROLL*ASSIST_ROLL_WITH_RUDDER"/>
  </command_laws>

<!-- 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 -->
  <section name="AUTO1" prefix="AUTO1_">
    <define name="MAX_ROLL" value="0.95"/> <!-- radians -->
    <define name="MAX_PITCH" value="0.95"/> <!-- radians -->
<!-- Or use as below -->
<!--    <define name="MAX_ROLL" value="RadOfDeg(95)"/> -->
<!--    <define name="MAX_PITCH" value="RadOfDeg(95)"/> -->
  </section>

  <section name="INFRARED" prefix="IR_">
<!-- NEUTRAL value below set via caliberation with all sensors covert and intill set to 0 the read via telemetry data and in this case 515 etc filled in later and reuploaded -->
<!-- In this plane IR1 points to side to side, the latereal axis -->
<!-- In this plane IR2 points to front and back, the longitudinal axis -->

<!--Reminder: reads X if value=0 is uploaded in airframe -->
    <define name="ADC_IR1_NEUTRAL" value="512"/>
<!--Reminder: reads X if value=0 is uploaded in airframe -->
    <define name="ADC_IR2_NEUTRAL" value="512"/>
<!--Reminder: reads X if value=0 is uploaded in airframe -->
    <define name="ADC_TOP_NEUTRAL" value="512"/>

<!-- old way
 <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"/>
-->

<!-- =============== possible new values =========================  -->
<!--   <define name="DEFAULT_CONTRAST" value="200"/> -->
<!--   <define name="RAD_OF_IR_CONTRAST" value="0.75"/> -->
<!--   <linear name="RollOfIrs" arity="2" coeff1="0.7" coeff2="-0.7"/> -->
<!--   <linear name="PitchOfIrs" arity="2" coeff1="0.7" coeff2="0.7"/> -->
<!--   <linear name="TopOfIr" arity="1" coeff1="-1"/> -->
<!--   <define name="RAD_OF_IR_MAX_VALUE" value="0.0045"/> -->
<!--   <define name="RAD_OF_IR_MIN_VALUE" value="0.00075"/> -->
<!--  ============== possible new values end ===================== -->

<!-- The three axis must give similar values for similar air to ground contrasts. -->
<!-- If you e.g. have a different brand of IR piles for straight up n down sensors. -->

    <define name="LATERAL_CORRECTION" value="0.8"/> <!-- was in the past 360_LATERAL_CORRECTION -->
    <define name="LONGITUDINAL_CORRECTION" value="0.8"/> <!-- was in the past 360_LONGITUDINAL_CORRECTION -->
<!-- One can set the top down correction a little lower so leftrightfrontback is more accurate n faster -->
    <define name="VERTICAL_CORRECTION" value="1.1"/>  <!-- was in the past 360_VERTICAL_CORRECTION -->

<!-- ONLY enable the line below if the sensor is ALIGENED front to back, side to side. Thus not 45deg rotated, and Disable the TILTED LINE -->
    <define name="HORIZ_SENSOR_ALIGNED" value="1"/>
<!-- ONLY enable the line below if the sensor is TILTED, and Disable the ALIGENED LINE -->
<!--    <define name="HORIZ_SENSOR_TILTED" value="1"/> -->

<!-- Ground(=Hotter than sky) on right side of airframe as seen from back -->
<!-- The Hotter side must give a positive value maybe -->

<!-- In this airframe IR1 points to front and side, the latereal AND longitudinal axis -->
    <define name="IR1_SIGN" value="-1"/>
<!-- In this airframe IR2 points to front and side, the latereal AND longitudinal axis -->
    <define name="IR2_SIGN" value="-1"/>
    <define name="TOP_SIGN" value="1"/>

<!-- below is very important per individual airframe, first set to 0,
then adjusted after testflight data is analyzed.
Setting also can be adjusted realtime via tuning config
or tuning_via?_transmitter config.
-->
    <define name="ROLL_NEUTRAL_DEFAULT" value="0" unit="deg"/>
    <define name="PITCH_NEUTRAL_DEFAULT" value="0" unit="deg"/>
  </section>

  <section name="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="18000" 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.3" unit="V"/> <!-- 3S lipo 3.1*3=9.3 -->
    <define name="CRITIC_BAT_LEVEL" value="10.0" unit="V"/>
    <define name="LOW_BAT_LEVEL" value="10.6" unit="V"/>
    <define name="MAX_BAT_LEVEL" value="12.6" unit="V"/> <!-- 3S lipo 4.2*3=12.6 -->
  </section>

  <section name="MISC">
    <define name="MINIMUM_AIRSPEED" value="10." unit="m/s"/>
    <define name="NOMINAL_AIRSPEED" value="14." unit="m/s"/>
    <define name="MAXIMUM_AIRSPEED" value="20." unit="m/s"/>
    <define name="CARROT" value="5." unit="s"/>
    <define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
<!--    <define name="XBEE_INIT" value="ATPL2\rATRN1\rATTT80\r" type="string"/> -->
<!--    <define name="NO_XBEE_API_INIT" value="TRUE"/> -->
   <!-- <define name="CONTROL_FREQUENCY" value="60" unit="Hz"/>-->

<!--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"/>

    <!-- OLD <define name="ALT_KALMAN_ENABLED" value="TRUE"/>-->
    <define name="TRIGGER_DELAY" value="1.0"/>
    <define name="DEFAULT_CIRCLE_RADIUS" value="70.0"/>
    <define name="MIN_CIRCLE_RADIUS" value="50.0"/><!-- needed for some nav modules like spiral-->

<!-- The Glide definitions are used for calculating the touch down point during auto landing -->
   <!-- <define name="GLIDE_AIRSPEED" value="11."/>
    <define name="GLIDE_VSPEED" value="1." unit="m/s"/>
    <define name="GLIDE_PITCH" value="7." unit="deg"/>-->
  </section>

<!-- ******************* VERTICAL CONTROL ******************************** -->
  <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.06"/> <!--unit="(m/s)/m"-->
    <!-- outer loop saturation -->
    <define name="ALTITUDE_MAX_CLIMB" value="2." unit="m/s"/>

    <!-- auto throttle inner loop -->
    <!-- auto throttle inner loop -->
   <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.85" unit="%"/>
   <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.65" unit="%"/>
   <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.99" unit="%"/>
   <define name="AUTO_THROTTLE_LOITER_TRIM" value="1000" unit="pprz_t"/>
   <define name="AUTO_THROTTLE_DASH_TRIM" value="-2000" unit="pprz_t"/>
   <define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.1" unit="%/(m/s)"/>

   <define name="AUTO_THROTTLE_PGAIN" value="0.0007" unit="%/(m/s)"/>
   <define name="AUTO_THROTTLE_IGAIN" value="0.002"/>
   <define name="AUTO_THROTTLE_DGAIN" value="0.0"/>
   <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.2" unit="rad/(m/s)"/>
   <define name="THROTTLE_SLEW_LIMITER" value="0.8" unit="s"/>

<!-- NOT YET USED auto airspeed and altitude inner loop -->
<!--    <define name="AIRSPEED_ETS_OFFSET" value="1542"/> -->

<!-- NEVER set AUTO_AIRSPEED_SETPOINT lower than airframe stall speed -->

<!--
    <define name="AUTO_AIRSPEED_SETPOINT" value="19.0" unit="m/s"/>
    <define name="AUTO_AIRSPEED_PGAIN" value="0.1"/>
    <define name="AUTO_AIRSPEED_IGAIN" value="0.05"/>
    <define name="AUTO_AIRSPEED_PITCH_PGAIN" value="0" unit="degree/(m/s)"/>
    <define name="AUTO_AIRSPEED_THROTTLE_PGAIN" value="0" unit="%/(m/s)"/>
    <define name="AUTO_AIRSPEED_THROTTLE_IGAIN" value="0"/>
-->

<!-- investigate: if higher _AIRSPEED_SETPOINT then airframe tries to maintain a constand ground speed UNKNOWN -->

<!--
    <define name="AUTO_GROUNDSPEED_SETPOINT" value="14.0" unit="m/s"/>
    <define name="AUTO_GROUNDSPEED_PGAIN" value="0.75"/>
    <define name="AUTO_GROUNDSPEED_IGAIN" value="0.25"/>
-->

    <!-- auto pitch inner loop -->
<!-- auto pitch inner loop -->
   <define name="AUTO_PITCH_PGAIN" value="0.052"/>
   <define name="AUTO_PITCH_IGAIN" value="0.065"/>
   <define name="AUTO_PITCH_MAX_PITCH" value="0.45"/>
   <define name="AUTO_PITCH_MIN_PITCH" value="-0.40"/>
  <!-- <define name="THROTTLE_SLEW" value="0.3"/> --> <!-- limiter for powerfull engines -->

    <!-- pitch trim -->
<!-- not used for now -->
   <!-- <define name="PITCH_LOITER_TRIM" value="RadOfDeg(5.)"/>
    <define name="PITCH_DASH_TRIM" value="RadOfDeg(-5.)"/>-->

  </section>

<!-- ******************* HORIZONTAL CONTROL ******************************** -->

  <section name="HORIZONTAL CONTROL" prefix="H_CTL_">
    <define name="COURSE_PGAIN" value="1.0"/>
    <define name="ROLL_MAX_SETPOINT" value="0.60" unit="rad"/>
    <define name="PITCH_MAX_SETPOINT" value="0.5" unit="rad"/>
    <define name="PITCH_MIN_SETPOINT" value="-0.5" unit="rad"/>

    <define name="ROLL_ATTITUDE_GAIN" value="5900"/>
    <define name="ROLL_RATE_GAIN" value="2900"/>
    <define name="ROLL_IGAIN" value="500"/>
    <define name="ROLL_KFFA" value="500"/>
    <define name="ROLL_KFFD" value="500"/>

    <define name="PITCH_PGAIN" value="9000."/>
    <define name="PITCH_DGAIN" value="1.5"/>
    <define name="PITCH_IGAIN" value="500"/>
    <define name="PITCH_KFFA" value="0."/>
    <define name="PITCH_KFFD" value="0."/>

    <define name="PITCH_OF_ROLL" value="RadOfDeg(0.2)"/>
    <define name="ELEVATOR_OF_ROLL" value="0"/>
 </section>

  <section name="NAV">
<!-- <define name="NAV_PITCH" value="0."/>-->
    <define name="NAV_GLIDE_PITCH_TRIM" value="0"/>
  </section>

<!-- ***************************** AGGRESIVE ******************************* -->
  <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="8"/> <!-- Altitude Error to Blend Aggressive to Regular Climb Modes  CANNOT BE ZERO!!-->
    <define name="CLIMB_THROTTLE" value="0.90"/> <!-- Gaz for Aggressive Climb -->
    <define name="CLIMB_PITCH" value="RadOfDeg(45)"/> <!-- Pitch for Aggressive Climb -->
    <define name="DESCENT_THROTTLE" value="0.4"/> <!-- Gaz for Aggressive Decent -->
    <define name="DESCENT_PITCH" value="RadOfDeg(-30)"/> <!-- 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="0.99"/>
  </section>

<!-- ****************************** FAILSAFE ******************************* -->
  <section name="FAILSAFE" prefix="FAILSAFE_">
    <define name="DELAY_WITHOUT_GPS" value="3" unit="s"/>
    <define name="DEFAULT_THROTTLE" value="0" unit="%"/>
    <define name="DEFAULT_ROLL" value="0.15" unit="rad"/>
    <define name="DEFAULT_PITCH" value="-0.1" unit="rad"/>
    <define name="HOME_RADIUS" value="70" unit="m"/>
  </section>

<!-- ****************************** DATALINK ******************************* -->
  <section name="DATALINK" prefix="DATALINK_">
    <define name="DEVICE_TYPE" value="PPRZ"/>
    <define name="DEVICE_ADDRESS" value="...."/>
  </section>
  
  <section name="DIGITAL_CAMERA" prefix="DC_">
    <define name="AUTOSHOOT_PERIOD" value="3" unit="sec"/>
    <define name="AUTOSHOOT_DISTANCE_INTERVAL" value="70" unit="meter"/>
  </section>

<!-- ******************************** SIMU ********************************* -->
  <section name="SIMU">
    <define name="YAW_RESPONSE_FACTOR" value="0.5"/> <!-- a to low of a value gives bad simulation results -->
  </section>

</airframe>

