<!--
 This airframe is connected to the build server and is used for hardware testing.
 The hardware configuration is
 Powered via a plug 12V pack
 Lisa/L v1.1 board
 XBee connected to UART2 configured at 38400
 Aspirin v1.5
 GPS connected to UART1 (Since this is inside in a metal box it won't ever get a solution)
 -->
<airframe name="TestConfig">
    <firmware name="fixedwing">
        <target name="sim"          board="pc"/>
        <target name="ap"           board="lisa_l_1.1">
            <configure name="PERIODIC_FREQUENCY" value="120"/>
        </target>

		<subsystem name="radio_control" type="ppm"/>
        <subsystem name="telemetry"     type="xbee_api">
            <configure name="MODEM_BAUD" value="B38400"/>
        </subsystem>
        <subsystem name="control"/>
        <subsystem name="imu"           type="aspirin_v1.5"/>
        <subsystem name="gps"           type="ublox">
            <configure name="GPS_BAUD"    value="B57600"/>
        </subsystem>
        <subsystem name="ahrs" type="float_dcm"/>
        <subsystem name="navigation"/>
        <subsystem name="ins" type="alt_float"/>
    </firmware>

    <servos>
        <servo name="MOTOR"         no="0" min="1000" neutral="1000" max="2000"/>
        <servo name="AILEVON_LEFT"  no="1" min="1900" neutral="1534" max="1100"/>
        <servo name="AILEVON_RIGHT" no="2" min="1100" neutral="1468" max="1900"/>
    </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.45"/>
        <define name="AILEVON_ELEVATOR_RATE" value="0.8"/>
    </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"/>
        <set servo="AILEVON_RIGHT" value="$elevator - $aileron"/>
    </command_laws>

    <section name="AUTO1" prefix="AUTO1_">
        <define name="MAX_ROLL" value="50" unit="deg"/>
        <define name="MAX_PITCH" value="35" unit="deg"/>
    </section>

    <section name="BAT">
        <define name="LOW_BAT_LEVEL" value="10.5" unit="V"/>
        <define name="CRITIC_BAT_LEVEL" value="10" unit="V"/>
        <define name="CATASTROPHIC_BAT_LEVEL" value="9.1" unit="V"/>
    </section>

    <section name="FAILSAFE" prefix="FAILSAFE_">
        <define name="DELAY_WITHOUT_GPS" value="2" 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>

    <section name="MISC">
        <define name="NOMINAL_AIRSPEED" value="13." unit="m/s"/>
        <define name="CARROT" value="5." unit="s"/>
        <define name="CONTROL_FREQUENCY" value="60" unit="Hz"/>
        <define name="XBEE_INIT" value="&quot;ATPL2\rATRN5\rATTT80\r&quot;"/>
        <!--    <define name="NO_XBEE_API_INIT" value="TRUE"/> -->
        <define name="DEFAULT_CIRCLE_RADIUS" value="80."/>
    </section>

    <!-- Local magnetic field -->
    <section name="AHRS" prefix="AHRS_" >
        <define name="H_X" value="0.51562740288882" />
        <define name="H_Y" value="-0.05707735220832" />
        <define name="H_Z" value="0.85490967783446" />
    </section>

    <section name="IMU" prefix="IMU_">
        <!-- Calibration Neutral -->
        <define name="GYRO_P_NEUTRAL" value="0"/>
        <define name="GYRO_Q_NEUTRAL" value="0"/>
        <define name="GYRO_R_NEUTRAL" value="0"/>

        <!-- SENS = 14.375 LSB/(deg/sec) * 57.6 deg/rad = 828 LSB/rad/sec / 12bit FRAC: 4096 / 828 -->
        <define name="GYRO_P_SENS" value="4.947" integer="16"/>
        <define name="GYRO_Q_SENS" value="4.947" integer="16"/>
        <define name="GYRO_R_SENS" value="4.947" integer="16"/>

        <define name="GYRO_P_Q" value="0."/>
        <define name="GYRO_P_R" value="0"/>
        <define name="GYRO_Q_P" value="0."/>
        <define name="GYRO_Q_R" value="0."/>
        <define name="GYRO_R_P" value="0."/>
        <define name="GYRO_R_Q" value="0."/>

        <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_NEUTRAL" value="-14"/>
        <define name="ACCEL_Y_NEUTRAL" value="0"/>
        <define name="ACCEL_Z_NEUTRAL" value="0"/>

        <!-- SENS = 256 LSB/g @ 2.5V [X&Y: 265 LSB/g @ 3.3V] / 9.81 ms2/g = 26.095 LSB/ms2 / 10bit FRAC: 1024 / 26.095 for z and 1024 / 27.01 for X&Y -->
        <define name="ACCEL_X_SENS" value="37.9" integer="16"/>
        <define name="ACCEL_Y_SENS" value="37.9" integer="16"/>
        <define name="ACCEL_Z_SENS" value="39.24" 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="MAG_X_NEUTRAL" value="0"/>
        <define name="MAG_Y_NEUTRAL" value="0"/>
        <define name="MAG_Z_NEUTRAL" value="0"/>

        <define name="MAG_X_SENS" value="1" integer="16"/>
        <define name="MAG_Y_SENS" value="1" integer="16"/>
        <define name="MAG_Z_SENS" value="1" integer="16"/>

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

        <define name="BODY_TO_IMU_PHI" value="90.0" unit="deg"/>
        <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" unit="deg"/>
        <define name="PITCH_NEUTRAL_DEFAULT" value="0" unit="deg"/>
    </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.03"/>
        <!-- outer loop saturation -->
        <define name="ALTITUDE_MAX_CLIMB" value="2."/>

        <!-- auto throttle inner loop -->
        <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.32"/>
        <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.25"/>
        <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.65"/>
        <define name="AUTO_THROTTLE_LOITER_TRIM" value="1500"/>
        <define name="AUTO_THROTTLE_DASH_TRIM" value="-4000"/>
        <define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.15" unit="%/(m/s)"/>
        <define name="AUTO_THROTTLE_PGAIN" value="0.01"/>
        <define name="AUTO_THROTTLE_IGAIN" value="0.1"/>
        <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.05"/>

        <define name="THROTTLE_SLEW_LIMITER" value="2" unit="s"/>
    </section>

    <section name="HORIZONTAL CONTROL" prefix="H_CTL_">
        <define name="COURSE_PGAIN" value="1.20000004768"/>
        <define name="COURSE_DGAIN" value="0.3"/>
        <define name="COURSE_PRE_BANK_CORRECTION" value="0.2"/>

        <define name="ROLL_MAX_SETPOINT" value="0.75" 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="12000."/>
        <define name="PITCH_DGAIN" value="1.5"/>

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

        <define name="ROLL_SLEW" value="1."/>

        <define name="ROLL_ATTITUDE_GAIN" value="7500"/>
        <define name="ROLL_RATE_GAIN" value="0."/>
    </section>

</airframe>
