> For the complete documentation index, see [llms.txt](https://lamhung81-2.gitbook.io/github-basic-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lamhung81-2.gitbook.io/github-basic-tutorial/ket-noi-camera-ocam-tren-ros.md).

# Kết nối camera oCAM trên ROS

## Trong folder catkin\_ws/src,

git clone <https://github.com/lamhung81/usb_cam.git>

Folder usb\_cam này đã được fork từ <http://wiki.ros.org/usb_cam> vào tài khoản github lamhung81

Sau đó catkin\_make hay catkin build

## Rồi chạy

roslaunch usb\_cam usb\_cam-test.launch

### Cách khác để chạy:

rosrun usb\_cam usb\_cam\_node

Chú ý là khi chạy lệnh này, thông tin confìguration sẽ được load từ file usb\_cam-test.launch

Do đó cần sửa thông số trong file .launch này

### Chú ý,

Kiểm tra xem oCAM đã được nối vào cổng USB 3.0 của máy tính chưa? Lưu ý có thể có cổng USB3.0 ở mặt trươc của desktop ko cho kết nối đúng.

dùng lệnh

ls /dev/

để kiểm tra xem có phải là camera đã được nhận trong hệ thống là video0 chưa?

### Sửa đổi tham số file usb\_cam-test.launch

Có thể sửa đổi, ví dụ kích cỡ frame, tần số, định dạng yuyv hay mjpeg ...

Tham khao thông tin tham số trên trang của ros

<http://wiki.ros.org/usb_cam>

### Báo lỗi:

Lưu ý là nếu định dạng yuyv thì tốt, còn nếu là mjpeg

\<param name="pixel\_format" value="mjpeg" />

thì báo lỗi

Webcam: expected picture but didn't get it...

### Sửa lỗi:

Ví dụ dùng camera oCAM oCam-5CRO-U, cần update firmware.

Tính đến ngày 21/12/2017 thì phiên bản mới nhất là R1707

Theo link <https://github.com/withrobot/oCam/tree/master/Firmware>

Có firmware mới nhất là [oCam-5CRO-U\_R1707\_170629.img](https://github.com/withrobot/oCam/blob/master/Firmware/oCam-5CRO-U_R1707_170629.img)

Để update firmware, cần thực hiện trên máy tính cài Windows, chi tiết theo link

<https://github.com/withrobot/oCam/tree/master/Firmware/Update_FW�>

�(Theo hướng dẫn này cần download 170703\_UpdateFW\.zip và drv\_1.2.3.10.zip)

Sau khi update firmware thì sẽ ko còn bị lỗi như trên nữa.

### Check fps

rostopic hz --window=1000 /usb\_cam/image\_raw

### Calibration:

Để calibrate camera trên ROS, theo link

<http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration>

Thực hiện theo chỉ dẫn, chú ý câu lệnh sau phải sửa theo thực tế

```
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/usb_cam/image_raw camera:=/usb_cam
```

Sau khi calibrate xong, ấn SAVE để lưu.

Nếu calibrate ok, thì ấn COMMIT để lưu nội dung lại trong file /home/nguyen/.ros/camera\_info/head\_camera.yaml
