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

<airframe name="MiniMag Laas N1 Tiny 0.99">

  <firmware name="fixedwing">
    <target name="sim" 			board="pc">
      <define name="AGR_CLIMB" />
      <define name="LOITER_TRIM" />
    </target>
    <target name="ap" 			board="tiny_0.99">
      <define name="AGR_CLIMB" />
      <define name="LOITER_TRIM" />
    </target>

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

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

    <subsystem name="control"/>
    <!-- Sensors -->
    <subsystem name="gps" 		    type="ublox_utm"/>
    <subsystem name="navigation"/>
    <subsystem name="ins" type="alt_float"/>
  </firmware>

  <firmware name="setup">
    <target name="tunnel"           board="tiny_0.99" />
    <target name="setup_actuators"  board="tiny_0.99" />
  </firmware>

  <modules>
    <load name="formation_flight.xml"/>
    <!-- <load name="tcas.xml"/> -->
    <!--load name="potential.xml"/-->
    <load name="cartography.xml"/>
    <load name="infrared_adc.xml">
      <configure name="ADC_IR1" value="ADC_1"/>
      <configure name="ADC_IR2" value="ADC_0"/>
      <configure name="ADC_IR_TOP" value="ADC_2"/>
    </load>
    <load name="ahrs_infrared.xml"/>
  </modules>





<!-- commands section -->
  <servos>
    <servo name="THROTTLE"   no="0" min="1200" neutral="1200" max="2000"/>
<!-- Aileron gauche (blanc) oppose de l'aileron droit (jaune) -->
<!-- max = valeur aileron vers le bas-->
    <servo name="AILERON_LEFT"  no="3" min="1900" neutral="1450" max="1100"/>
    <servo name="AILERON_RIGHT" no="1" min="1900" neutral="1520" max="1100"/>
    <servo name="RUDDER" no="4" min="1850" neutral="1500" max="1150"/>
    <servo name="ELEVATOR" no="5" min="2000" neutral="1568" max="1150"/>

  </servos>

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

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

  <section name="MIXER">
    <define name="AILERON_DIFF" value="0.66"/>
    <define name="COMBI_SWITCH" value="1.0"/>
  </section>

  <command_laws>
    <set servo="THROTTLE"           value="@THROTTLE"/>
    <set servo="ELEVATOR" value="@PITCH"/>
    <set servo="RUDDER" value="@YAW + @ROLL*COMBI_SWITCH"/>

    <let var="roll" value="@ROLL"/>
    <set servo="AILERON_LEFT" value="($roll > 0 ? 1 : AILERON_DIFF) * $roll"/>
    <set servo="AILERON_RIGHT" value="($roll > 0 ? AILERON_DIFF : 1) * $roll"/>
  </command_laws>

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

  <section name="INFRARED" prefix="IR_">
    <define name="ROLL_NEUTRAL_DEFAULT" value="-2.6" unit="deg"/>
    <define name="PITCH_NEUTRAL_DEFAULT" value="8.6" unit="deg"/>

    <define name="HORIZ_SENSOR_TILTED" value="1"/>
    <define name="IR2_SIGN" value="1"/>
    <define name="TOP_SIGN" value="1"/>

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

    <define name="ADC_IR1_NEUTRAL" value="507"/>
    <define name="ADC_IR2_NEUTRAL" value="509"/>
    <define name="ADC_TOP_NEUTRAL" value="515"/>

    <define name="LATERAL_CORRECTION" value="1."/>
    <define name="LONGITUDINAL_CORRECTION" value="-1."/>
    <define name="VERTICAL_CORRECTION" value="1.5"/>
  </section>

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

  <section name="MISC">
    <define name="NOMINAL_AIRSPEED" value="11." unit="m/s"/>
    <define name="MINIMUM_AIRSPEED" value="8." unit="m/s"/>
    <define name="MAXIMUM_AIRSPEED" value="16." unit="m/s"/>
    <define name="CARROT" value="3." unit="s"/>
    <define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
<!--    <define name="XBEE_INIT" value="\"ATPL2\rATRN1\rATTT80\rATBD6\rATWR\r\""/> -->
    <define name="XBEE_INIT" value="\"ATPL2\rATRN1\rATTT80\r\""/>
<!--    <define name="NO_XBEE_API_INIT" value="TRUE"/> -->
    <define name="TRIGGER_DELAY" value="1."/>
    <define name="DEFAULT_CIRCLE_RADIUS" value="60."/>
  </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.15"/>
    <!-- outer loop saturation -->
    <define name="ALTITUDE_MAX_CLIMB" value="2."/>

    <!-- auto throttle inner loop -->
    <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.55"/>
    <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.30"/>
    <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.90"/>
    <define name="AUTO_THROTTLE_LOITER_TRIM" value="1500"/>
    <define name="AUTO_THROTTLE_DASH_TRIM" value="-2000"/>
    <define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.15" unit="%/(m/s)"/>
    <define name="AUTO_THROTTLE_PGAIN" value="0.05"/>
    <define name="AUTO_THROTTLE_IGAIN" value="0.1"/>
    <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.05"/>

    <!-- auto pitch inner loop -->
    <define name="AUTO_PITCH_PGAIN" value="0.065"/>
    <define name="AUTO_PITCH_IGAIN" value="0.15"/>
    <define name="AUTO_PITCH_MAX_PITCH" value="0.35"/>
    <define name="AUTO_PITCH_MIN_PITCH" value="-0.35"/>

    <define name="THROTTLE_SLEW" value="0.05"/>

  </section>

  <section name="HORIZONTAL CONTROL" prefix="H_CTL_">
    <define name="COURSE_PGAIN" value="1."/>
    <define name="ROLL_MAX_SETPOINT" value="0.6" 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="10000"/>
    <define name="AILERON_OF_THROTTLE" value="0.0"/>
    <define name="PITCH_PGAIN" value="12000."/>
    <define name="PITCH_DGAIN" value="1.5"/>
    <define name="ELEVATOR_OF_ROLL" value="1250"/>
  </section>

  <section name="NAV">
    <define name="NAV_GLIDE_PITCH_TRIM" value="0"/>
    <define name="NAV_GROUND_SPEED_PGAIN" value="0.015"/>
    <define name="NAV_FOLLOW_PGAIN" value="-0.05"/>
  </section>

  <section name="FORMATION" prefix="FORM_">
    <define name="CARROT" value="3." unit="s"/> <!-- carrot distance for followers -->
    <define name="POS_PGAIN" value="0.02"/> <!-- coef on position error -->
    <define name="SPEED_PGAIN" value="0.4"/> <!-- coef on speed error -->
    <define name="COURSE_PGAIN" value="0.8"/> <!-- coef on course error (override course pgain for followers) -->
    <define name="ALTITUDE_PGAIN" value="0.1"/> <!-- coef on altitude error -->
    <define name="PROX" value="60." unit="m"/> <!-- proximity distance -->
    <define name="MODE" value="0"/> <!-- mode 0 = global, 1 = local -->
  </section>

  <section name="TCAS" prefix="TCAS_">
    <define name="TAU_TA" value="10." unit="s"/> <!-- traffic advisory -->
    <define name="TAU_RA" value="6." unit="s"/> <!-- resolution advisory -->
    <define name="ALIM" value="15." unit="m"/> <!-- altitude limitation -->
    <define name="DT_MAX" value="2000" unit="ms"/> <!-- lost comm or timeout -->
  </section>

  <section name="POTENTIAL">
    <define name="FORCE_POS_GAIN" value="50"/>
    <define name="FORCE_SPEED_GAIN" value="1"/>
    <define name="FORCE_CLIMB_GAIN" value="8"/>
  </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="0.8"/><!-- 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="1" 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"/>
    <define name="HOME_RADIUS" value="100" unit="m"/>
  </section>

  <section name="SIMU">
    <define name="YAW_RESPONSE_FACTOR" value="1."/>
  </section>

 <makefile>
# external module
#ap.srcs += external.c

  </makefile>
</airframe>
