Skip to content

Commit

Permalink
Add camera image brightness test
Browse files Browse the repository at this point in the history
With this, we can hopefully auto-detect broken light panels.
  • Loading branch information
luator committed Sep 19, 2023
1 parent e4a4462 commit 7acb283
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
[plotext](https://github.com/piccolomo/plotext) to show the plot directly in
the terminal or save as file to /tmp if plotext is not available.
- Check camera sharpness in `trifinger_post_submission.py`. This should alert us early,
if a lense comes loose.
if a lens comes loose.
- Check camera brightness in `trifinger_post_submission.py` to auto-detect
broken light panels.

### Changed
- plot_post_submission_log.py now plots multiple log files side by side instead of
Expand Down
56 changes: 56 additions & 0 deletions scripts/trifingerpro_post_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,57 @@ def record_camera_observations(
return observation_buffer


def check_camera_brightness(
observations: typing.Sequence[tricamera.TriCameraObjectObservation],
log: logging.Logger,
) -> bool:
"""Check if the camera images match the expected brightness.
If they are too dark, it might mean that one of the light panels is broken.
Args:
observations: Sequence of camera observations.
log: Logger instance to log results.
Returns:
True if test is successful, False if there is any issue.
"""
# On robots with all four panels on, brightness mean is typically in the range of
# 90-95. On a robot that has 90 with all on, turning one panel off reduced it to
# 75. Set the threshold based on this information. If it results in frequent false
# positives, we can lower it a bit.
BRIGHTNESS_MEAN_TRHESHOLD = 87.0

all_cameras_means = []
for obs in observations:
# NOTE for brightness estimation, we don't need to debayer, we can just
# use the raw data
image_means = [np.mean(camera.image) for camera in obs.cameras]
all_cameras_means.append(np.mean(image_means))

total_mean = np.mean(all_cameras_means)

if total_mean >= BRIGHTNESS_MEAN_TRHESHOLD:
log.info(
SM(
"Image brightness is okay",
mean_brightness=total_mean,
limit=BRIGHTNESS_MEAN_TRHESHOLD,
)
)
else:
log.error(
SM(
"Image brightness is too low. Lighting should be checked.",
mean_brightness=total_mean,
limit=BRIGHTNESS_MEAN_TRHESHOLD,
)
)
return False

return True


def check_camera_sharpness(
observations: typing.Sequence[tricamera.TriCameraObjectObservation],
log: logging.Logger,
Expand Down Expand Up @@ -622,6 +673,11 @@ def main():
args.object, num_observations=30
)

if not check_camera_brightness(
camera_observations, logging.getLogger("camera_brightness")
):
sys.exit(2)

if not check_camera_sharpness(
camera_observations, logging.getLogger("camera_sharpness")
):
Expand Down

0 comments on commit 7acb283

Please sign in to comment.