Skip to content

enable sending camera triggers from board#127

Merged
beniroquai merged 1 commit intomasterfrom
mergemaster
Jan 10, 2026
Merged

enable sending camera triggers from board#127
beniroquai merged 1 commit intomasterfrom
mergemaster

Conversation

@beniroquai
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings January 10, 2026 20:34
@beniroquai beniroquai merged commit bdc3486 into master Jan 10, 2026
2 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds camera trigger functionality to enable the board to send camera trigger signals for software-triggered image acquisition during stage scanning, and extends stage scanning to support Z-axis positioning.

Changes:

  • New CameraTrigger class that handles incoming camera trigger signals from ESP32 firmware ({"cam":1})
  • Extended start_stage_scanning method with Z-axis parameters (zstart, zstep, nz)
  • Updated documentation to reflect Z-axis support in coordinate-based scanning

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
uc2rest/camera_trigger.py New module implementing camera trigger callback handling with support for registering multiple callbacks and tracking trigger statistics
uc2rest/motor.py Added Z-axis parameters to stage scanning methods and updated example documentation to include Z coordinates
uc2rest/UC2Client.py Integrated CameraTrigger module into UC2Client initialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +55 to +57
# Register callback for camera trigger on serial loop
if hasattr(self._parent, "serial"):
self._parent.serial.register_callback(self._callback_camera_trigger, pattern="cam")
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CameraTrigger is initialized unconditionally, but the serial callback registration (line 57) only works when a serial connection is used. When using WiFi mode (host is not None), the parent will not have a 'serial' attribute, so the callback won't be registered. However, camera triggers from the board may not work in WiFi mode anyway. Consider documenting this limitation in the class docstring or adding a log message when the callback cannot be registered.

Copilot uses AI. Check for mistakes.
Comment on lines +95 to +104
self._parent.logger.debug(f"Camera trigger received: {trigger_info}")
else:
# Handle extended trigger data
trigger_info = {
"trigger": cam_data.get("trigger", 1),
"frame_id": cam_data.get("frame_id", self._trigger_count),
"illumination": cam_data.get("illumination", -1),
"timestamp": self._last_trigger_time
}
self._parent.logger.debug(f"Camera trigger with data received: {trigger_info}")
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code accesses self._parent.logger without checking if parent is None or if it has a logger attribute. While this is likely safe given the UC2Client initialization, consider adding a defensive check or using hasattr similar to line 56 for consistency. Alternatively, you could check for a DEBUG flag before logging, as is done in motor.py (line 512).

Copilot uses AI. Check for mistakes.
def start_stage_scanning(self, xstart=0, xstep=1000, nx=20, ystart=0, ystep=1000, ny=10, tsettle=5, tExposure=50, illumination=(0,0,0,0), led=0, speed=20000, acceleration=None):
# {"task": "/motor_act", "stagescan": {"xStart": 0, "yStart": 0, "xStep": 500, "yStep": 500, "nX": 10, "nY": 10, "tPre": 50, "tPost": 50, "illumination": [0, 1, 0, 0], "led": 255}}
def start_stage_scanning(self, xstart=0, xstep=1000, nx=20, ystart=0, ystep=1000, ny=10, zstart=0, zstep=1000, nz=10, tsettle=5, tExposure=50, illumination=(0,0,0,0), led=0, speed=20000, acceleration=None):
# {"task": "/motor_act", "stagescan": {"xStart": 0, "yStart": 0, "zStart": 0, "xStep": 500, "yStep": 500, "zStep": 500, "nX": 10, "nY": 10, "nZ": 10, "tPre": 50, "tPost": 50, "illumination": [0, 1, 0, 0], "led": 255}}
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation uses tabs instead of spaces, which is inconsistent with Python's PEP 8 style guide and likely the rest of the codebase. This could cause issues with mixed indentation. Please replace the tabs with spaces (typically 4 or 8 spaces depending on the project's convention).

Suggested change
# {"task": "/motor_act", "stagescan": {"xStart": 0, "yStart": 0, "zStart": 0, "xStep": 500, "yStep": 500, "zStep": 500, "nX": 10, "nY": 10, "nZ": 10, "tPre": 50, "tPost": 50, "illumination": [0, 1, 0, 0], "led": 255}}
# {"task": "/motor_act", "stagescan": {"xStart": 0, "yStart": 0, "zStart": 0, "xStep": 500, "yStep": 500, "zStep": 500, "nX": 10, "nY": 10, "nZ": 10, "tPre": 50, "tPost": 50, "illumination": [0, 1, 0, 0], "led": 255}}

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +10
import numpy as np
import time
import json
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imports 'numpy' and 'json' are not used anywhere in this file. Consider removing these unused imports to keep the code clean and reduce unnecessary dependencies.

Suggested change
import numpy as np
import time
import json
import time

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant