Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openpilot webcam support fixed #34215

Merged
merged 14 commits into from
Dec 19, 2024
7 changes: 4 additions & 3 deletions system/manager/process_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ def and_(*fns):
procs = [
DaemonProcess("manage_athenad", "system.athena.manage_athenad", "AthenadPid"),

NativeProcess("camerad", "system/camerad", ["./camerad"], driverview),
NativeProcess("camerad", "system/camerad", ["./camerad"], driverview, enabled=not WEBCAM),
PythonProcess("webcamerad", "tools.webcam.camerad", driverview, enabled=WEBCAM),
NativeProcess("logcatd", "system/logcatd", ["./logcatd"], only_onroad),
NativeProcess("proclogd", "system/proclogd", ["./proclogd"], only_onroad),
PythonProcess("logmessaged", "system.logmessaged", always_run),
PythonProcess("micd", "system.micd", iscar),
PythonProcess("timed", "system.timed", always_run, enabled=not PC),

# TODO Make python process once TG allows opening QCOM from child proc
NativeProcess("dmonitoringmodeld", "selfdrive/modeld", ["./dmonitoringmodeld"], driverview, enabled=(not PC or WEBCAM)),
NativeProcess("dmonitoringmodeld", "selfdrive/modeld", ["./dmonitoringmodeld"], driverview, enabled=(WEBCAM or not PC)),
MikeBusuttil marked this conversation as resolved.
Show resolved Hide resolved
NativeProcess("encoderd", "system/loggerd", ["./encoderd"], only_onroad),
NativeProcess("stream_encoderd", "system/loggerd", ["./encoderd", "--stream"], notcar),
NativeProcess("loggerd", "system/loggerd", ["./loggerd"], logging),
Expand All @@ -89,7 +90,7 @@ def and_(*fns):
PythonProcess("selfdrived", "selfdrive.selfdrived.selfdrived", only_onroad),
PythonProcess("card", "selfdrive.car.card", only_onroad),
PythonProcess("deleter", "system.loggerd.deleter", always_run),
PythonProcess("dmonitoringd", "selfdrive.monitoring.dmonitoringd", driverview, enabled=(not PC or WEBCAM)),
PythonProcess("dmonitoringd", "selfdrive.monitoring.dmonitoringd", driverview, enabled=(WEBCAM or not PC)),
PythonProcess("qcomgpsd", "system.qcomgpsd.qcomgpsd", qcomgps, enabled=TICI),
PythonProcess("pandad", "selfdrive.pandad.pandad", always_run),
PythonProcess("paramsd", "selfdrive.locationd.paramsd", only_onroad),
Expand Down
28 changes: 13 additions & 15 deletions tools/webcam/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
# Run openpilot with webcam on PC

What's needed:
- Ubuntu 24.04
- Ubuntu 24.04 ([WSL2 is not supported](https://github.com/commaai/openpilot/issues/34216))
- GPU (recommended)
- Two USB webcams, at least 720p and 78 degrees FOV (e.g. Logitech C920/C615)
- [Car harness](https://comma.ai/shop/products/comma-car-harness) with black panda to connect to your car
- [Panda paw](https://comma.ai/shop/products/panda-paw) or USB-A to USB-A cable to connect panda to your computer
That's it!

## Setup openpilot
- Follow [this readme](../README.md) to install and build the requirements
- Install OpenCL Driver
```
cd ~
git clone https://github.com/commaai/openpilot.git
```
- Follow [this readme](https://github.com/commaai/openpilot/tree/master/tools) to install the requirements
- Install [OpenCL Driver](https://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/15532/l_opencl_p_18.1.0.015.tgz)

## Build openpilot for webcam
```
cd ~/openpilot
USE_WEBCAM=1 scons -j$(nproc)
sudo apt install pocl-opencl-icd
```

## Connect the hardware
- Connect the road facing camera first, then the driver facing camera
- (default indexes are 1 and 2; can be modified in system/camerad/cameras/camera_webcam.cc)
- Connect your computer to panda

## GO
```
cd ~/openpilot/system/manager
NOSENSOR=1 USE_WEBCAM=1 ./manager.py
USE_WEBCAM=1 system/manager/manager.py
```
- Start the car, then the UI should show the road webcam's view
- Adjust and secure the webcams (you can run tools/webcam/front_mount_helper.py to help mount the driver camera)
- Adjust and secure the webcams.
MikeBusuttil marked this conversation as resolved.
Show resolved Hide resolved
- Finish calibration and engage!

## Specify Cameras

Use the `ROAD_CAM`, `DRIVER_CAM`, and optional `WIDE_CAM` environment variables to specify which camera is which (ie. `DRIVER_CAM=2` uses `/dev/video2` for the driver-facing camera):
```
USE_WEBCAM=1 ROAD_CAM=4 WIDE_CAM=6 system/manager/manager.py
```
15 changes: 8 additions & 7 deletions tools/webcam/camerad.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from openpilot.tools.webcam.camera import Camera
from openpilot.common.realtime import Ratekeeper

DUAL_CAM = os.getenv("DUAL_CAMERA")
WIDE_CAM = os.getenv("WIDE_CAM")
CameraType = namedtuple("CameraType", ["msg_name", "stream_type", "cam_id"])
CAMERAS = [
CameraType("roadCameraState", VisionStreamType.VISION_STREAM_ROAD, os.getenv("CAMERA_ROAD_ID", "/dev/video0")),
CameraType("driverCameraState", VisionStreamType.VISION_STREAM_DRIVER, os.getenv("CAMERA_DRIVER_ID", "/dev/video1")),
CameraType("roadCameraState", VisionStreamType.VISION_STREAM_ROAD, os.getenv("ROAD_CAM", "0")),
CameraType("driverCameraState", VisionStreamType.VISION_STREAM_DRIVER, os.getenv("DRIVER_CAM", "2")),
]
if DUAL_CAM:
CAMERAS.append(CameraType("wideRoadCameraState", VisionStreamType.VISION_STREAM_WIDE_ROAD, DUAL_CAM))
if WIDE_CAM:
CAMERAS.append(CameraType("wideRoadCameraState", VisionStreamType.VISION_STREAM_WIDE_ROAD, WIDE_CAM))

class Camerad:
def __init__(self):
Expand All @@ -25,8 +25,9 @@ def __init__(self):

self.cameras = []
for c in CAMERAS:
print(f"opening {c.msg_name} at {c.cam_id}")
cam = Camera(c.msg_name, c.stream_type, c.cam_id)
cam_device = f"/dev/video{c.cam_id}"
print(f"opening {c.msg_name} at {cam_device}")
cam = Camera(c.msg_name, c.stream_type, cam_device)
self.cameras.append(cam)
self.vipc_server.create_buffers(c.stream_type, 20, cam.W, cam.H)

Expand Down
14 changes: 0 additions & 14 deletions tools/webcam/start_camerad.sh

This file was deleted.

Loading