Skip to content

Engineering/lab_test_optim.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
#   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 lab_test_optim {
  arguments {
    MissionTimeout = 15 minute
      """
      Backseat will stay on for this duration, independent of Optim state
      """

    RecordTime = 1 minute
      """
      How long to record after startup sequence (hopefully) turns on Optim camera
      """

    BackseatWait = 30 second
      """
      How long to wait for the backseat to power up before attempting to power the Optim
      """

    UseMission = true
      """
      If true, tries to go through the application and use components/behaviors for commands.
      Set InitialSampleTime to change delays. If false, backdoors app. Use SleepCycles to change delays.
      Optim must be on C3.
      """

    UseHardcode = false
      """
      If true, backdoors app with a powercycle and a hardcoded sleep 1. Try the two other modes first?
      Optim must be on C3.
      """

    InitialSampleTime = 1 second
      """
      PowerOnly sample time for initial record. Will go back to continuous after startup.
      """

    SleepCycles = 3 count
      """
      How many vehicle computation cycles to wait before commanding the Optim off on initial record
      """

    LightMode = 2 count
      """
      Mode for Multiray lights. 0 is off, 1 is red, 2 is white
      """

    BrightnessWhite = 100 none_int
      """
      White Multiray LED brightness, 0-100
      """

    BrightnessRed = 100 none_int
      """
      Red Multiray LED brightness, 0-100
      """
  }

  output {
    CyclesWaited = 0 count

    RecordingEnabled = false

    LightsEnabled = false
  }

  timeout duration=MissionTimeout

  insert Insert/BackseatDriver.tl
  assign in parallel BackseatDriver:EnableBackseat = true

  readData strategy="MinError" {
    while ( RecordingEnabled )

    Sensor:PowerOnly.sampleLoad1
  }

  readData strategy="MinError" {
    while ( LightsEnabled )

    Sensor:MultiRay.lightModeLog
  }

  aggregate Startup {
    run in sequence

    syslog important "Waiting " + BackseatWait~s + " for backseat to start up..."

    behavior Guidance:Wait {
      run in sequence

      set duration = BackseatWait
    }

    aggregate UseMission {
      run in sequence

      break if (
        not UseMission
        or UseHardcode
      )

      assign in parallel Sensor:PowerOnly.sampleTime1 = InitialSampleTime

      assign in sequence RecordingEnabled = true

      syslog important "Disabling Optim recording after " + InitialSampleTime~s
      assign in sequence RecordingEnabled = false

      behavior Guidance:Wait {
        run in sequence

        set duration = InitialSampleTime
      }

      assign in sequence RecordingEnabled = true
      syslog important "Powering up Optim to try to tide over gap to handoff..."
    }

    aggregate UseBackdoor {
      run in sequence

      break if (
        UseMission
        or UseHardcode
      )

      behavior Guidance:Execute {
        run in sequence

        set command = "! echo 1 > /dev/loadC3"
      }

      syslog important "Optim power on. Spinning for " + SleepCycles~count + " cycles."

      aggregate WaitForStop {
        run in sequence repeat=SleepCycles

        assign in sequence CyclesWaited = CyclesWaited + 1 count
      }

      behavior Guidance:Execute {
        run in sequence

        set command = "! echo 0 > /dev/loadC3"
      }

      syslog important "Optim power off. Spinning again."

      aggregate WaitForStart {
        run in sequence repeat=SleepCycles

        assign in sequence CyclesWaited = CyclesWaited + 1 count
      }

      behavior Guidance:Execute {
        run in sequence

        set command = "! echo 1 > /dev/loadC3"
      }

      syslog important "Optim power on. Handing off to mission."
    }

    aggregate UseHardcode {
      run in sequence

      break if ( not UseHardcode )

      behavior Guidance:Execute {
        run in sequence

        set command = "! echo 1 > /dev/loadC3; sleep 1; echo 0 > /dev/loadC3; sleep 1; echo 1 > dev/loadC3"
      }

      syslog important "Hardcoded Optim command sent. Good luck."
    }
  }

  aggregate Run {
    run in sequence

    syslog important "Trying to run Optim and Multiray forreal"

    assign in sequence RecordingEnabled = true
    assign in sequence LightsEnabled = true
    assign in sequence Sensor:MultiRay.lightModeCommand = LightMode

    aggregate setRed {
      run in sequence

      break if ( LightMode != 1 count )

      assign in sequence Sensor:MultiRay.brightnessRed = BrightnessRed
      syslog info "Setting multiray red brightness to" + BrightnessRed~count
    }

    aggregate setWhite {
      run in sequence

      break if ( LightMode != 2 count )

      assign in sequence Sensor:MultiRay.brightnessWhite = BrightnessWhite
      syslog info "Setting muliray white brightness to" + BrightnessWhite~count
    }

    syslog important "Recording for " + RecordTime~min

    behavior Guidance:Wait {
      run in sequence

      set duration = RecordTime
    }
  }

  behavior Guidance:Wait {
    run in sequence

    set duration = MissionTimeout
  }
}