Clean up repository and add Python formatting
This commit is contained in:
+34
-24
@@ -1,14 +1,14 @@
|
||||
"""
|
||||
Automated Photogrammetry Capture Suite
|
||||
=====================================
|
||||
This module automates a 360-degree photography sequence using an Olympus OM-D
|
||||
EM-10 Mk III camera and an Arduino-controlled rotation stand.
|
||||
This module automates a 360-degree photography sequence using an Olympus OM-D
|
||||
EM-10 Mk III camera and an Arduino-controlled rotation stand.
|
||||
|
||||
The script synchronizes the two systems by:
|
||||
1. Initializing the camera's internal API to enter shutter mode.
|
||||
2. Establishing a persistent serial connection with the Arduino controller to
|
||||
2. Establishing a persistent serial connection with the Arduino controller to
|
||||
manage rotation speed and movement.
|
||||
3. Executing a sequenced loop of image capture, delay cycles, and incremental
|
||||
3. Executing a sequenced loop of image capture, delay cycles, and incremental
|
||||
rotation steps.
|
||||
|
||||
Hardware Requirements:
|
||||
@@ -18,8 +18,8 @@ Hardware Requirements:
|
||||
|
||||
Usage Note:
|
||||
----------
|
||||
Ensure the Camera's WiFi is active and the script 'CAMERA_IP' matches its
|
||||
assigned address on your network. Ensure the correct 'ARDUINO_PORT' is mapped
|
||||
Ensure the Camera's WiFi is active and the script 'CAMERA_IP' matches its
|
||||
assigned address on your network. Ensure the correct 'ARDUINO_PORT' is mapped
|
||||
to your local system (e.g., /dev/ttyUSB0 or COMx).
|
||||
"""
|
||||
|
||||
@@ -52,7 +52,9 @@ def initialize_camera():
|
||||
Configures the camera's hardware state for photography.
|
||||
"""
|
||||
print("[CAMERA] Switching to SHUTTER mode.")
|
||||
requests.get(f"http://{CAMERA_IP}/switch_cammode.cgi?mode=shutter", timeout=TIMEOUT)
|
||||
requests.get(
|
||||
f"http://{CAMERA_IP}/switch_cammode.cgi?mode=shutter", timeout=TIMEOUT
|
||||
)
|
||||
time.sleep(0.3)
|
||||
|
||||
|
||||
@@ -60,8 +62,8 @@ def initialize_stand(ser):
|
||||
"""
|
||||
Configures the Arduino-controlled rotation stand's parameters.
|
||||
|
||||
This is a blocking function. It sends commands to set the stand into
|
||||
MANUAL mode and defines the rotation speed (deg/sec). It will not return
|
||||
This is a blocking function. It sends commands to set the stand into
|
||||
MANUAL mode and defines the rotation speed (deg/sec). It will not return
|
||||
until the Arduino confirms these states have been successfully accepted.
|
||||
|
||||
Args:
|
||||
@@ -72,7 +74,9 @@ def initialize_stand(ser):
|
||||
time.sleep(0.3)
|
||||
await_completion(ser, "Mode: MANUAL")
|
||||
|
||||
print(f"[STAND] Setting rotation speed to {ROTATION_SPEED_DPS} degrees/second.")
|
||||
print(
|
||||
f"[STAND] Setting rotation speed to {ROTATION_SPEED_DPS} degrees/second."
|
||||
)
|
||||
ser.write(f"s{ROTATION_SPEED_DPS}\n".encode())
|
||||
time.sleep(0.3)
|
||||
await_completion(ser, f"Speed: {ROTATION_SPEED_DPS:.0f}")
|
||||
@@ -83,10 +87,15 @@ def take_photo():
|
||||
Triggers the camera's shutter and waits for capture completion.
|
||||
"""
|
||||
print("[CAMERA] Activating electronic shutter.")
|
||||
requests.get(f"http://{CAMERA_IP}/exec_shutter.cgi?type=1st2ndpush", timeout=TIMEOUT)
|
||||
requests.get(
|
||||
f"http://{CAMERA_IP}/exec_shutter.cgi?type=1st2ndpush", timeout=TIMEOUT
|
||||
)
|
||||
time.sleep(0.3)
|
||||
|
||||
requests.get(f"http://{CAMERA_IP}/exec_shutter.cgi?com=2nd1strelease", timeout=TIMEOUT)
|
||||
|
||||
requests.get(
|
||||
f"http://{CAMERA_IP}/exec_shutter.cgi?com=2nd1strelease",
|
||||
timeout=TIMEOUT,
|
||||
)
|
||||
time.sleep(0.3)
|
||||
|
||||
|
||||
@@ -94,8 +103,8 @@ def rotate_stand(ser):
|
||||
"""
|
||||
Commands the stand to perform a specific rotation.
|
||||
|
||||
This is a blocking function. It sends the degrees-to-rotate command
|
||||
and monitors the serial line until the Arduino confirms that the
|
||||
This is a blocking function. It sends the degrees-to-rotate command
|
||||
and monitors the serial line until the Arduino confirms that the
|
||||
movement has finished or is ready for the next instruction.
|
||||
|
||||
Args:
|
||||
@@ -109,7 +118,7 @@ def rotate_stand(ser):
|
||||
|
||||
def await_completion(ser, s):
|
||||
"""
|
||||
Blocks the execution of the script until a specific confirmation
|
||||
Blocks the execution of the script until a specific confirmation
|
||||
string is detected in the serial output from the Arduino.
|
||||
|
||||
Args:
|
||||
@@ -117,16 +126,16 @@ def await_completion(ser, s):
|
||||
s (str): The substring expected in the response to indicate completion.
|
||||
|
||||
Raises:
|
||||
SerialTimeoutError: If no data is received or if a
|
||||
SerialTimeoutError: If no data is received or if a
|
||||
non-matching line is found repeatedly.
|
||||
"""
|
||||
while True:
|
||||
line_bytes = ser.readline()
|
||||
line_str = line_bytes.decode('utf-8').strip()
|
||||
|
||||
line_str = line_bytes.decode("utf-8").strip()
|
||||
|
||||
if not line_str:
|
||||
raise SerialTimeoutError
|
||||
|
||||
|
||||
if s in line_str:
|
||||
break
|
||||
|
||||
@@ -136,7 +145,7 @@ def await_completion(ser, s):
|
||||
def main():
|
||||
with serial.Serial(ARDUINO_PORT, BAUD_RATE, timeout=TIMEOUT) as ser:
|
||||
try:
|
||||
time.sleep(2.0) # Buffer to account for Arduino startup
|
||||
time.sleep(2.0) # Buffer to account for Arduino startup
|
||||
|
||||
print("Flushing serial buffers.")
|
||||
ser.reset_input_buffer()
|
||||
@@ -144,13 +153,14 @@ def main():
|
||||
|
||||
initialize_stand(ser)
|
||||
initialize_camera()
|
||||
time.sleep(2.0) # Buffer to ensure the display is not moving
|
||||
time.sleep(2.0) # Buffer to ensure the display is not moving
|
||||
|
||||
current_angle = 0.0
|
||||
|
||||
while current_angle < TOTAL_TARGET_DEGREES:
|
||||
take_photo()
|
||||
time.sleep(PHOTO_TO_MOVE_DELAY) # Buffer to account for shutter speed
|
||||
# Buffer to account for shutter speed
|
||||
time.sleep(PHOTO_TO_MOVE_DELAY)
|
||||
rotate_stand(ser)
|
||||
|
||||
current_angle += ROTATION_STEP_SIZE
|
||||
@@ -173,4 +183,4 @@ if __name__ == "__main__":
|
||||
# Response: "Mode: MANUAL | State: WAIT | Steps Left: 0 | Speed: 45.00 deg/s | Wait: 8.00s"
|
||||
|
||||
# Send `a15` command
|
||||
# Response: "Waiting indefinitely for new command (MANUAL mode)."
|
||||
# Response: "Waiting indefinitely for new command (MANUAL mode)."
|
||||
|
||||
Reference in New Issue
Block a user