Skip to content

Insert/LineCapture.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
#   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.

aggregate LineCapture {
  """
  Home to transponder sequence: (0) Undock (1) Midcourse guidance: nav to
  dock WP while querying transponder, execute search pattern if WP is
  reached with no response from x-ponder. (2) Terminal guidance: home to
  target using DUSBL tracking data, reset nav, and dock
  """

  arguments {
    # Dock

    DockLat = Dock:Dock.lat
      """
      Latitude of docking station waypoint (defaults to
      Config/workSite.beaconLat).
      """

    DockLon = Dock:Dock.lon
      """
      Longitude of docking station waypoint (defaults to
      Config/workSite.beaconLon).
      """

    # Undock arguments

    DetachTimeout = 30 minute
      """
      Maximum time duration for the vehicle to detach form the dock. The
      vehicle will switch over to midcourse guidance after the timeout is
      expired.
      """

    # Midcourse guidance arguments

    MidcourseDepth = Dock:LineCapture.midcourseDepth
      """
      Desired vehicle depth when navigating to dock WP (during midcourse
      phase).
      """

    MidcourseSpeed = Dock:LineCapture.midcourseSpeed
      """
      Thruster speed during Midcourse guidance.
      """

    MidcourseTimeout = Dock:LineCapture.midcourseTimeout
      """
      Maximum time duration for running in midcourse guidance mode.
      """

    # Terminal guidance arguments

    TerminalRange = Dock:LineCapture.terminalRange
      """
      Range at which the vehicle should switch from navigating to the dock wp
      and start homing to the target using DUSBL tracking data. Max is ??
      meters due to DUSBL ???.
      """

    AcousticTimeout = Dock:LineCapture.acousticTimeout
      """
      Maximum time duration allowed between pings during terminal guidance. If
      expired, the vehicle will regress to Midcourse guidance.
      """

    losRateIIRFilterDecay = 0.0 none
      """
      LineCapture single-pole IIR filter decay value.
      Filters line-of-sight (LOS) angle rotation rate.
      The Decay value should be btween 0 to 1, set to 0 disable filtering.
      """

    # Search pattern arguments

    SearchTimeout = Dock:LineCapture.searchTimeout
      """
      Maximum time duration for running in search guidance mode.
      """

    CircleRadius = Dock:LineCapture.searchCircleRadius
      """
      Radius of circle around the dock waypoint.
      """

    CircleMaxError = 1 meter
      """
      If this distance away from the circle, drive straight towards (or away
      from the center). Otherwise, try to reduce distance from the ideal
      circle.
      """

    CircleTurnToPort = false
      """
      If true, vehicle turns to the left around the center point. If false,
      vehicle turns to the right.
      """

    # General settings

    DepthDeadband = 0.01 meter
      """
      Vertical drift from the specified depth that's allowed during depth
      keeping.
      """

    RudderDeadband = 0.001 arcdeg
      """
      Degree of rounding in rudder command output values to use during
      Terminal Homing.
      """

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

    MaxDepth = 8 meter
      """
      Maximum depth for the entire mission.
      """

    MinOffshore = 1 meter
      """
      Minimum offshore distance for the entire mission.
      """

    DockingAltitude = NaN meter
      """
      Docking altitude. Ignored when NaN and used over depth when a valid altitude is set.
      """

    InvalidAltitudeTimeout = NaN minute
      """
      The mission will use the last good depth command if no valid altitude readings are received within
      this specified time duration.
      """

    AltitudeDepthLimit = NaN meter
      """
      Vehicle will not be commanded deeper than this regardless of altitude command.
      """

    AltitudeIIRFilterDecay = 0.0 none
      """
      AltitudeServo single-pole IIR filter decay value.
      Low-pass filters the AltitudeServo depth command.
      The Decay value should be btween 0 to 1, set to 0 disable filtering.
      """

    # Mission Variables (don't change!)

    ElapsedRange = 0 minute
      """
      Mission variable (don't change). Time since last range to acoustic contact.
      """

    Range = NaN meter
      """
      Mission variable (don't change). Most recent range to acoustic contact.
      """
  }

  output {
    # Mission Variables (don't change!)

    DoneTimeout = -1 count
      """
      Mission variable (don't change). The mission will run in this mode when
      the insert timed out.
      """

    Done = 0 count
      """
      Mission variable (don't change). The mission will run in this mode when
      the insert is done (docked).
      """

    DetachFromDock = 1 count
      """
      Mission variable (don't change). The mission will run in this mode to
      drift away from the dock after is unlatched.
      """

    Midcourse = 2 count
      """
      Mission variable (don't change). The mission will run in this mode when
      approaching the dock under Midcourse guidance.
      """

    Terminal = 3 count
      """
      Mission variable (don't change). The mission will run in this mode when
      approaching the dock under Terminal guidance.
      """

    GuidanceMode = DetachFromDock
      """
      Mission variable (don't change). The mission sets this variable to
      switch between guidance modes.
      """

    DockingDepth = 1 meter
      """
      Mission variable (don't change). Actual docking depth.
      """
  }

  run when ( called )

  assign in sequence GuidanceMode = DetachFromDock

  assign in sequence DockingDepth = Dock:Dock.depth + Dock:Docked.dockingDepthOffset

  # Safety nets

  insert Insert/StandardEnvelopes.tl

  assign in sequence StandardEnvelopes:MinAltitude = MinAltitude

  assign in sequence StandardEnvelopes:MaxDepth = MaxDepth

  assign in sequence StandardEnvelopes:MinOffshore = MinOffshore

  # Update internal range arguments

  assign in parallel ElapsedRange = elapsed ( Universal:acoustic_contact_range )

  assign in parallel Range = Universal:acoustic_contact_range

  # Set default mass and buoyancy positions

  aggregate HoldMassAndBuoyancy {
    """
    Maintain VB and mass at neutral/default position while underway
    (during Midcourse and Terminal guidance).
    """

    run while (
      abs ( Control:SpeedControl.speedCmd ) > 0 meter_per_second
    )

    assign in parallel Control:VerticalControl.depthDeadband = DepthDeadband

    behavior Guidance:Mass {
      run in parallel

      set position = Control:VerticalControl.massDefault
    }

    behavior Guidance:Buoyancy {
      run in parallel

      set position = Control:VerticalControl.buoyancyNeutral
    }
  }

  aggregate HomingSequence {
    """
    This is the insert's guidance section, which arbitrates between 3
    modes: 1) DetachFromDock: unlatch and drift away from the dock. 2)
    Midcourse: navigate toward the dock waypoint, and enter search
    pattern if waypoint has been reached with no range data. 2)
    Terminal: home toward the dock using DUSBL tracking data.
    """

    run in sequence

    break if ( GuidanceMode <= Done )

    aggregate DetachFromDock {
      """
      Unlatch and drift away from the dock.
      """

      run while ( GuidanceMode == DetachFromDock )

      aggregate guide {
        run in sequence

        behavior Dock:Undock {
          run in sequence

          timeout duration=DetachTimeout {
            syslog important "Timed out while trying to detach from dock at current depth of "
                 + Universal:depth~meter + "."
          }
        }

        syslog info "Transitioning to midcourse guidance."

        assign in sequence GuidanceMode = Midcourse
      }
    }

    aggregate MidcourseGuidance {
      """
      (1) Navigate toward the dock waypoint while querying the dock
      transponder. (2) Continue until within *TerminalRange*, then
      move on to terminal guidance. (3) Enter search pattern if
      waypoint has been reached with no range data.
      """

      run while ( GuidanceMode == Midcourse )

      aggregate guide {
        run in sequence

        syslog info "Navigating to dock waypoint (" + DockLat~degree + "," + DockLon~degree + ")"

        aggregate CheckRange {
          run when (
            Range < TerminalRange
            and ( ElapsedRange <= AcousticTimeout )
          )

          syslog info "Transitioning to terminal guidance at range" + Range~meter

          assign in sequence GuidanceMode = Terminal
        }

        behavior Guidance:SetSpeed {
          run in parallel

          set speed = MidcourseSpeed
        }

        behavior Guidance:Pitch {
          run in parallel

          set depth = MidcourseDepth
        }

        behavior Guidance:Waypoint {
          run in sequence

          timeout duration=MidcourseTimeout {
            syslog important "Terminating homing sequence: timed out while navigating to the dock waypoint."

            assign in sequence GuidanceMode = DoneTimeout
          }

          set latitude = DockLat
          set longitude = DockLon
        }

        syslog info "Executing search pattern."

        aggregate SearchPattern {
          run in sequence

          timeout duration=SearchTimeout {
            syslog important "Timed out while executing search pattern around dock waypoint."
          }

          behavior Guidance:Circle {
            run in parallel

            set latitude = DockLat
            set longitude = DockLon
            set radius = CircleRadius
            set maxError = CircleMaxError
            set turnToPort = CircleTurnToPort
          }

          behavior Guidance:Wait {
            run in sequence

            set duration = SearchTimeout
          }
        }

        syslog important "Homing sequence timed out prior to docking."

        assign in sequence GuidanceMode = DoneTimeout
      }
    }

    aggregate TerminalGuidance {
      """
      Home toward the target using USBL tracking data.
      """

      run while ( GuidanceMode == Terminal )

      aggregate guide {
        run in sequence

        syslog info "Terminal guidance."

        aggregate CheckRange {
          run when (
            Range >= TerminalRange
            or ( ElapsedRange > AcousticTimeout )
          )

          syslog important "Transitioning to midcourse guidance. Received last range of"
               + Range~meter + ElapsedRange~minute + "ago."

          assign in sequence GuidanceMode = Midcourse
        }

        aggregate altitudeControl {
          run while ( not ( isNaN ( DockingAltitude ) ) )

          behavior Guidance:AltitudeServo {
            run in parallel

            set targetAltitude = DockingAltitude
            set initialDepth = DockingDepth
            set invalidAltitudeTimeout = InvalidAltitudeTimeout
            set maxDepthLimit = AltitudeDepthLimit
            set iirFilterDecay = AltitudeIIRFilterDecay
          }
        }

        aggregate depthControl {
          run while ( isNaN ( DockingAltitude ) )

          behavior Guidance:Pitch {
            run in parallel

            set depth = DockingDepth
          }
        }

        assign in parallel Servo:RudderServo.deviationAngle = RudderDeadband

        assign in parallel Control:HorizontalControl.rudDeadband = RudderDeadband

        behavior Dock:LineCapture {
          run in sequence

          set iirFilterDecay = losRateIIRFilterDecay
        }

        syslog info "Docked. Homing sequence complete."

        assign in sequence GuidanceMode = Done
      }
    }
  }

  behavior Guidance:Wait {
    run in sequence

    set duration = 3 second
  }

  syslog info "GuidanceMode" + GuidanceMode~count
}