<airframe name="UofA Group 1000 Fixed Pitch Airframe">

  <servos>
    <servo name="FRONT" no="0" min="0" neutral="0" max="255"/>
    <servo name="BACK" no="1" min="0" neutral="0" max="255"/>
    <servo name="RIGHT" no="2" min="0" neutral="0" max="255"/>
    <servo name="LEFT" 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="ACTUATORS_MKK" prefix="ACTUATORS_MKK_">
    <define name="NB" value="4"/>
    <define name="ADDR" value="{ 0x52, 0x54, 0x56, 0x58 }"/>
  </section>

  <section name="SUPERVISION" prefix="SUPERVISION_">
    <define name="MIN_MOTOR" value="2"/>
    <define name="MAX_MOTOR" value="210"/>
    <define name="TRIM_A" value="0"/>
    <define name="TRIM_E" value="0"/>
    <define name="TRIM_R" value="0"/>
    <define name="NB_MOTOR" value="4"/>
    <define name="SCALE" value="256"/>
    <define name="ROLL_COEF" value="{    0,    0, -256,  256}"/>
    <define name="PITCH_COEF" value="{  256, -256,    0,    0}"/>
    <define name="YAW_COEF" value="{ 256, 256,  -256,  -256}"/>
    <define name="THRUST_COEF" value="{ 256,  256,  256,  256}"/>
  </section>

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

<!-- beginning of CRISTA IMU sign defines -->

    <define name="GYRO_P_SIGN" value="-1"/>
    <define name="GYRO_Q_SIGN" value="1"/>
    <define name="GYRO_R_SIGN" value="1"/>

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

    <define name="MAG_X_SIGN" value="-1"/>
    <define name="MAG_Y_SIGN" value="1"/>
    <define name="MAG_Z_SIGN" value="-1"/>

<!-- end of crista imu sign defines -->

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

<!--    <define name="GYRO_P_NEUTRAL" value="32734"/>

    <define name="GYRO_Q_NEUTRAL" value="32272"/>
    <define name="GYRO_R_NEUTRAL" value="32420"/>  -->

<define name="GYRO_P_NEUTRAL" value="30900"/>

    <define name="GYRO_Q_NEUTRAL" value="32400"/>
    <define name="GYRO_R_NEUTRAL" value="31800"/>

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

    <define name="ACCEL_X_CHAN" value="2"/>
    <define name="ACCEL_Y_CHAN" value="5"/>
    <define name="ACCEL_Z_CHAN" value="6"/>

    <define name="ACCEL_X_SENS" value=" 6.29676358" integer="16"/>
    <define name="ACCEL_Y_SENS" value=" 6.07991732" integer="16"/>
    <define name="ACCEL_Z_SENS" value=" 6.62632272" integer="16"/>

    <define name="ACCEL_X_NEUTRAL" value="40385"/>
    <define name="ACCEL_Y_NEUTRAL" value="39223"/>
    <define name="ACCEL_Z_NEUTRAL" value="38860"/>
    <!-- test neutral <define name="ACCEL_Z_NEUTRAL" value="38900"/> -->


    <define name="MAG_X_CHAN" value="4"/> <!-- previously 0-->
    <define name="MAG_Y_CHAN" value="0"/> <!-- previously 4-->
    <define name="MAG_Z_CHAN" value="2"/>



<!--
   <define name="MAG_X_NEUTRAL" value="2339"/>
    <define name="MAG_Y_NEUTRAL" value="2106"/>
    <define name="MAG_Z_NEUTRAL" value="1902"/>

    <define name="MAG_X_SENS" value=" 4.4039655" integer="16"/>
    <define name="MAG_Y_SENS" value=" 4.2959321" integer="16"/>
    <define name="MAG_Z_SENS" value=" 4.0988408" integer="16"/> -->
<!--
second attempt
    <define name="MAG_X_NEUTRAL" value="2169"/>
    <define name="MAG_Y_NEUTRAL" value="2263"/>
    <define name="MAG_Z_NEUTRAL" value="1673"/>
-->



<!-- Second Attempt
    <define name="MAG_X_SENS" value="3.77021943193" integer="16"/>
    <define name="MAG_Y_SENS" value="3.4884990526" integer="16"/>
    <define name="MAG_Z_SENS" value="3.52031672283" integer="16"/>
-->

   <define name="MAG_X_NEUTRAL" value="2110"/>
    <define name="MAG_Y_NEUTRAL" value="2168"/>
    <define name="MAG_Z_NEUTRAL" value="1612"/>

    <define name="MAG_45_HACK" value="1"/>

    <define name="MAG_X_SENS" value="2.828427125" integer="16"/>
    <define name="MAG_Y_SENS" value="2.973101172" integer="16"/>
    <define name="MAG_Z_SENS" value="3.88650043" integer="16"/>



<!--
    <define name="MAG_X_SENS" value="2.665947727" integer="16"/>
    <define name="MAG_Y_SENS" value="2.466741336" integer="16"/>
    <define name="MAG_Z_SENS" value="3.4884990526" integer="16"/>

    <define name="MAG_45_HACK" value="1"/>
-->
    <define name="BODY_TO_IMU_PHI"   value="2.9 " unit="deg"/> <!-- previously 1.5-->
    <define name="BODY_TO_IMU_THETA" value="-3.7 " unit="deg"/> <!-- previously -1.5-->
    <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"/>

<!-- new section from the NOVA -->

        <define name="DEADBAND_P" value="0" />
        <define name="DEADBAND_Q" value="0" />
        <define name="DEADBAND_R" value="200" />
        <define name="REF_TAU" value="4" />

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

        <define name="IGAIN_P" value="75" />
        <define name="IGAIN_Q" value="75" />
        <define name="IGAIN_R" value="50" />

        <!-- feedforward -->
        <define name="DDGAIN_P" value="300" />
        <define name="DDGAIN_Q" value="300" />
        <define name="DDGAIN_R" value="300" />

    <!-- original values
    <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="500" unit="deg/s"/> <!--originally 800-->
    <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="500" unit="deg/s"/> <!-- originally 800-->
    <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="700" unit="deg/s"/> <!-- originally 500-->
    <define name="REF_ZETA_R"   value="0.85"/>
    <define name="REF_MAX_R"    value="180." unit="deg/s"/>
    <define name="REF_MAX_RDOT" value="RadOfDeg(1800.)"/>

   <!-- feedback -->
    <define name="PHI_PGAIN"  value="400"/>
    <define name="PHI_DGAIN"  value="300"/>
    <define name="PHI_IGAIN"  value="100"/>

    <define name="THETA_PGAIN"  value="400"/>
    <define name="THETA_DGAIN"  value="300"/>
    <define name="THETA_IGAIN"  value="100"/>

    <define name="PSI_PGAIN"  value="380"/>
    <define name="PSI_DGAIN"  value="320"/>
    <define name="PSI_IGAIN"  value="75"/>

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

  </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="MAX_SUM_ERR" value="2000000"/>
   <define name="HOVER_KP" value="500"/>
   <define name="HOVER_KD" value="200"/>
   <define name="HOVER_KI" value="100"/>
   <!-- 1.5m/s for full stick : BOOZ_SPEED_I_OF_F(1.5) / (MAX_PPRZ/2) -->
   <define name="RC_CLIMB_COEF" value="163"/>
   <!-- BOOZ_SPEED_I_OF_F(1.5) * 20% -->
   <define name="RC_CLIMB_DEAD_BAND" value="160000"/>
<!--   <define name="INV_M" value ="0.2"/> -->
  </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="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_HOVER_Z_HOLD"/>
 </section>

 <section name="FMS">

 </section>

 <section name="MISC">
   <define name="FACE_REINJ_1" value="1024"/>
   <define name="NOMINAL_AIRSPEED" 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="INITIAL_CONDITITONS" value="&quot;reset00&quot;"/>
   <define name="SENSORS_PARAMS" value="&quot;nps_sensors_params_booz2_a1.h&quot;"/>
 </section>




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

# prevents motors from ever starting
ap.CFLAGS += -DKILL_MOTORS
ap.CFLAGS += -DMODEM_BAUD=B57600
#ap.CFLAGS += -DGPS_USE_LATLONG now included in NOVA section, include if NOVA section removed

#throttle killswitch
ap.CFLAGS += -DRADIO_KILL_SWITCH=RADIO_CONTROL_SWITCH1

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

include $(CFG_BOOZ)/subsystems/booz2_radio_control_ppm.makefile
include $(CFG_BOOZ)/subsystems/booz2_actuators_mkk.makefile
include $(CFG_BOOZ)/subsystems/booz2_imu_crista.makefile
include $(CFG_BOOZ)/subsystems/booz_gps_ublox.makefile

include $(CFG_BOOZ)/subsystems/booz2_ahrs_cmpl.makefile

#include $(CFG_BOOZ)/subsystems/booz2_fms_test_signal.makefile

#stuff from nova below

ap.CFLAGS += -DFAILSAFE_GROUND_DETECT

include $(CFG_BOOZ)/subsystems/ins_hff.makefile
#set USE_GPS lag for horizontal filter
ap.CFLAGS += -DGPS_LAG=0.8 -DUSE_GPS_ACC4R
ap.CFLAGS += -DGPS_USE_LATLONG

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


  </makefile>

</airframe>
