<airframe name="BOOZ2_A4">

  <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"/>
    <servo name="AILEVON_R" no="4" min="1000" neutral="1750" max="2000"/>
    <servo name="AILEVON_L" no="5" min="1000" neutral="1680" max="2000"/>
  </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="IMU" prefix="IMU_">

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

    <define name="GYRO_Q_NEUTRAL" value="31993"/>
    <define name="GYRO_R_NEUTRAL" value="31923"/>
    <define name="GYRO_P_NEUTRAL" value="32727"/>

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

    <define name="ACCEL_Y_CHAN" value="5"/>
    <define name="ACCEL_Z_CHAN" value="3"/>
    <define name="ACCEL_X_CHAN" value="4"/>

    <define name="ACCEL_Y_SENS" value="-2.58291748" integer="16"/>
    <define name="ACCEL_Z_SENS" value="-2.53729378" integer="16"/>
    <define name="ACCEL_X_SENS" value="-2.57289306" integer="16"/>

    <define name="ACCEL_Y_NEUTRAL" value="32803"/>
    <define name="ACCEL_Z_NEUTRAL" value="32466"/>
    <define name="ACCEL_X_NEUTRAL" value="32575"/>

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

    <define name="MAG_Z_NEUTRAL" value="48"/>
    <define name="MAG_X_NEUTRAL" value="11"/>
    <define name="MAG_Y_NEUTRAL" value="-45"/>

    <define name="MAG_Z_SENS" value="-4.65606311" integer="16"/>
    <define name="MAG_X_SENS" value="-3.03386034" integer="16"/>
    <define name="MAG_Y_SENS" value=" 4.99085017" integer="16"/>

    <define name="BODY_TO_IMU_PHI"   value="0." unit="deg"/>
    <define name="BODY_TO_IMU_THETA" value="0." 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_">

    <define name="SP_MAX_PHI"     value="3000"/>
    <define name="SP_MAX_THETA"   value="6000"/>
    <define name="SP_MAX_R"       value="4000"/>
    <define name="DEADBAND_R"     value="250"/>

    <define name="PHI_THETA_PGAIN"  value="-400"/>
    <define name="PHI_THETA_DGAIN"  value="-300"/>
    <define name="PHI_THETA_DDGAIN" value=" 300"/>
    <define name="PHI_THETA_IGAIN"  value="-50"/>

    <define name="PSI_PGAIN"  value="380"/>
    <define name="PSI_DGAIN"  value="320"/>
    <define name="PSI_DDGAIN" value=" 300"/>
    <define name="PSI_IGAIN"  value="50"/>

  </section>

  <section name="SUPERVISION" prefix="SUPERVISION_">
    <define name="TRIM_A"  value="0"/>
    <define name="TRIM_E"  value="0"/>
    <define name="TRIM_R"  value="0"/>
    <define name="HACK_45" value="1"/>
  </section>

  <section name="INS" prefix="INS_">
    <define name="BARO_SENS" value="14.9" integer="16"/>
  </section>


  <section name="GUIDANCE_V"   prefix="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="HOVER_KP"     value="500"/>
   <define name="HOVER_KD"     value="250"/>
   <!-- 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"/>
  </section>

 <section name="GUIDANCE_H" prefix="GUIDANCE_H_">
   <define name="PGAIN" value="100"/>
   <define name="DGAIN" value="100"/>
   <define name="IGAIN" value="0"/>
 </section>

 <section name="BAT">
   <define name="MILLIAMP_PER_PERCENT" value="0.86"/>
   <define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
   <define name="BATTERY_SENS"   value="0.25" integer="16"/>
<!--   <define name="BATTERY_SENS"   value="1" integer="16"/>-->
 </section>

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


 <section name="MISC">
   <define name="FACE_REINJ_1"  value="1024"/>
 </section>

  <makefile>
ARCH=lpc21
BOARD_CFG = \"boards/booz2_v1_0.h\"

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

include $(PAPARAZZI_SRC)/conf/firmwares/booz2_common.makefile
include $(PAPARAZZI_SRC)/conf/firmwares/booz2_autopilot.makefile
include $(PAPARAZZI_SRC)/conf/firmwares/booz2_test_progs.makefile

sim.CFLAGS += -DBSM_PARAMS=\"booz_sensors_model_params_booz2_a2.h\"
include $(PAPARAZZI_SRC)/conf/firmwares/booz2_simulator.makefile

ap.CFLAGS += -DMODEM_BAUD=B57600
include $(PAPARAZZI_SRC)/conf/firmwares/radio_control_spektrum.makefile
include $(PAPARAZZI_SRC)/conf/firmwares/booz2_actuators_asctec.makefile
include $(PAPARAZZI_SRC)/conf/firmwares/booz2_imu_b2v1_1.makefile

include $(CFG_BOOZ)/subsystems/booz2_ahrs_cmpl.makefile

ap.CFLAGS += -DUSE_BOOZ2_CONTROL_SURFACES -DUSE_BOOZ2_SERVOS_DIRECT
ap.CFLAGS += -DUSE_BOOZ2_SERVOS_DIRECT_0 -DUSE_BOOZ2_SERVOS_DIRECT_1
ap.srcs += $(SRC_BOOZ_ARCH)/booz2_servos_direct_hw.c

  </makefile>

</airframe>
