112 lines
2.3 KiB
Bash
112 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck disable=SC1091
|
|
source "${SCRIPT_DIR}/load-env.sh"
|
|
|
|
camera_device="${OMNI_CAMERA_DEVICE}"
|
|
camera_profile="${OMNI_CAMERA_PROFILE}"
|
|
camera_brightness="${OMNI_CAMERA_BRIGHTNESS}"
|
|
camera_custom_ctrl="${OMNI_CAMERA_CUSTOM_CTRL}"
|
|
camera_verify="${OMNI_CAMERA_VERIFY}"
|
|
|
|
is_truthy() {
|
|
case "${1:-0}" in
|
|
1|true|TRUE|yes|YES|on|ON)
|
|
return 0
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
require_v4l2_ctl() {
|
|
if command -v v4l2-ctl >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
|
|
echo "Missing required command: v4l2-ctl. Install v4l-utils on the robot side before starting b_side_omnid." >&2
|
|
exit 1
|
|
}
|
|
|
|
run_v4l2_ctl() {
|
|
v4l2-ctl -d "${camera_device}" "$@"
|
|
}
|
|
|
|
set_ctrl() {
|
|
local ctrl="$1"
|
|
|
|
echo "[camera-controls] set ${camera_device} ${ctrl}"
|
|
run_v4l2_ctl "--set-ctrl=${ctrl}"
|
|
}
|
|
|
|
verify_ctrl() {
|
|
local ctrl="$1"
|
|
|
|
echo "[camera-controls] verify ${camera_device} ${ctrl}"
|
|
run_v4l2_ctl "--get-ctrl=${ctrl}"
|
|
}
|
|
|
|
needs_v4l2_ctl=0
|
|
|
|
case "${camera_profile}" in
|
|
night)
|
|
needs_v4l2_ctl=1
|
|
;;
|
|
day)
|
|
if [[ -n "${camera_brightness}" ]]; then
|
|
needs_v4l2_ctl=1
|
|
fi
|
|
;;
|
|
custom)
|
|
if [[ -z "${camera_custom_ctrl}" ]]; then
|
|
echo "OMNI_CAMERA_CUSTOM_CTRL must be non-empty when OMNI_CAMERA_PROFILE=custom." >&2
|
|
exit 1
|
|
fi
|
|
needs_v4l2_ctl=1
|
|
;;
|
|
*)
|
|
echo "Unsupported OMNI_CAMERA_PROFILE: ${camera_profile}. Expected one of: night, day, custom." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
if is_truthy "${camera_verify}"; then
|
|
needs_v4l2_ctl=1
|
|
fi
|
|
|
|
if [[ "${needs_v4l2_ctl}" == "0" ]]; then
|
|
echo "[camera-controls] profile=${camera_profile}; no camera controls requested"
|
|
exit 0
|
|
fi
|
|
|
|
require_v4l2_ctl
|
|
|
|
case "${camera_profile}" in
|
|
night)
|
|
set_ctrl "auto_exposure=1"
|
|
set_ctrl "exposure_time_absolute=800"
|
|
set_ctrl "gain=64"
|
|
if [[ -n "${camera_brightness}" ]]; then
|
|
set_ctrl "brightness=${camera_brightness}"
|
|
fi
|
|
;;
|
|
day)
|
|
if [[ -n "${camera_brightness}" ]]; then
|
|
set_ctrl "brightness=${camera_brightness}"
|
|
fi
|
|
;;
|
|
custom)
|
|
set_ctrl "${camera_custom_ctrl}"
|
|
;;
|
|
esac
|
|
|
|
if is_truthy "${camera_verify}"; then
|
|
verify_ctrl "auto_exposure"
|
|
verify_ctrl "exposure_time_absolute"
|
|
verify_ctrl "gain"
|
|
verify_ctrl "brightness"
|
|
fi
|