http://blog.sina.com.cn/s/blog_602f87700102wtwz.html
http://blog.sina.com.cn/s/blog_602f87700102wtwz.html
ROS 公用包学习解析<一> usb_cam (2017-07-31 16:28:21)
标签: usb_cam ros 分类: 机器人-ROS
作者: Sam (甄峰) sam_code@hotmail.com
Sam最近在学习ROS过程中,遇到非常多官方Package。对ROS Driver也有所得。现陆续记录如下。
首先从usb_cam Package说起。
-
简介:
A ROS Driver For V4L USB Camera.
0.1: ROS Driver和Linux driver的区别:
ROS并非全操作系统,它只是架设在Ubuntu上的一个次级系统。提供了一系列通讯方式,工具和包,让开发者更容易工作的一个平台。
所以,ROS Driver与Linux Driver完全不同。 Linux Driver是在内核模式下获取硬件信息,反馈到用户模式下。并提供在用户模式下控制内核模式下才能访问的硬件的途径(ioctl)。
ROS Driver则不同,它完全是在用户模式下,从Linux层面获取数据。并通过Topic发送Message。使得其它ROS Node可以通过topic得到信息的程序。
usb_cam就是个典型的ROS Driver. 通过它,理解ROS Driver的层级和用途。
它并非Linux传统意义上的Driver, 它其实只是个应用程序,通过V4L2接口设置Camera并获取数据, 利用ROS接口发布Topic,供其它Node实用. -
usb_cam的下载和组织结构:
1.1: 下载并编译:
$cd ~/catkin_ws/src
$git clone https://github.com/ros-drivers/usb_cam.git
$cd ~catkin_ws
$catkin_make
1.2:目录文件分析:
分析代码组织架构,最好的方法是分析CMakeLists.txt. 从中可以看到,主要的C/C++源码有2个。
src/usb_cam.cpp最终产生libusb_cam.so, 它使用V4L2 接口访问Camera,并提供一些必要的格式转换工具。
nodes/usb_cam_node.cpp最终产生usb_cam_node。(它使用了前面产生的库)。它初始化ROS,利用libusb_cam.so获取Camera数据。并利用image_transport发布各种格式的Image。
1.3:usb_cam_node相关讲解:
usb_cam_node 利用libusb_cam.so使用通用接口访问USB Camera。并publishe Image使用格式为:sensor_msgs::Image.
可以使用image_transport 库去传输压缩格式Image。
1.3.1: Publish Topic:
~/image (sensor_msgs/Image)
The image
1.3.2:Parameter:
~video_device (string, default: “/dev/video0”)
The device the camera is on.
~image_width (integer, default: 640)
Image width
~image_height (integer, default: 480)
Image height
~pixel_format (string, default: “mjpeg”)
Possible values are mjpeg, yuyv, uyvy
~io_method (string, default: “mmap”)
Possible values are mmap, read, userptr
~camera_frame_id (string, default: “head_camera”)
The camera's tf frame
~framerate (integer, default: 30)
The required framerate
~contrast (integer, default: 32)
Contrast of video image (0-255)
~brightness (integer, default: 32)
Brightness of video image (0-255)
~saturation (integer, default: 32)
Saturation of video image (0-255)
~sharpness (integer, default: 22)
Sharpness of video image (0-255)
~autofocus (boolean, default: false)
Enable camera's autofocus
~focus (integer, default: 51)
If autofocus is disabled, the focus of the camera (0=at infinity)
~camera_info_url (string, default: )
An url to the camera calibration file that will be read by the CameraInfoManager class
~camera_name (string, default: head_camera)
The camera name. This must match the name in the camera calibration
这些参数就是V4L2常用的设置参数。
- usb_cam使用:
2.1: 字符模式下使用:
$roscore
$rosrun usb_cam usb_cam_node
$rosrun rqt_image_view rqt_image_view