# TrackingMount1

Keywords: mount

## Summary

This scene demonstrates the Tracking mount, which will always point at a specific target geometry instance. The mount accounts for both platform and target motion. It is useful for setting up scenarios such as a UAV with a camera ball that follows a vehicle on the ground.

## Details

The scene contains a moving fighter jet and a moving truck. The imaging platform is moving due east and stares at the fighter jet. The tracking mount will dynamically compute the platform-relative pointing during the simulation to have the attached camera stare at either the fighter jet or the truck.

## Important Files

There are two components to setting up a tracking mount:

1. The geometry list (GLIST) file must have a unique name (or tag) assigned to the instance to be tracked.

2. The tracking mount must be selected and configured in the platform file.

### Scene Geometry

The `geometry/tracking.glist` GLIST file contains the scene gometry including a ground plane, a moving jet fighter and a moving truck. The truck and fighter each have a single "named" instance. A "named" instance is an instance with the `name` attribute set to unique string. This name can be used for a variety of purposes. In this scenario, the name will be used to tell the tracking mount which object to track.

The following excerpt from the `geometry/demo.glist` GLIST file shows the setup for the fighter jet, including the name `EnemyFighter` being assigned to the one `<dynamicinstance>`:

      <object tags="EnemyFighterObject">
        <basegeometry>
          <gdb><filename>aircraft.gdb</filename></gdb>
        </basegeometry>
        <dynamicinstance name="EnemyFighter">
          <keyframemovement>
            <filename>$SCENE_DIR/geometry/aircraft.mov</filename>
          </keyframemovement>
        </dynamicinstance>
      </object>

The truck inserted via the `geometry/demo.glist` GLIST file has a single dynamic instance with the name `EnemyTruck` assigned to it:

      <object tags="EnemyTruckObject">
        <basegeometry>
          <gdb><filename>truck.gdb</filename></gdb>
        </basegeometry>
        <dynamicinstance name="EnemyTruck">
          <keyframemovement>
            <filename>$SCENE_DIR/geometry/truck.mov</filename>
          </keyframemovement>
        </dynamicinstance>
      </object>

### Mount Configuration

As of the DISIG 4.6.5 release, this mount can be configured in the graphical Platform Editor. However, the mount can be manually configured by hand-editing the `.platform` file. To select this mount, the `type` attribute within the `<mount>` element must be set to `tracking`. The `<targetname>` element must be set to the name of a named instance in the scene. The example below the named instance `EnemyFighter` has be specified:

        <mount type="tracking" name="Tracking Mount">
          <data>
            <targetname>EnemyFighter</targetname>
            <targetoffset>
              <point><x>0.0</x><y>0.0</y><z>0.0</z></point>
            </targetoffset>
          </data>

Note that by default the mount will point to the (0,0,0) coordinate in the target geometry’s local coordinate space. It is possible to modify this location using the `<targetoffset>` element, which specifies the location in the instances local coordinate system that the mount will stare at. For example, this could be used to have the mount stare at the front or rear of the fighter rather than the middle (where the fighter’s origin is).

Note | To switch the tracked target from the figher to the truck, simply change the `<targetname>` element for the mount from `EnemyFighter` to `EnemyTruck`.

The camera attached to the tracking mount has a 4 Hz read out rate and the task has a duration of 5 seconds. The simulation will therefore produce 20 individual image files.

## Simulations and Results

### Fighter Tracking Scenario

The time-lapse animation below shows the frames from the simple camera staring at the fighter jet as the imaging platform flies across the scene.

Figure 1. Time-lapse of the camera tracking the fighter during the platform fly-by.

### Truck Tracking Scenario

If the `<targetname>` is changed to `EnemyTruck` then the camera follows the truck:

Figure 2. Time-lapse of the camera tracking the truck during the platform fly-by.

### In-the-Loop Video Encoding

This demo also includes an "in-the-loop" video encoding example using the inline processing option in the BasicPlatform plugin. This is captured in the `encode.jsim` setup, which uses the `encode.platform` file. This is essentially the same platfrom setup except that it includes a pair of post-processing tasks:

1. At the end of each capture (`schedule="capture_completed"`), each radiance image is converted to a PNG file using the DIRSIG image_tool utility.

2. At the end of the simulation (`schedule="simulation_completed"`), the PNG files are encoded into a MP4 video file using the FFmpeg utility (note, FFmpeg must be installed separately).

Post-processing tasks must be manually configured in the `.platform` XML file. The setup for this scenario is shown below:

                  <processing>
                    <task schedule="capture_completed">
                      <message>Scaling frame to PNG</message>
                      <program>image_tool</program>
                      <argument>convert</argument>
                      <argument>--minmax</argument>
                      <argument>--gamma=1.0</argument>
                      <argument>--output=$$IMG_BASENAME$$.png</argument>
                      <argument>$$IMG_BASENAME$$.img</argument>
                    </task>
                    <task schedule="collection_completed">
                      <message>Encoding frames into video</message>
                      <program>ffmpeg</program>
                      <argument>-y</argument>
                      <argument>-framerate</argument>
                      <argument>15</argument>
                      <argument>-i</argument>
                      <argument>demo-t0000-c%04d.png</argument>
                      <argument>video.mp4</argument>
                    </task>
                  </processing>