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

<airframe name="BOOZ2_G1">

  <modules main_freq="512">
    <!--load name="vision_cmucam.xml"/-->
    <load name="sonar_maxbotix_booz.xml"/>
    <load name="booz_extra_dl.xml"/>
    <load name="booz_gumstix_com.xml"/>
  </modules>

  <servos>
    <servo name="PITCH"  no="0" min="0" neutral="0" max="255"/>
    <servo name="ROLL"   no="1" min="0" neutral="0" max="255"/>
    <servo name="YAW"    no="2" min="0" neutral="0" max="255"/>
    <servo name="THRUST" no="3" min="0" neutral="0" max="255"/>
  </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="SUPERVISION" prefix="SUPERVISION_">
    <define name="TRIM_A" value="0"/>
    <define name="TRIM_E" value="6"/>
    <define name="TRIM_R" value="0"/>
  </section>

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

    <define name="GYRO_P_CHAN" value="1"/>
    <define name="GYRO_Q_CHAN" value="0"/>
    <define name="GYRO_R_CHAN" value="2"/>

    <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_CHAN" value="5"/>
    <define name="ACCEL_Y_CHAN" value="3"/>
    <define name="ACCEL_Z_CHAN" value="4"/>

    <define name="ACCEL_X_SENS" value="2.55975587" integer="16"/>
    <define name="ACCEL_Y_SENS" value="2.55643340" integer="16"/>
    <define name="ACCEL_Z_SENS" value="2.57178460" integer="16"/>

    <define name="ACCEL_X_NEUTRAL" value="33067"/>
    <define name="ACCEL_Y_NEUTRAL" value="32778"/>
    <define name="ACCEL_Z_NEUTRAL" value="32140"/>

    <define name="MAG_X_CHAN" value="0"/>
    <define name="MAG_Y_CHAN" value="1"/>
    <define name="MAG_Z_CHAN" value="2"/>

    <define name="MAG_X_NEUTRAL" value="-12"/>
    <define name="MAG_Y_NEUTRAL" value="-10"/>
    <define name="MAG_Z_NEUTRAL" value="-11"/>

    <define name="MAG_X_SENS" value="22.008352" integer="16"/>
    <define name="MAG_Y_SENS" value="21.79885" integer="16"/>
    <define name="MAG_Z_SENS" value="14.675745" 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="BOOZ_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="BOOZ_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="2000"/>
    <define name="PHI_DGAIN"  value="400"/>
    <define name="PHI_IGAIN"  value="200"/>

    <define name="THETA_PGAIN"  value="2000"/>
    <define name="THETA_DGAIN"  value="400"/>
    <define name="THETA_IGAIN"  value="200"/>

    <define name="PSI_PGAIN"  value="1000"/>
    <define name="PSI_DGAIN"  value="350"/>
    <define name="PSI_IGAIN"  value="10"/>

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

  </section>

  <section name="INS" prefix="BOOZ_INS_">
    <define name="BARO_SENS" value="15." integer="16"/>
    <define name="SONAR_SENS" value="2.146" integer="16"/>
  </section>

  <section name="HORIZONTAL_FILTER" prefix="B2_HFF_">
    <define name="ACCEL_NOISE"  value="10."/>
    <define name="R_POS"        value="0.05"/>
    <define name="R_POS_MIN"    value="0."/>
    <define name="R_SPEED"      value="1."/>
    <define name="R_SPEED_MIN"  value="0."/>
  </section>

  <section name="GUIDANCE_V" prefix="BOOZ2_GUIDANCE_V_">
   <define name="MIN_ERR_Z"    value="POS_BFP_OF_REAL(-10.)"/>
   <define name="MAX_ERR_Z"    value="POS_BFP_OF_REAL( 10.)"/>
   <define name="MIN_ERR_ZD"   value="SPEED_BFP_OF_REAL(-10.)"/>
   <define name="MAX_ERR_ZD"   value="SPEED_BFP_OF_REAL( 10.)"/>
   <define name="MAX_SUM_ERR"  value="2000000"/>
   <define name="REF_MIN_ZDD"  value="-1.5*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) -->
   <define name="RC_CLIMB_COEF" value ="163"/>
   <!-- SPEED_BFP_OF_REAL(1.5) * 20% -->
   <define name="RC_CLIMB_DEAD_BAND" value ="160000"/>
   <!-- <define name="INV_M" value="0.118"/> -->
  </section>


 <section name="GUIDANCE_H" prefix="BOOZ2_GUIDANCE_H_">
   <define name="PGAIN" value="50"/>
   <define name="DGAIN" value="60"/>
   <define name="IGAIN" value="0"/>
   <define name="NGAIN" value="0"/>
   <!-- feedforward -->
   <define name="AGAIN" value="50"/>
 </section>

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

 <section name="AUTOPILOT">
   <define name="BOOZ2_MODE_MANUAL" value="BOOZ2_AP_MODE_ATTITUDE_DIRECT"/>
   <define name="BOOZ2_MODE_AUTO1"  value="BOOZ2_AP_MODE_ATTITUDE_Z_HOLD"/>
   <define name="BOOZ2_MODE_AUTO2"  value="BOOZ2_AP_MODE_NAV"/>
 </section>

 <section name="FMS">

 </section>

 <section name="MISC">
   <define name="BOOZ_ANALOG_BARO_THRESHOLD" value="800"/>
   <define name="BOOZ2_FACE_REINJ_1"  value="1024"/>
   <define name="DEFAULT_CIRCLE_RADIUS" value="10."/>
 </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="INITIAL_CONDITITONS" value="&quot;reset_enac&quot;"/-->
   <define name="SENSORS_PARAMS" value="&quot;nps_sensors_params_booz2_a1.h&quot;"/>
 </section>


  <makefile>
ARCH=lpc21
ARCHI=arm7
BOARD_CFG = \"boards/booz2_v1_0.h\"
FLASH_MODE=IAP

# prevents motors from ever starting
#ap.CFLAGS += -DKILL_MOTORS

include $(PAPARAZZI_SRC)/conf/firmwares/booz2_common.makefile
include $(CFG_BOOZ)/booz2_autopilot.makefile
include $(CFG_BOOZ)/booz2_test_progs.makefile
ap.CFLAGS += -DBOOZ_FAILSAFE_GROUND_DETECT

sim.CFLAGS += -DBSM_PARAMS=\"booz_sensors_model_params_booz2_a2.h\"
sim.CFLAGS += -DNPS_NO_SUPERVISION
include $(CFG_BOOZ)/booz2_simulator_nps.makefile

ap.CFLAGS += -DMODEM_BAUD=B57600
include $(CFG_BOOZ)/subsystems/booz2_actuators_asctec.makefile
include $(CFG_BOOZ)/subsystems/booz2_radio_control_ppm.makefile
include $(CFG_BOOZ)/subsystems/booz2_imu_b2v1_1.makefile
#include $(CFG_BOOZ)/subsystems/booz2_gps.makefile
include $(CFG_BOOZ)/subsystems/booz2_analog_bat_baro.makefile
include $(CFG_BOOZ)/subsystems/booz2_fms_datalink.makefile

include $(CFG_BOOZ)/subsystems/booz2_ahrs_cmpl.makefile

#include $(CFG_BOOZ)/subsystems/booz2_ins_hff.makefile
#ap.CFLAGS += -DR_POS=0.1

ap.CFLAGS += -DUSE_ADAPT_HOVER -DUSE_INS_NAV_INIT -DACTUATORS_START_DELAY=3
sim.CFLAGS += -DUSE_ADAPT_HOVER -DUSE_INS_NAV_INIT -DACTUATORS_START_DELAY=3

ap.CFLAGS += -DUSE_MODULES

  </makefile>

</airframe>
