Skip to content

Engineering/tail_acoustic_contact.tl

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#   Copyright (c) 2024 MBARI
#   MBARI Proprietary Information. Confidential. All Rights Reserved
#   Unauthorized copying or distribution of this file via any medium is strictly
#   prohibited.
#
#   WARNING - This file contains information whose export is restricted by the
#   Export Administration Act of 1979 (Title 50, U.S.C., App. 2401 et seq.), as
#   amended. Violations of these export laws are subject to severe civil and/or
#   criminal penalties.

mission follow_that_car {
  """
  Home to target when outside TailDistance, otherwise drift.
  Stay close... but not too close. U+1F575
  """

  arguments {
    MissionTimeout = 2 hour
      """
      Maximum length of mission
      """

    NeedCommsTime = 60 minute
      """
      How often to surface for communications
      """

    ContactLabel = 9 count
      """
      The acoustic address of the asset to be tracked
      """

    ContactDepth = 2 meter
      """
      The depth of the asset to be tracked
      """

    TailDistance = 10 meter
      """
      How close to get before stopping. DAT.ignoreElevationAngle will
      be set by the mission, so this distance is horizontal range, not slant
      range.
      """

    TailDeadband = 10 meter
      """
      How much additional distance to allow from contact before resuming chase
      after waiting
      """

    TrackingUpdatePeriod = 5 second
      """
      How long to wait between acoustic queries
      """

    NumberOfPings = 1 count
      """
      Number of pings requested each time
      """

    Speed = 1 meter_per_second
      """
      Vehicle speed during driving intervals
      """

    Depth = 50 meter
      """
      Vehicle depth
      """

    WaitDepthDeadband = 10 meter
      """
      Depth deviation to allow before using buoyancy to correct
      during wait
      """

    MinAltitude = 5 meter
      """
      Minimum height above sea floor for the entire mission
      """

    MaxDepth = 205 meter
      """
      Maximum depth of the enter mission
      """

    MinOffshore = 2 kilometer
      """
      Minimum offshore distance for the entire mission
      """

    ContactLatitude = 36.797 degree
      """
      The latitude of the center of the circle. Fill this in to specify a
      start position, it will be overwritten once the vehicle receives an
      acoustic signal from the contact.
      """

    ContactLongitude = -121.847 degree
      """
      The longitude of the center of the circle. Fill this in to specify a
      start position, it will be overwritten once the vehicle receives an
      acoustic signal from the contact.
      """
  }

  output {
    # Internal variables, do not change
    LocationUpdated = false
      """
      Mission variable (don't change). Flag to indicate contact lat/lon was updated
      """

    Chasing = false
      """
      Mission variable (don't change). Flag to indicate whether in chase or wait mode
      """

    DistanceAllowed = TailDistance
      """
      Mission variable (don't change). Allowable distance from contact before chasing
      """
  }

  timeout duration=MissionTimeout

  insert Insert/Science.tl

  insert Insert/StandardEnvelopes.tl

  assign in sequence StandardEnvelopes:MinAltitude = MinAltitude

  assign in sequence StandardEnvelopes:MaxDepth = MaxDepth

  assign in sequence StandardEnvelopes:MinOffshore = MinOffshore

  insert id="NeedComms" Insert/NeedComms.tl

  assign in sequence NeedComms:DiveInterval = NeedCommsTime

  assign in sequence NeedComms:WaitForPitchUp = 0 minute

  insert Insert/BackseatDriver.tl

  insert Insert/PowerOnly.tl

  # Add track acoustic contact directive high in the stack.
  behavior Estimation:TrackAcousticContact {
    run in parallel

    set contactLabelSetting = ContactLabel
    set contactDepthSetting = ContactDepth
    set numberOfSamplesSetting = NumberOfPings
    set updatePeriodSetting = TrackingUpdatePeriod
  }

  # Use horizontal range, not slant range
  assign in parallel Sensor:DAT.ignoreElevationAngle = true

  aggregate UpdateLocation {
    run when (
      elapsed ( Estimation:TrackAcousticContact.range_to_contact ) < ( elapsed ( LocationUpdated ) )
    )

    break if (
      isNaN ( Estimation:TrackAcousticContact.contact_latitude )
      or isNaN ( Estimation:TrackAcousticContact.contact_longitude )
    )

    assign in sequence ContactLatitude = Estimation:TrackAcousticContact.contact_latitude

    assign in sequence ContactLongitude = Estimation:TrackAcousticContact.contact_longitude

    assign in sequence LocationUpdated = true

    syslog debug "Updated target location to " + ContactLatitude~degree + ", "
         + ContactLongitude~degree
  }

  call id="StartingMission" refId="NeedComms"

  aggregate Tail {
    run in sequence

    aggregate Chase {
      """
      Head towards the target
      """

      run while (
        # Universal range, directly from the DAT, will always be slant range
        # If we're ignoring elevation, TrackAcousticContact range will be horizontal range
        # which is what we want.
        # Yeah, ignoreElevationAngle is a DAT setting, shhhhhhhh.
        Estimation:TrackAcousticContact.range_to_contact > DistanceAllowed
        or isNaN ( Estimation:TrackAcousticContact.range_to_contact )
      )

      aggregate SetChase {
        run in sequence

        break if ( Chasing )

        assign in sequence DistanceAllowed = TailDistance

        syslog important "Target distance " + Estimation:TrackAcousticContact.range_to_contact~m
             + " exceeded max " + DistanceAllowed~m + ", giving chase."
        assign in sequence Chasing = true
      }

      behavior Guidance:Mass {
        run in parallel

        set position = Control:VerticalControl.massDefault
      }

      behavior Guidance:Buoyancy {
        run in parallel

        set position = Control:VerticalControl.buoyancyNeutral
      }

      behavior Guidance:SetSpeed {
        run in parallel

        set speed = Speed
      }

      behavior Guidance:Pitch {
        run in parallel

        set depth = Depth
      }

      aggregate Wpt {
        run in sequence

        behavior Guidance:Waypoint {
          run in sequence

          set latitude = ContactLatitude
          set longitude = ContactLongitude
        }
      }
    }

    aggregate Wait {
      """
      Drift until target is out of range
      """

      run while (
        # Horizontal range (if set to compute it) here too
        Estimation:TrackAcousticContact.range_to_contact <= DistanceAllowed
      )

      aggregate SetWait {
        run in sequence

        break if ( not Chasing )

        assign in sequence DistanceAllowed = TailDistance + TailDeadband

        syslog important "Caught up to target at distance "
             + Estimation:TrackAcousticContact.range_to_contact~m + " waiting until target is "
             + DistanceAllowed~m + "away to resume pursuit."
        assign in sequence Chasing = false
      }

      assign in parallel Control:VerticalControl.depthDeadband = WaitDepthDeadband

      behavior Guidance:SetSpeed {
        run in parallel

        set speed = 0 meter_per_second
      }

      behavior Guidance:Pitch {
        run in parallel

        set depth = Depth
        set pitch = 0 degree
        set elevatorAngle = 0 degree
      }

      behavior Guidance:Point {
        run in parallel

        set rudderAngle = 0 degree
      }

      behavior Guidance:Wait {
        run in sequence

        set duration = MissionTimeout
      }
    }
  }
}