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

<!--

Tricopter Frame, MKK2 BLDC x3 + Servo x1, Lisa-m-2.

http://www.robbe.de/roxxy-bl-outrunner-2827-34.html

Technische Daten

Abmessungen: Ø 28 x 29 mm
Freie Wellenlänge: 12.5 mm
Gewicht ca.: 57 g
Laststrom (5min/120°C): 9 A
Umdrehung / Volt: 760 Umin/V
Max.Wirkungsgrad: 76 %
Laststrom max. (60 Sek.): 10 A
Zellenzahl: 6-10 NC/NiMH
Leistung: 110 W
Wellendurchmesser: 3.17 mm
Spannung: 7-12 Volt
LiPo/LiIo-Zellen: 2-3

-->

<airframe name="TriCopter_CDW">
  <!-- ************************* FIRMWARE ************************* -->

  <firmware name="rotorcraft">
    <target name="ap" board="lisa_m_2.0">
      <define name="RADIO_KILL_SWITCH" value="RADIO_FLAPS"/>
      <define name="USE_KILL_SWITCH_FOR_MOTOR_ARMING" value="1"/>
      <define name="USE_ATTITUDE_REF" value="1" />
      <define name="AHRS_PROPAGATE_LOW_PASS_RATES" value="1" />
    </target>
    <target name="nps" board="pc">
      <subsystem name="fdm" type="jsbsim"/>
    </target>
    <subsystem name="radio_control" type="ppm"/>
    <subsystem name="telemetry" type="xbee_api"/>
    <subsystem name="motor_mixing"/>
    <subsystem name="actuators" type="mkk_v2"/>
    <subsystem name="actuators" type="pwm">
      <define name="USE_PWM0"/>
    </subsystem>
    <subsystem name="imu" type="aspirin_v2.1"/>
    <subsystem name="gps" type="ublox"/>
    <subsystem name="stabilization" type="int_euler"/>
    <subsystem name="ahrs" type="int_cmpl_euler"/>
    <subsystem name="ins" type="hff"/>
  </firmware>

  <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_Z_HOLD"/>
  </section>

  <!-- ************************* MODULES ************************* -->

  <modules>
    <load name="configure_actuators_mkk_v2.xml"/>
    <load name="imu_quality_assessment.xml"/>
  </modules>

  <!-- ************************* ACTUATORS ************************* -->

  <section name="ACTUATORS_MKK_V2" prefix="ACTUATORS_MKK_V2_">
    <define name="NB" value="3"/>
    <define name="ADDR" value="{ 0x52, 0x56, 0x54 }"/>
    <define name="DEVICE" value="i2c1"/>
  </section>

  <servos driver="Mkk_v2">
    <servo name="FRONTRIGHT" no="0" min="0" neutral="30" max="2047"/>
    <servo name="FRONTLEFT" no="1" min="0" neutral="30" max="2047"/>
    <servo name="BACK" no="2" min="0" neutral="30" max="2047"/>
  </servos>

  <servos driver="Pwm">
    <servo name="TAIL" no="0" min="1000" neutral="1500" 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="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="3"/>
    <define name="SCALE" value="2048"/>
    <define name="ROLL_COEF" value="{  2048, -2048,    0}"/>
    <define name="PITCH_COEF" value="{  1024,  1024, -2048}"/>
    <define name="YAW_COEF" value="{    0,    0,    0}"/>
    <define name="THRUST_COEF" value="{ 2048,  2048,  2048}"/>
  </section>

  <command_laws>
    <call fun="motor_mixing_run(autopilot_motors_on,FALSE,values)"/>
    <set servo="FRONTRIGHT" value="motor_mixing.commands[0]"/>
    <set servo="FRONTLEFT" value="motor_mixing.commands[1]"/>
    <set servo="BACK" value="motor_mixing.commands[2]"/>
    <set servo="TAIL" value="@YAW"/>
  </command_laws>

  <!-- ************************* SENSORS ************************* -->

  <section name="IMU" prefix="IMU_">
    <define name="MAG_X_NEUTRAL" value="-152"/>
    <define name="MAG_Y_NEUTRAL" value="-51"/>
    <define name="MAG_Z_NEUTRAL" value="10"/>
    <define name="MAG_X_SENS" value="4.04042714046" integer="16"/>
    <define name="MAG_Y_SENS" value="3.95350991963" integer="16"/>
    <define name="MAG_Z_SENS" value="3.83055079257" 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="-90." unit="deg"/>
  </section>

  <!-- local magnetic field, calculated for: 52°3'56", 4°31'24" -->
  <!-- http://wiki.paparazziuav.org/wiki/Subsystem/ahrs#Local_Magnetic_Field -->
  <section name="AHRS" prefix="AHRS_">
    <define name="H_X" value="0.513081"/>
    <define name="H_Y" value="-0.00242783"/>
    <define name="H_Z" value="0.858336"/>
  </section>

  <!-- section name="AHRS" >
    <define name="ACCEL_OMEGA" value="0.0063" />
    <define name="MAG_OMEGA" value="0.004" />
  </section -->

  <section name="INS" prefix="INS_">
  </section>

  <!-- ************************* GAINS ************************* -->

  <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="1350"/>
  </section>

  <section name="STABILIZATION_ATTITUDE" prefix="STABILIZATION_ATTITUDE_">
    <!-- setpoints -->
    <define name="SP_MAX_PHI" value="55." unit="deg"/>
    <define name="SP_MAX_THETA" value="55." unit="deg"/>
    <define name="SP_MAX_R" value="360." unit="deg/s"/>
    <define name="DEADBAND_R" value="200"/>
    <!-- reference -->
    <define name="REF_OMEGA_P" value="800" unit="deg/s"/>
    <define name="REF_ZETA_P" value="0.9"/>
    <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.9"/>
    <define name="REF_MAX_Q" value="300." unit="deg/s"/>
    <define name="REF_MAX_QDOT" value="RadOfDeg(7000.)"/>
    <define name="REF_OMEGA_R" value="1200" unit="deg/s"/>
    <define name="REF_ZETA_R" value="0.85"/>
    <define name="REF_MAX_R" value="600." unit="deg/s"/>
    <define name="REF_MAX_RDOT" value="RadOfDeg(7000.)"/>
    <!-- feedback -->
    <define name="PHI_PGAIN" value="400"/>
    <define name="PHI_DGAIN" value="410"/>
    <define name="PHI_IGAIN" value="0"/>
    <define name="THETA_PGAIN" value="400"/>
    <define name="THETA_DGAIN" value="410"/>
    <define name="THETA_IGAIN" value="114"/>
    <define name="PSI_PGAIN" value="900"/>
    <define name="PSI_DGAIN" value="1328"/>
    <define name="PSI_IGAIN" value="0"/>
    <!-- feedforward -->
    <define name="PHI_DDGAIN" value=" 100"/>
    <define name="THETA_DDGAIN" value=" 100"/>
    <define name="PSI_DDGAIN" value=" 300"/>
  </section>

  <section name="GUIDANCE_V" prefix="GUIDANCE_V_">
    <define name="HOVER_KP" value="500"/>
    <define name="HOVER_KD" value="200"/>
    <define name="HOVER_KI" value="100"/>
  </section>

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

  <!-- ************************* MISC ************************* -->

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

  <section name="FMS">

  </section>

  <section name="MISC">
    <define name="XBEE_INIT" value="&quot;ATID3332\r&quot;"/>
    <define name="FACE_REINJ_1" value="1024"/>
    <define name="VoltageOfAdc(adc)" value="(0.00528*adc)"/>
  </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="SENSORS_PARAMS" value="&quot;nps_sensors_params_default.h&quot;"/>
  </section>

  </airframe>
