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

<airframe name="SilverTwin">
  <description>
Silverlit Twin
Lisa/S v1.0 board (http://wiki.paparazziuav.org/wiki/Lisa/S)
  </description>

  <firmware name="fixedwing"> <!-- -->
    <target name="ap" board="lisa_s_1.0">
      <define name="USE_PERSISTENT_SETTINGS" value="TRUE"/>

      <module name="radio_control" type="superbitrf_rc">
        <!-- TUDelft Dx6i: TX 4 1974942194, TX 5 692352099, the superbitrf dongle : 2008496626 -->
        <!-- graupner (orange RX) : 3327503026, graupner (spektrum 9) : 4095452533 -->
        <!-- use 0x for the hex version -->
        <!-- 3411796053 -->
        <define name="RADIO_TRANSMITTER_ID" value="-883171243"/>    <!-- TX2 : 0xCB5BE055 -883171243-->
        <define name="RADIO_TRANSMITTER_PROTOCOL" value="DSM_DSM2_1"/>
        <!--<define name="RADIO_TRANSMITTER_PROTOCOL" value="0x01"/>--> <!-- DSM_DSM2_1 -->
        <define name="RADIO_TRANSMITTER_CHAN" value="6"/>
        <define name="RADIO_MODE" value="RADIO_GEAR"/>  <!-- RADIO_FLAP -->
      </module>

      <define name="USE_PERSISTENT_SETTINGS" value="TRUE"/>

      <!-- the  periodic frequency is 60 by default in fixed wing, 512 in rotorcraft -->
      <!-- AHRS_PROPAGATE_FREQUENCY mus be < PERIODIC_FREQUENCY -->
      <configure name="AHRS_PROPAGATE_FREQUENCY" value="120"/>
      <configure name="PERIODIC_FREQUENCY" value="120"/>  <!-- 120 seams to be the max of the barometer -->

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

    <define name="LOITER_TRIM"/>
    <define name="STRONG_WIND"/>

    <!--<define name="LISA_S_SIDEWAY"/>-->

    <define name="USE_BAROMETER" value="TRUE"/>

    <!-- Communication -->
    <!--<module name="telemetry" type="transparent">-->
    <!--<configure name="MODEM_BAUD" value="B57600"/>
    <configure name="MODEM_PORT" value="UART1"/>-->
    <!--</module>-->

    <module name="telemetry" type="superbitrf"/>


    <!-- Sensors -->
    <module name="imu" type="lisa_s_v1.0"/>   <!-- lisa_s_v1.0 -->
    <module name="gps" type="ublox">
      <configure name="GPS_PORT" value="UART3"/>
      <configure name="GPS_BAUD" value="B38400"/>
    </module>

    <module name="actuators" type="pwm">
      <define name="SERVO_HZ" value="8000"/>
      <define name="USE_SERVOS_1AND2"/>
    </module>

    <!--<module name="ahrs" type="float_dcm"/>-->
    <!--<module name="ahrs" type="int_cmpl_quat"/>-->
    <module name="ahrs" type="int_cmpl_quat">
      <configure name="USE_MAGNETOMETER" value="TRUE"/>
      <configure name="AHRS_USE_GPS_HEADING" value="FALSE"/>
    </module>

    <!--<module name="stabilization" type="int_quat"/>-->

    <module name="control"/>
    <module name="navigation"/>

    <module name="ins" type="alt_float"/>
  </firmware>

  <modules main_freq="512"> <!-- NEW (512hz) -->
    <module name="baro_sim"/>
    <module name="gps" type="ubx_ucenter"/>
    <module name="nav" type="line"/>
    <!--<module name="nav" type="catapult"/>-->
    <!--<module name="send_imu_mag_current"/>-->
    <!--<load name="geo_init"/>-->
  </modules>


  <!--<section name="CATAPULT" prefix="NAV_CATAPULT_" >
    <define name="MOTOR_DELAY" value="0.1" unit="seconds"/>
    <define name="HEADING_DELAY" value="2.0" unit="seconds"/>
    <define name="ACCELERATION_THRESHOLD" value="0.2"/>
    <define name="INITIAL_PITCH" value="5" unit="deg"/>
    <define name="INITIAL_THROTTLE" value="1.0" />
  </section>-->



  <servos driver="Pwm">
    <servo name="MOTORLEFT" no="3" min="0" neutral="0" max="125"/>
    <servo name="MOTORRIGHT" no="2" min="0" neutral="0" max="125"/>
  </servos>


  <commands>
    <axis name="THROTTLE" failsafe_value="0"/>
    <axis name="ROLL" failsafe_value="3000"/>
    <axis name="PITCH" failsafe_value="0"/>
    <axis name="YAW" failsafe_value="0"/>
  </commands>

  <rc_commands>
    <set command="THROTTLE" value="@THROTTLE"/>
    <set command="ROLL" value="@ROLL"/>
    <set command="PITCH" value="@PITCH"/>
    <set command="YAW" value="@YAW"/>
  </rc_commands>

  <section name="MIXER">
    <define name="AILEVON_AILERON_RATE" value="0.75"/>
    <define name="AILEVON_ELEVATOR_RATE" value="0.75"/>
  </section>

  <command_laws>
    <set servo="MOTORLEFT" value="@THROTTLE + @PITCH * 0.3 + @ROLL"/>
    <set servo="MOTORRIGHT" value="@THROTTLE + @PITCH * 0.3 - @ROLL"/>
  </command_laws>



 <section name="SIMULATOR" prefix="NPS_">
   <define name="ACTUATOR_NAMES" value="front_motor, back_motor, right_motor, left_motor" type="string[]"/>
   <define name="JSBSIM_MODEL" value="simple_quad" type="string"/>
   <define name="SENSORS_PARAMS" value="nps_sensors_params_default.h" type="string"/>
 </section>

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

    <!-- these gyro and accel calib values are the defaults for aspirin2.1/2.2 -->
    <define name="GYRO_X_NEUTRAL" value="0"/>
    <define name="GYRO_Y_NEUTRAL" value="0"/>
    <define name="GYRO_Z_NEUTRAL" value="0"/>

    <define name="GYRO_X_SENS" value="4.359" integer="16"/>
    <define name="GYRO_Y_SENS" value="4.359" integer="16"/>
    <define name="GYRO_Z_SENS" value="4.359" integer="16"/>

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

    <define name="ACCEL_X_SENS" value="4.905" integer="16"/>	<!-- 4.905/9.81 -->
    <define name="ACCEL_Y_SENS" value="4.905" integer="16"/>
    <define name="ACCEL_Z_SENS" value="4.905" integer="16"/>

  <!-- delfly beta1 <define name="MAG_X_NEUTRAL" value="-349"/>
    <define name="MAG_Y_NEUTRAL" value="130"/>
    <define name="MAG_Z_NEUTRAL" value="355"/>
    <define name="MAG_X_SENS" value="3.66980420844" integer="16"/>
    <define name="MAG_Y_SENS" value="3.86694176583" integer="16"/>
    <define name="MAG_Z_SENS" value="4.02840414264" integer="16"/>-->

    <define name="MAG_X_NEUTRAL" value="914"/>
    <define name="MAG_Y_NEUTRAL" value="20"/>
    <define name="MAG_Z_NEUTRAL" value="71"/>
    <define name="MAG_X_SENS" value="3.6433558115" integer="16"/>
    <define name="MAG_Y_SENS" value="4.0497072473" integer="16"/>
    <define name="MAG_Z_SENS" value="4.52432874264" integer="16"/>

    <!--<define name="MAG_X_CURRENT_COEF" value="-0.0166153857964"/>
    <define name="MAG_Y_CURRENT_COEF" value="0.00153949503277"/>-
    <define name="MAG_Z_CURRENT_COEF" value="0.0295034374697"/>-->

    <define name="BODY_TO_IMU_PHI" value="-90." unit="deg"/> <!-- Roll -104 -->
    <define name="BODY_TO_IMU_THETA" value="-180." unit="deg"/> <!-- pitch : true value : 180; add 15° of pitching up : -165 -->
    <define name="BODY_TO_IMU_PSI" value="0." unit="deg"/> <!-- Yaw -->
  </section>



  <section name="AHRS" prefix="AHRS_">
    <!--     Delft magnetic field karlito   -->
    <define name="H_X" value="0.3946524"/> <!-- 0.3770441 -->
    <define name="H_Y" value="-0.0187289"/> <!-- 0.0193986 -->
    <define name="H_Z" value="0.9186396"/> <!-- 0.9259921 -->
  </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="4.2" unit="volt"/>
    <!-- outer loop proportional gain -->
    <define name="ALTITUDE_PGAIN" value="0.100"/>
    <!-- outer loop saturation -->
    <define name="ALTITUDE_MAX_CLIMB" value="2."/>

    <!-- auto throttle inner loop -->
    <define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.9"/>
    <define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.7"/>
    <define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.99"/>
    <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.04"/>
    <define name="AUTO_THROTTLE_IGAIN" value="0.03"/>
    <define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.08"/>

    <define name="THROTTLE_SLEW_LIMITER" value="0.06" unit="s"/>

    <!--<define name="PITCH_LOITER_TRIM" value="RadOfDeg(50.)"/>
    <define name="PITCH_DASH_TRIM" value="RadOfDeg(-0.)"/>-->
  </section>



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

    <define name="ROLL_MAX_SETPOINT" value="35.8098622366" unit="deg"/>
    <define name="PITCH_MAX_SETPOINT" value="45" unit="deg"/>
    <define name="PITCH_MIN_SETPOINT" value="-25" unit="deg"/>

    <define name="PITCH_PGAIN" value="0"/>
    <define name="PITCH_DGAIN" value="0"/>

    <define name="ELEVATOR_OF_ROLL" value="800"/>

    <define name="ROLL_SLEW" value="1000"/>

    <define name="ROLL_ATTITUDE_GAIN" value="1000"/>
    <define name="ROLL_RATE_GAIN" value="10"/>
  </section>



  <section name="FAILSAFE" prefix="FAILSAFE_">
    <define name="DELAY_WITHOUT_GPS" value="5" unit="s"/>
    <define name="DEFAULT_THROTTLE" value="0.0"/>
    <define name="DEFAULT_ROLL" value="5000"/>
    <define name="DEFAULT_PITCH" value="3000"/>
  </section>



  <section name="AUTO1" prefix="AUTO1_">
    <define name="MAX_ROLL" value="90." unit="deg"/>
    <define name="MAX_PITCH" value="40." unit="deg"/>
  </section>



  <section name="BAT">
    <define name="MILLIAMP_AT_FULL_THROTTLE" value="1500"/>
    <define name="BAT_CHECKER_DELAY" value="5"/>
    <define name="CATASTROPHIC_BAT_LEVEL" value="2.0" unit="V"/>
    <define name="CRITIC_BAT_LEVEL" value="2.1" unit="V"/>
    <define name="LOW_BAT_LEVEL" value="2.2" unit="V"/>
    <define name="MAX_BAT_LEVEL" value="4.1" unit="V"/>
    <define name="VoltageOfAdc(adc)" value="(0.0052*adc)"/>
  </section>





  <section name="MISC">
    <define name="NOMINAL_AIRSPEED" value="6." unit="m/s"/>
	  <define name="MIN_AIRSPEED" value="3." unit="m/s"/>
	  <define name="MAX_AIRSPEED" value="12." unit="m/s"/>
    <define name="CARROT" value="3." unit="s"/>
    <define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
    <define name="CONTROL_FREQUENCY" value="120" unit="Hz"/>
    <define name="DEFAULT_CIRCLE_RADIUS" value="10."/>

    <define name="UNLOCKED_HOME_MODE" value="TRUE"/>
    <define name="RC_LOST_MODE" value="PPRZ_MODE_AUTO2"/>
  </section>


</airframe>
