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

<!-- Fire Storm
     Umarim
     Radiotronix modem
     -->

<airframe name="FireStorm">

  <modules>
    <load name="poles.xml"/>
  </modules>

  <firmware name="fixedwing">
    <define name="AGR_CLIMB"/>
    <define name="LOITER_TRIM"/>
    <!--define name="PITCH_TRIM"/-->

    <target name="sim" board="pc"/>
    <target name="ap" board="umarim_1.0">
      <configure name="FLASH_MODE" value="IAP"/>
      <define name="USE_I2C0"/>
      <define name="USE_I2C1"/>
    </target>

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

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

    <!-- Actuators are automatically chosen according to board-->
    <subsystem name="imu"     type="umarim"/>
    <subsystem name="ahrs"    type="float_dcm"/>
    <subsystem name="ins"     type="alt_float"/>
    <subsystem name="control" type="adaptive"/>
    <subsystem name="navigation"/>
    <!-- Sensors -->
    <subsystem name="gps" type="ublox"/>

    <subsystem name="current_sensor">
      <configure name="ADC_CURRENT_SENSOR" value="ADC_0"/>
    </subsystem>
  </firmware>

  <!-- commands section -->
  <servos>
    <servo name="MOTOR" no="2" min="1250" neutral="1250" max="1800"/>
    <servo name="AILEVON_LEFT" no="0" min="1850" neutral="1370" max="1000"/>
    <servo name="AILEVON_RIGHT" no="1" min="1000" neutral="1515" max="1870"/>
  </servos>

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

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

  <section name="MIXER">
    <define name="AILEVON_AILERON_RATE" value="0.75"/>
    <define name="AILEVON_ELEVATOR_RATE" value="0.75"/>
    <define name="AILERON_DIFF" value="0.5"/>
  </section>

  <command_laws>
    <let var="aileron" value="@ROLL  * AILEVON_AILERON_RATE"/>
    <let var="elevator" value="@PITCH * AILEVON_ELEVATOR_RATE"/>
    <set servo="MOTOR" value="@THROTTLE"/>
    <set servo="AILEVON_LEFT" value="$elevator + ($aileron > 0 ? 1 : AILERON_DIFF) * $aileron"/>
    <set servo="AILEVON_RIGHT" value="$elevator - ($aileron > 0 ? AILERON_DIFF : 1) * $aileron"/>
  </command_laws>

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

  <section name="IMU" prefix="IMU_">
    <define name="GYRO_P_SIGN" value="1"/>
    <define name="GYRO_Q_SIGN" value="-1"/>
    <define name="GYRO_R_SIGN" value="-1"/>

    <!-- Calibration Neutral -->
    <define name="GYRO_P_NEUTRAL" value="-53"/>
    <define name="GYRO_Q_NEUTRAL" value="33"/>
    <define name="GYRO_R_NEUTRAL" value="-16"/>

    <!-- SENS ITG3200  1/14.375 (deg/s)/LSB, rate frac 12bit => 1/14.375 * pi / 180 * 2^12 -->
    <define name="GYRO_P_SENS" value="4.97312" integer="16"/>
    <define name="GYRO_Q_SENS" value="4.97312" integer="16"/>
    <define name="GYRO_R_SENS" value="4.97312" integer="16"/>

    <define name="ACCEL_X_SIGN" value="1"/>
    <define name="ACCEL_Y_SIGN" value="-1"/>
    <define name="ACCEL_Z_SIGN" value="-1"/>

    <define name="ACCEL_X_NEUTRAL" value="-2"/>
    <define name="ACCEL_Y_NEUTRAL" value="1"/>
    <define name="ACCEL_Z_NEUTRAL" value="-43"/>

    <define name="ACCEL_X_SENS" value="38.9923420841" integer="16"/>
    <define name="ACCEL_Y_SENS" value="39.2011913001" integer="16"/>
    <define name="ACCEL_Z_SENS" value="39.4148057033" integer="16"/>

    <!-- Just to compile -->
    <define name="MAG_X_NEUTRAL" value="0"/>
    <define name="MAG_Y_NEUTRAL" value="0"/>
    <define name="MAG_Z_NEUTRAL" value="0"/>

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

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

  <section name="BAT">
    <define name="MILLIAMP_AT_FULL_THROTTLE" value="2000"/>
    <define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
    <define name="MilliAmpereOfAdc(_adc)" value="(_adc-162)*17.4"/>
  </section>

  <section name="MISC">
    <define name="MINIMUM_AIRSPEED" value="13." unit="m/s"/>
    <define name="NOMINAL_AIRSPEED" value="16." unit="m/s"/>
    <define name="MAXIMUM_AIRSPEED" value="24." unit="m/s"/>
    <define name="CARROT" value="5." unit="s"/>
    <define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
    <define name="DEFAULT_CIRCLE_RADIUS" value="80."/>
    <define name="UNLOCKED_HOME_MODE" value="TRUE"/>
    <define name="TELEMETRY_MODE_AP" value="1"/>
  </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.04"/>
    <!-- outer loop saturation -->
    <define name="ALTITUDE_MAX_CLIMB" value="2."/>

    <!-- auto throttle inner loop -->
    <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.5"/>
    <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.25"/>
    <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.80"/>
    <define name="AUTO_THROTTLE_LOITER_TRIM" value="1500"/>
    <define name="AUTO_THROTTLE_DASH_TRIM" value="-2500"/>
    <define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.05" unit="%/(m/s)"/>
    <define name="AUTO_THROTTLE_PGAIN" value="0.007"/>
    <define name="AUTO_THROTTLE_IGAIN" value="0.067"/>
    <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.11"/>

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

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

  </section>

  <section name="HORIZONTAL CONTROL" prefix="H_CTL_">
    <define name="COURSE_PGAIN" value="0.9"/>

    <define name="ROLL_MAX_SETPOINT" value="0.805000007153" unit="rad"/>
    <define name="PITCH_MAX_SETPOINT" value="0.5" unit="rad"/>
    <define name="PITCH_MIN_SETPOINT" value="-0.5" unit="rad"/>

    <define name="PITCH_PGAIN" value="14255.3193359"/>
    <define name="PITCH_DGAIN" value="1.5"/>

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

    <define name="ROLL_ATTITUDE_GAIN" value="2600"/>
    <define name="ROLL_RATE_GAIN" value="850"/>

    <define name="ROLL_KFF" value="-500"/>
    <define name="ROLL_IGAIN" value="00"/>
    <define name="PITCH_IGAIN" value="500"/>
  </section>

  <section name="NAV">
    <define name="NAV_GLIDE_PITCH_TRIM" value="0"/>
  </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.75"/><!-- Gaz for Aggressive Climb -->
    <define name="CLIMB_PITCH" value="0.20"/><!-- Pitch for Aggressive Climb -->
    <define name="DESCENT_THROTTLE" value="0.1"/><!-- Gaz for Aggressive Decent -->
    <define name="DESCENT_PITCH" value="-0.15"/><!-- 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="GYRO_GAINS">
    <define name="GYRO_MAX_RATE" value="200."/>
    <define name="ROLLRATESUM_NB_SAMPLES" value="64"/>
    <define name="ALT_ROLL__PGAIN" value="1.0"/>
    <define name="ROLL_RATE_PGAIN" value="1000.0"/>
    <define name="ROLL_RATE_IGAIN" value="0.0"/>
    <define name="ROLL_RATE_DGAIN" value="0.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>

</airframe>
