
<airframe name="flappy">
  <description>Ornitopter frame equiped with Lisa/MXS 1.0 and MX-3.5A pwm motor controllers
  </description>

  <servos driver="Pwm">
    <servo name="NE" no="0" min="1100" neutral="1120" max="1900"/>
    <servo name="SE" no="1" min="1100" neutral="1120" max="1900"/>
    <servo name="SW" no="2" min="1100" neutral="1120" max="1900"/>
    <servo name="NW" no="3" min="1100" neutral="1120" max="1900"/>
  </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>

  <command_laws>
    <call fun="motor_mixing_run(autopilot_get_motors_on(),FALSE,values)"/>
    <set servo="NE" value="motor_mixing.commands[2]"/>
    <set servo="SE" value="motor_mixing.commands[3]"/>
    <set servo="SW" value="motor_mixing.commands[0]"/>
    <set servo="NW" value="motor_mixing.commands[1]"/>
  </command_laws>

  <section name="MIXING" prefix="MOTOR_MIXING_">
    <define name="TRIM_ROLL" value="0"/>
    <define name="TRIM_PITCH" value="0"/>
    <define name="TRIM_YAW" value="0"/>
    <define name="NB_MOTOR" value="4"/>
    <define name="SCALE" value="256"/>
    <define name="ROLL_COEF" value="{  -256, -256,  256,  256 }"/>
    <define name="PITCH_COEF" value="{  256, -256, -256,  256 }"/>
    <define name="YAW_COEF" value="{   -256,  256, -256,  256 }"/>
    <define name="THRUST_COEF" value="{ 256,  256,  256,  256 }"/>
  </section>

  <section name="IMU" prefix="IMU_">
    <define name="BODY_TO_IMU_PHI"   value="90." unit="deg"/>
    <define name="BODY_TO_IMU_THETA" value="0." unit="deg"/>
    <define name="BODY_TO_IMU_PSI"   value="90." unit="deg"/>

    <define name="ACCEL_X_NEUTRAL" value="0"/>
    <define name="ACCEL_Y_NEUTRAL" value="0"/>
    <define name="ACCEL_Z_NEUTRAL" value="0"/>

    <!-- MAGNETO CALIBRATION DELFT -->
    <define name="MAG_X_NEUTRAL" value="286"/>
    <define name="MAG_Y_NEUTRAL" value="-72"/>
    <define name="MAG_Z_NEUTRAL" value="97"/>
    <define name="MAG_X_SENS" value="3.94431833863" integer="16"/>
    <define name="MAG_Y_SENS" value="4.14629702271" integer="16"/>
    <define name="MAG_Z_SENS" value="4.54518768636" integer="16"/>

    <!-- MAGNETO CURRENT CALIBRATION 
    <define name="MAG_X_CURRENT_COEF" value="0.0103422023767"/>
    <define name="MAG_Y_CURRENT_COEF" value="0.0084568317783"/>
    <define name="MAG_Z_CURRENT_COEF" value="-0.01935617335"/>-->
  </section>

 <section name="AUTOPILOT">
   <define name="MODE_STARTUP" value="AP_MODE_NAV"/>
   <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="BAT">
   <define name="MILLIAMP_AT_FULL_THROTTLE" value="14000"/>
   <define name="CATASTROPHIC_BAT_LEVEL" value="3.0" unit="V"/>
   <define name="CRITIC_BAT_LEVEL" value="3.3" unit="V"/>
    <define name="LOW_BAT_LEVEL" value="3.5" unit="V"/>
    <define name="MAX_BAT_LEVEL" value="4.1" unit="V"/>
 </section>

  <section name="STABILIZATION_RATE" prefix="STABILIZATION_RATE_">
    <define name="SP_MAX_P" value="15000"/>
    <define name="SP_MAX_Q" value="15000"/>
    <define name="SP_MAX_R" value="15000"/>

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

    <define name="IGAIN_P" value="301"/>
    <define name="IGAIN_Q" value="302"/>
    <define name="IGAIN_R" value="303"/>
  </section>

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

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

    <!-- reference -->
    <define name="REF_OMEGA_P" value="750" 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(8000.)"/>

    <define name="REF_OMEGA_Q" value="750" 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(8000.)"/>

    <define name="REF_OMEGA_R" value="250" unit="deg/s"/>
    <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(1000.)"/>

    <!-- feedback -->
    <define name="PHI_PGAIN" value="320"/>
    <define name="PHI_DGAIN" value="220"/>
    <define name="PHI_IGAIN" value="0"/>

    <define name="THETA_PGAIN" value="320"/>
    <define name="THETA_DGAIN" value="220"/>
    <define name="THETA_IGAIN" value="0"/>

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

    <!-- feedforward -->
    <define name="PHI_DDGAIN" value="0"/>
    <define name="THETA_DDGAIN" value="0"/>
    <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_">
  </section>

 <section name="GUIDANCE_V" prefix="GUIDANCE_V_">
   <define name="HOVER_KP" value="276"/>
   <define name="HOVER_KD" value="455"/>
   <define name="HOVER_KI" value="100"/>
   <define name="GUIDANCE_V_NOMINAL_HOVER_THROTTLE" value="0.5"/>
  </section>

  <section name="AHRS" prefix="AHRS_">
    <define name="H_X" value=" 0.47577"/>
    <define name="H_Y" value=" 0.11811"/>
    <define name="H_Z" value=" 0.87161"/>
  </section>

 <section name="GUIDANCE_H" prefix="GUIDANCE_H_">
   <define name="PGAIN" value="39"/>
   <define name="DGAIN" value="50"/>
   <define name="IGAIN" value="19"/>
 </section>

  <section name="MISC">
    <define name="VoltageOfAdc(adc)" value="(adc)*0.00162f" />
  </section>


 <section name="SIMULATOR" prefix="NPS_">
   <define name="ACTUATOR_NAMES" value="{&quot;ne_motor&quot;, &quot;se_motor&quot;, &quot;sw_motor&quot;, &quot;nw_motor&quot;}"/>
   <define name="JSBSIM_MODEL" value="&quot;simple_x_quad_ccw&quot;"/>
   <define name="SENSORS_PARAMS" value="&quot;nps_sensors_params_default.h&quot;"/>
 </section>

 <modules main_freq="512">
   <!--load name="gps_ubx_ucenter.xml"/-->
   <!--load name="send_imu_mag_current.xml"/-->
   <!--load name="logger_uart.xml" /-->
 </modules>

  <firmware name="rotorcraft">
    <target name="ap" board="lisa_mx_2.1">
      <define name="REMAP_UART3" value="TRUE" />

      <!--configure name="SYS_TIME_LED" value="none" /-->
      <module name="radio_control" type="ppm">
      </module>
      <define name="RADIO_KILL_SWITCH" value="RADIO_KILL"/>
      <define name="USE_KILL_SWITCH_FOR_MOTOR_ARMING" value="1"/>
      <!--module name="radio_control" type="spektrum">
        <configure name="RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT" value="UART5" />
      </module-->

      <configure name="AHRS_PROPAGATE_FREQUENCY" value="500"/>
      <define name="USE_PERSISTENT_SETTINGS" value="TRUE"/>
    </target>

    <target name="nps" board="pc">
      <module name="fdm" type="jsbsim"/>
      <module name="radio_control" type="ppm"/>
    </target>

    <module name="motor_mixing"/>
    <module name="actuators" type="pwm">
      <define name="SERVO_HZ" value="400"/>
    </module>

    <!--module name="telemetry" type="superbitrf"/-->
    <!-- Comment the previous line and uncomment the following one if you need
         to use the debug serial interface for telemetry. -->
    <module name="telemetry" type="transparent">
      <configure name="MODEM_PORT" value="UART1"/>
      <configure name="MODEM_BAUD" value="B115200"/>
    </module>

    <module name="imu" type="lisa_mx_v2.1"/>

    <module name="gps" type="ublox">
      <configure name="GPS_PORT" value="UART2"/>
      <configure name="GPS_BAUD" value="B38400"/>
    </module>

    <module name="stabilization" type="int_quat"/>
    <module name="ahrs" type="int_cmpl_quat">
      <configure name="USE_MAGNETOMETER" value="FALSE"/>
    </module>
    <module name="ins"/>

    <module name="air_data">
      <define name="AIR_DATA_CALC_AMSL_BARO" value="TRUE"/>
    </module>

  </firmware>
</airframe>
