Skip to content

Commit

Permalink
add boot_lockout state to deal with accessing the camera to fast afte…
Browse files Browse the repository at this point in the history
…r boot
  • Loading branch information
ryanpdx committed May 16, 2024
1 parent 53478b1 commit 3dad56d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
20 changes: 17 additions & 3 deletions oresat_cfc/services/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from enum import IntEnum
from time import time
from time import monotonic, time

import canopen
import cv2
Expand All @@ -27,6 +27,8 @@ class CameraState(IntEnum):
"""Camera is on, but no doing anything"""
CAPTURE = 0x3
"""Camera is capturing image and saving them to freac cache"""
BOOT_LOCKOUT = 0x4
"""Camera is locked out until system is done booting and PRUs are available."""
ERROR = 0xFF
"""Error with camera hardware"""

Expand All @@ -40,6 +42,7 @@ class CameraState(IntEnum):
CameraState.CAPTURE,
CameraState.ERROR,
],
CameraState.BOOT_LOCKOUT: [CameraState.OFF],
CameraState.ERROR: [CameraState.OFF, CameraState.ERROR],
}
"""Valid state transistions."""
Expand All @@ -48,10 +51,12 @@ class CameraState(IntEnum):
class CameraService(Service):
"""Service for camera and capture state machine"""

_BOOT_LOCKOUT_S = 70

def __init__(self, pirt1280: Pirt1280):
super().__init__()

self._state = CameraState.OFF
self._state = CameraState.BOOT_LOCKOUT
self._next_state_internal = -1
self._next_state_user = -1

Expand Down Expand Up @@ -121,14 +126,23 @@ def _state_machine_transition(self, new_state: [CameraState, int]):
self._state = new_state

def on_loop(self):

if self._state == CameraState.BOOT_LOCKOUT and monotonic() > self._BOOT_LOCKOUT_S:
self._next_state_internal = CameraState.OFF.value

if self._next_state_internal != -1:
self._state_machine_transition(self._next_state_internal)
self._next_state_internal = -1
elif self._next_state_user != -1:
self._state_machine_transition(self._next_state_user)
self._next_state_user = -1

if self._state in [CameraState.OFF, CameraState.STANDBY, CameraState.ERROR]:
if self._state in [
CameraState.OFF,
CameraState.STANDBY,
CameraState.ERROR,
CameraState.BOOT_LOCKOUT,
]:
self.sleep(0.1)
elif self._state == CameraState.CAPTURE:
self._count += 1
Expand Down
21 changes: 16 additions & 5 deletions oresat_cfc/templates/cfc.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
<!--the "//:0" is a basically the way to make any empty img-->
<img id="image" src="//:0" alt="camera"/>
<br/>
<button onclick="downloadRawImage()">Download Raw Image</button>
<button onclick="downloadDisplayImage()">Download Display Image</button>
<button id="downloadRawImageButton" onclick="downloadRawImage()" disabled>Download Raw Image</button>
<button id="downloadDisplayImageButton" onclick="downloadDisplayImage()" disabled>Download Display Image</button>
</div>
<div id="gridColumn">
<h4>State Machine</h4>
<table>
<tr>
<td>Status</td>
<td><span id="cfcState">OFF</span></td>
<td><span id="cfcState">BOOT_LOCKOUT</span></td>
</tr>
<tr>
<td>Capture Delay</td>
Expand Down Expand Up @@ -91,7 +91,7 @@ <h4>TEC (Thermoelectric Cooler) Controller</h4>
</table>
<br />
<div>
<button id="changeSettings">Change Settings</button>
<button id="changeSettingsButton" disabled>Change Settings</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -149,7 +149,7 @@ <h4>TEC (Thermoelectric Cooler) Controller</h4>
</dialog>
<script>
let lastDisplayImage;
const settingsButton = document.getElementById("changeSettings");
const settingsButton = document.getElementById("changeSettingsButton");
const cancelButton = document.getElementById("cancel");
const submitButton = document.getElementById("submit");
const dialog = document.getElementById("favDialog");
Expand Down Expand Up @@ -265,6 +265,7 @@ <h4>TEC (Thermoelectric Cooler) Controller</h4>
0x01: "OFF",
0x02: "STANDBY",
0x03: "CAPTURE",
0x04: "BOOT_LOCKOUT",
0xFF: "ERROR",
};
let lastCapture = 0;
Expand All @@ -288,6 +289,16 @@ <h4>TEC (Thermoelectric Cooler) Controller</h4>
document.getElementById("saveCaptures").innerHTML = "FALSE";
}

if (state === "BOOT_LOCKOUT") {
document.getElementById("changeSettingsButton").disabled = true;
document.getElementById("downloadRawImageButton").disabled = true;
document.getElementById("downloadDisplayImageButton").disabled = true;
} else {
document.getElementById("changeSettingsButton").disabled = false;
document.getElementById("downloadRawImageButton").disabled = false;
document.getElementById("downloadDisplayImageButton").disabled = false;
}

// get last image capture for display
obj = await readValue("camera", "last_capture_time");
if (state != "OFF" && obj.value != lastCapture) {
Expand Down

0 comments on commit 3dad56d

Please sign in to comment.