traffic_sign_node 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. # Keep the NPU runtime isolated from the system Python used by ROS Noetic.
  3. set -uo pipefail
  4. script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
  5. camera_device="/dev/video0"
  6. child_pid=""
  7. # This is deliberately in the outer process: rknnlite/rospy shutdown may not
  8. # run Python callbacks after roslaunch sends SIGINT. The profile is global to
  9. # the USB camera, so always leave it in the normal automatic state on exit.
  10. restore_camera_profile() {
  11. v4l2-ctl -d "$camera_device" --set-ctrl=exposure_auto=3 >/dev/null 2>&1 || true
  12. v4l2-ctl -d "$camera_device" --set-ctrl=exposure_auto_priority=0 >/dev/null 2>&1 || true
  13. v4l2-ctl -d "$camera_device" --set-ctrl=white_balance_temperature_auto=1 >/dev/null 2>&1 || true
  14. v4l2-ctl -d "$camera_device" --set-ctrl=brightness=0 >/dev/null 2>&1 || true
  15. v4l2-ctl -d "$camera_device" --set-ctrl=contrast=50 >/dev/null 2>&1 || true
  16. v4l2-ctl -d "$camera_device" --set-ctrl=saturation=50 >/dev/null 2>&1 || true
  17. v4l2-ctl -d "$camera_device" --set-ctrl=gamma=300 >/dev/null 2>&1 || true
  18. echo "traffic_sign_node: camera profile restored to automatic exposure" >&2
  19. }
  20. forward_shutdown() {
  21. if [[ -n "$child_pid" ]]; then
  22. kill -INT "$child_pid" 2>/dev/null || true
  23. wait "$child_pid" 2>/dev/null || true
  24. fi
  25. exit 0
  26. }
  27. trap restore_camera_profile EXIT
  28. trap forward_shutdown INT TERM
  29. /home/ucar/venv3.9/bin/python3 "$script_dir/traffic_sign_node.py" "$@" &
  30. child_pid=$!
  31. wait "$child_pid"
  32. exit $?