<airframe name="BOOZ2_G1">

  <modules main_freq="512">
    <load name="servo_switch.xml"/>
    <load name="rotorcraft_cam.xml"/>
    <load name="sonar_adc.xml">
      <configure name="ADC_SONAR" value="ADC_0"/>
      <define name="USE_SONAR"/>
      <!--define name="SENSOR_SYNC_SEND_SONAR"/-->
    </load>
    <!--load name="baro_mpl3115.xml">
      <define name="MPL3115_I2C_DEV" value="i2c1"/>
      <define name="USE_I2C1"/>
      <define name="SENSOR_SYNC_SEND"/>
    </load-->
    <!--load name="mavlink_decoder.xml">
      <configure name="MAVLINK_PORT" value="UART0"/>
      <configure name="MAVLINK_BAUD" value="B115200"/>
    </load>
    <load name="px4flow.xml"/-->
    <!--load name="adc_generic.xml">
      <configure name="ADC_CHANNEL_GENERIC1" value="ADC_0"/>
    </load-->
    <!--load name="sys_mon.xml"/-->
  </modules>

  <firmware name="rotorcraft">
    <define name="DEBUG_VFF_EXTENDED"/>
    <define name="USE_INS_NAV_INIT"/>
    <!--define name="GUIDANCE_H_USE_REF"/-->

    <target name="ap" board="booz_1.0">
      <define name="FAILSAFE_GROUND_DETECT"/>
      <define name="USE_GPS_ACC4R"/>
      <define name="ACTUATORS_START_DELAY" value="3"/>
    </target>
    <target name="nps" board="pc">
      <subsystem name="fdm"         type="jsbsim"/>
    </target>

    <subsystem name="radio_control" type="ppm"/>
    <subsystem name="telemetry"     type="transparent"/>
    <subsystem name="actuators"     type="asctec"/>
    <subsystem name="actuators"     type="pwm">
      <define name="USE_PWM0"/>
      <define name="USE_PWM1"/>
    </subsystem>
    <subsystem name="imu"           type="b2_v1.1"/>
    <subsystem name="gps"           type="ublox">
      <configure name="GPS_BAUD"    value="B57600"/>
    </subsystem>
    <subsystem name="stabilization" type="int_euler"/>
    <subsystem name="ahrs"          type="int_cmpl_euler"/>
    <subsystem name="ins"           type="extended"/>
  </firmware>

  <servos driver="Asctec">
    <servo name="PITCH"  no="0" min="-100" neutral="0" max="100"/>
    <servo name="ROLL"   no="1" min="-100" neutral="0" max="100"/>
    <servo name="YAW"    no="2" min="-100" neutral="0" max="100"/>
    <servo name="THRUST" no="3" min="0"    neutral="0" max="200"/>
  </servos>

  <servos driver="Pwm">
    <servo name="SWITCH" no="0" min="1060" neutral="1500" max="2120"/>
    <servo name="CAM" no="1" min="1000" neutral="1500" max="2300"/>
  </servos>

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

  <section name="TRIM">
    <define name="TRIM_ROLL" value="0"/>
    <define name="TRIM_PITCH" value="6"/>
    <define name="TRIM_YAW" value="0"/>
  </section>

  <command_laws>
    <set servo="PITCH" value="@PITCH - TRIM_PITCH"/>
    <set servo="ROLL" value="@ROLL - TRIM_ROLL"/>
    <set servo="YAW" value="@YAW - TRIM_YAW"/>
    <set servo="THRUST" value="@THRUST"/>
  </command_laws>

  <section name="IMU" prefix="IMU_">

    <define name="GYRO_P_NEUTRAL" value="32238"/>
    <define name="GYRO_Q_NEUTRAL" value="32391"/>
    <define name="GYRO_R_NEUTRAL" value="32853"/>

    <define name="GYRO_P_SENS" value="1.00" integer="16"/>
    <define name="GYRO_Q_SENS" value="1.00" integer="16"/>
    <define name="GYRO_R_SENS" value="1.00" integer="16"/>

    <define name="ACCEL_X_NEUTRAL" value="32508"/>
    <define name="ACCEL_Y_NEUTRAL" value="32565"/>
    <define name="ACCEL_Z_NEUTRAL" value="32147"/>

    <define name="ACCEL_X_SENS" value="2.56787679957" integer="16"/>
    <define name="ACCEL_Y_SENS" value="2.55480391706" integer="16"/>
    <define name="ACCEL_Z_SENS" value="2.57076132924" integer="16"/>

    <define name="MAG_X_NEUTRAL" value="19"/>
    <define name="MAG_Y_NEUTRAL" value="-91"/>
    <define name="MAG_Z_NEUTRAL" value="-40"/>

    <define name="MAG_X_SENS" value="4.93239693731" integer="16"/>
    <define name="MAG_Y_SENS" value="4.91905188125" integer="16"/>
    <define name="MAG_Z_SENS" value="3.3560174578" integer="16"/>

    <define name="BODY_TO_IMU_PHI"   value="1.3" unit="deg"/>
    <define name="BODY_TO_IMU_THETA" value="-2.6" unit="deg"/>
    <define name="BODY_TO_IMU_PSI"   value="0." unit="deg"/>

  </section>

  <section name="STABILIZATION_RATE" prefix="STABILIZATION_RATE_">

    <define name="SP_MAX_P" value="10000"/>
    <define name="SP_MAX_Q" value="10000"/>
    <define name="SP_MAX_R" value="10000"/>

    <define name="GAIN_P" value="400"/>
    <define name="GAIN_Q" value="400"/>
    <define name="GAIN_R" value="350"/>

  </section>

  <section name="STABILIZATION_ATTITUDE" prefix="STABILIZATION_ATTITUDE_">

    <!-- setpoints -->
    <define name="SP_MAX_PHI"     value="45." unit="deg"/>
    <define name="SP_MAX_THETA"   value="45." unit="deg"/>
    <define name="SP_MAX_R"       value="90." unit="deg/s"/>
    <define name="DEADBAND_R"     value="250"/>

     <!-- reference -->
    <define name="REF_OMEGA_P"  value="800" unit="deg/s"/>
    <define name="REF_ZETA_P"   value="0.85"/>
    <define name="REF_MAX_P"    value="300." unit="deg/s"/>
    <define name="REF_MAX_PDOT" value="RadOfDeg(7000.)"/>

    <define name="REF_OMEGA_Q"  value="800" unit="deg/s"/>
    <define name="REF_ZETA_Q"   value="0.85"/>
    <define name="REF_MAX_Q"    value="300." unit="deg/s"/>
    <define name="REF_MAX_QDOT" value="RadOfDeg(7000.)"/>

    <define name="REF_OMEGA_R"  value="500" unit="deg/s"/>
    <define name="REF_ZETA_R"   value="0.85"/>
    <define name="REF_MAX_R"    value="90." unit="deg/s"/>
    <define name="REF_MAX_RDOT" value="RadOfDeg(900.)"/>

   <!-- feedback -->
    <define name="PHI_PGAIN"  value="6000"/>
    <define name="PHI_DGAIN"  value="800"/>
    <define name="PHI_IGAIN"  value="500"/>

    <define name="THETA_PGAIN"  value="6000"/>
    <define name="THETA_DGAIN"  value="800"/>
    <define name="THETA_IGAIN"  value="500"/>

    <define name="PSI_PGAIN"  value="3000"/>
    <define name="PSI_DGAIN"  value="600"/>
    <define name="PSI_IGAIN"  value="100"/>

    <!-- feedforward -->
    <define name="PHI_DDGAIN"   value=" 300"/>
    <define name="THETA_DDGAIN" value=" 300"/>
    <define name="PSI_DDGAIN"   value=" 300"/>

    <define name="PHI_AGAIN"   value="0"/>
    <define name="THETA_AGAIN" value="0"/>
    <define name="PSI_AGAIN"   value="0"/>

  </section>

  <section name="INS" prefix="INS_">
    <define name="SONAR_MAX_RANGE" value="5.0"/>
    <define name="SONAR_MIN_RANGE" value="0.25"/>
  </section>

  <section name="SONAR">
    <!--define name="SONAR_SCALE" value="0.00650498" integer="16"/--> <!-- XL-MaxSonar-EZ4 5V supply -->
    <define name="SONAR_SCALE" value="0.016775" integer="16"/> <!-- XL-MaxSonar-EZ4 5V supply scaled to 3.3V -->
  </section>

  <section name="GUIDANCE_V" prefix="GUIDANCE_V_">
    <define name="REF_MIN_ZDD"  value="-0.8*9.81"/>
    <define name="REF_MAX_ZDD"  value=" 0.5*9.81"/>
    <define name="REF_MIN_ZD"   value="-1.5"/>
    <define name="REF_MAX_ZD"   value=" 1.5"/>
    <define name="HOVER_KP"     value="150"/>
    <define name="HOVER_KD"     value="80"/>
    <define name="HOVER_KI"     value="0"/>
    <!-- 1.5m/s for full stick : SPEED_BFP_OF_REAL(1.5) / (MAX_PPRZ/2) -->
    <!-- SPEED_BFP_OF_REAL(1.5) * 20% -->
  </section>


  <section name="GUIDANCE_H" prefix="GUIDANCE_H_">
    <define name="USE_REF" value="FALSE"/>
    <define name="MAX_BANK" value="30" unit="deg"/>
    <define name="PGAIN" value="40"/>
    <define name="DGAIN" value="70"/>
    <define name="IGAIN" value="15"/>
    <define name="NGAIN" value="0"/>
    <!-- feedforward -->
    <define name="AGAIN" value="0"/>
  </section>

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

  <section name="AUTOPILOT">
    <define name="MODE_MANUAL" value="AP_MODE_ATTITUDE_DIRECT"/>
    <define name="MODE_AUTO1"  value="AP_MODE_ATTITUDE_Z_HOLD"/>
    <define name="MODE_AUTO2"  value="AP_MODE_NAV"/>
  </section>

  <section name="FMS">
    <define name="BOOZ_FMS_TIMEOUT" value="0"/>
  </section>

  <section name="CAM" prefix="ROTORCRAFT_CAM_">
    <define name="SWITCH_GPIO" value="CAM_SWITCH_GPIO"/>
    <define name="TILT_SERVO" value="CAM"/>
    <define name="TILT_ANGLE_MAX" value="-90." unit="deg"/>
    <define name="TILT_ANGLE_MIN" value=" 10." unit="deg"/>
  </section>

  <section name="SERVO_SWITCH">
    <define name="SERVO_SWITCH_ON_VALUE" value="SERVO_SWITCH_MIN"/>
    <define name="SERVO_SWITCH_OFF_VALUE" value="SERVO_SWITCH_MAX"/>
    <define name="DropOpen()" value="ServoSwitchOn()"/>
    <define name="DropClose()" value="ServoSwitchOff()"/>
  </section>

  <section name="MISC">
    <define name="BOOZ_ANALOG_BARO_THRESHOLD" value="800"/>
    <define name="FACE_REINJ_1"  value="1024"/>
    <define name="DEFAULT_CIRCLE_RADIUS" value="10."/>
    <!--define name="IMU_MAG_OFFSET" value="RadOfDeg(-5.8)"/-->
  </section>

  <section name="GCS">
    <define name="ALT_SHIFT_PLUS_PLUS" value="5"/>
    <define name="ALT_SHIFT_PLUS" value="1"/>
    <define name="ALT_SHIFT_MINUS" value="-1"/>
  </section>

  <section name="SIMULATOR" prefix="NPS_">
    <define name="ACTUATOR_NAMES"  value="{&quot;front_motor&quot;, &quot;back_motor&quot;, &quot;right_motor&quot;, &quot;left_motor&quot;}"/>
    <define name="JSBSIM_MODEL" value="&quot;simple_quad&quot;"/>
    <!--define name="JSBSIM_INIT" value="&quot;reset_enac&quot;"/-->
    <define name="SENSORS_PARAMS" value="&quot;nps_sensors_params_booz2_a1.h&quot;"/>
  </section>

</airframe>
