<?xml version="1.0" ?>
<!--
    Zephyr Delta Wing with Parachute

    https://ardupilot.org/plane/docs/common-parachute.html#common-parachute

    1. Parachute set up

    ArduPilotPlugin
    ===============

    Add a control element for the parachute:

    <control channel="4">
      <jointName>parachute_attachment_joint</jointName>
      <type>COMMAND</type>
      <cmd_topic>/parachute/cmd_release</cmd_topic>
      <servo_min>1100</servo_min>
      <servo_max>1900</servo_max>
    </control>


    ParachutePlugin
    ===============

    Add the parachute plugin element to the model:

      <plugin filename="libParachutePlugin.so" name="ParachutePlugin">
        <parent_link>parachute_attachment_link</parent_link>
        <child_model>parachute_small</child_model>
        <child_link>chute</child_link>
        <child_pose>0 0 0 0 -1.0 0</child_pose>
        <cmd_topic>/parachute/cmd_release</cmd_topic>
      </plugin>


    Zephyr Parameters
    =================

    Set the parameters for parachute release using MAVProxy:

    # Enable parachute release triggered by a servo.
    CHUTE_ALT_MIN    0
    CHUTE_CRT_SINK   0.0
    CHUTE_DELAY_MS   500
    CHUTE_ENABLED    1        # Enabled
    CHUTE_OPTIONS    1
    CHUTE_SERVO_OFF  1100
    CHUTE_SERVO_ON   1900
    CHUTE_TYPE       10       # Servo

    # Assign servo5 for parachute release.
    SERVO5_FUNCTION  27       # Parachute
    SERVO5_MAX       1900
    SERVO5_MIN       1100
    SERVO5_REVERSED  0        # Normal
    SERVO5_TRIM      1500

    # Assign RC9 to trigger manual release.
    RC9_MAX          1900
    RC9_MIN          1100
    RC9_OPTION       22       # Parachute Release
    RC9_REVERSED     0        # Normal
    RC9_TRIM         1500

  2. Running

  Server
  ======

  gz sim -v4 -s -r zephyr_runway.sdf

  Client
  ======

  gz sim -v4 -g

  SITL
  ====

  sim_vehicle.py -D -v ArduPlane -f gazebo-zephyr -\-model JSON -\-map -\-console

  MAVProxy
  ========

  A figure of 8 mission at alt = 100m is set.

  MANUAL> fbwa            # switch mode 
  FBWA>   arm throttle    # arm
  FBWA>   rc 3 1900       # vertical launch
  FBWA>   auto            # switch to auto
  AUTO>   rc 9 1900       # manual parachute release
-->
<sdf version="1.9">
  <world name="zephyr_runway">
    <physics name="1ms" type="ignore">
      <max_step_size>0.001</max_step_size>
      <real_time_factor>-1.0</real_time_factor>
    </physics>

    <plugin filename="gz-sim-physics-system"
      name="gz::sim::systems::Physics">
    </plugin>
    <plugin filename="gz-sim-user-commands-system"
      name="gz::sim::systems::UserCommands">
    </plugin>
    <plugin filename="gz-sim-scene-broadcaster-system"
      name="gz::sim::systems::SceneBroadcaster">
    </plugin>
    <plugin filename="gz-sim-imu-system"
      name="gz::sim::systems::Imu">
    </plugin>
    <plugin filename="gz-sim-navsat-system"
      name="gz::sim::systems::NavSat">
    </plugin>

    <scene>
      <ambient>1.0 1.0 1.0</ambient>
      <background>0.8 0.8 0.8</background>
      <sky></sky>
    </scene>

    <spherical_coordinates>
      <latitude_deg>-35.363262</latitude_deg>
      <longitude_deg>149.165237</longitude_deg>
      <elevation>584</elevation>
      <heading_deg>0</heading_deg>
      <surface_model>EARTH_WGS84</surface_model>
    </spherical_coordinates>

    <light type="directional" name="sun">
      <cast_shadows>true</cast_shadows>
      <pose>0 0 10 0 0 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.8 0.8 0.8 1</specular>
      <attenuation>
        <range>1000</range>
        <constant>0.9</constant>
        <linear>0.01</linear>
        <quadratic>0.001</quadratic>
      </attenuation>
      <direction>-0.5 0.1 -0.9</direction>
    </light>

    <model name="axes">
      <static>1</static>
      <link name="link">
        <visual name="r">
          <cast_shadows>0</cast_shadows>
          <pose>5 0 0.1 0 0 0</pose>
          <geometry>
            <box>
              <size>10 0.01 0.01</size>
            </box>
          </geometry>
          <material>
            <ambient>1 0 0 0.8</ambient>
            <diffuse>1 0 0 0.8</diffuse>
            <emissive>1 0 0 0.8</emissive>
            <specular>0.5 0.5 0.5 0.8</specular>
          </material>
        </visual>
        <visual name="g">
          <cast_shadows>0</cast_shadows>
          <pose>0 5 0.1 0 0 0</pose>
          <geometry>
            <box>
              <size>0.01 10 0.01</size>
            </box>
          </geometry>
          <material>
            <ambient>0 1 0 0.8</ambient>
            <diffuse>0 1 0 0.8</diffuse>
            <emissive>0 1 0 0.8</emissive>
            <specular>0.5 0.5 0.5 0.8</specular>
          </material>
        </visual>
        <visual name="b">
          <cast_shadows>0</cast_shadows>
          <pose>0 0 5.1 0 0 0</pose>
          <geometry>
            <box>
              <size>0.01 0.01 10</size>
            </box>
          </geometry>
          <material>
            <ambient>0 0 1 0.8</ambient>
            <diffuse>0 0 1 0.8</diffuse>
            <emissive>0 0 1 0.8</emissive>
            <specular>0.5 0.5 0.5 0.8</specular>
          </material>
        </visual>
        <sensor name="navsat_sensor" type="navsat">
          <always_on>1</always_on>
          <update_rate>1</update_rate>
        </sensor>
      </link>
    </model>
    
    <include>
      <uri>model://runway</uri>
      <pose degrees="true">-29 545 0 0 0 363</pose>
    </include>

    <include>
      <uri>model://zephyr_with_parachute</uri>
      <pose degrees="true">0 0 0.422 -90 0 180</pose>

      <plugin name="ParachutePlugin" filename="ParachutePlugin">
        <parent_link>parachute_attachment_link</parent_link>
        <child_model>parachute_small</child_model>
        <child_link>chute</child_link>
        <child_pose>0 0 0 0 -1.0 0</child_pose>
        <cmd_topic>/parachute/cmd_release</cmd_topic>
      </plugin>

    </include>

  </world>
</sdf>

