ROS机器人视觉(一)

 

1. 器材

ROS Hydro
Logitech摄像头(型号未知)
  •  

2. 确定安装的驱动

查看设备驱动号和产品号命令lsusb:
$ lsusb
如果该摄像头兼容UVC,则会输出类似信息

  bFunctionClass 14 Video 
  bInterfaceClass 14 Video 
  bInterfaceClass 14 Video 
  bInterfaceClass 14 Video 
  若无以上信息,则是non-UVC设备。

我的是046d:082d Logitech, Inc。所以安装usb_cam,而不是uvc_cam包。
  •  

3. 安装测试ROS摄像头驱动包(usb_cam)

两种安装方式
  •  

1. apt-get install

$ sudo apt-get install ros-hydro-bosch-drivers 
  •  

2.下载安装编译包

$ cd catkin_ws/src  
$ git clone https://github.com/bosch-ros-pkg/usb_cam.git  
$ cd ..  
$ catkin_make 

apt-get install 时候找不到相应的包,所以使用第二种。无问题。

4. 运行usb_cam_node开启摄像头

    在另外一个终端打开
    $ roscore
    新版本的usb_cam包在launch文件夹下有自带的launch文件,名叫usb_cam-test.launch 我们可以直接cd到这个文件夹下运行它.
    $ cd  
    $ cd catkin_ws/src/usb_cam/launch  
    $ roslaunch usb_cam-test.launch 

    如果工作空间的usb_cam包中不带这个launch文件我们就要新建它:打开catkin_ws/src/usb_cam/launch文件夹,在其中新建一个文件,把名字改为usb_cam-test.launch用文本编辑器打开,写入以下代码:
    <launch> 
    <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >  
    <param name="video_device" value="/dev/video0" />  
    <param name="image_width" value="640" />  
    <param name="image_height" value="480" />  
    <param name="pixel_format" value="yuyv" />  
    <param name="camera_frame_id" value="usb_cam" />  
    <param name="io_method" value="mmap"/>  
  </node>  
    <node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">  
    <remap from="image" to="/usb_cam/image_raw"/>  
    <param name="autosize" value="true" />  
  </node>  
</launch>  

保存,并关闭这个文件。 
然后同样要cd到launch文件夹才能运行这个文件:

    $ cd  
    $ cd catkin_ws/src/usb_cam/launch  
    $ roslaunch usb_cam-test.launch 

图像出来了。由于用的另一台机器,不方便截图,就未截图。

5. 遇到的问题

1、报错[usb_cam-test.launch] is not a launch file name 
运行完roslaunch usb_cam-test.launch后报错说usb_cam-test.launch不是一个launch文件,这是因为没有cd到catkin_ws/src/usb_cam/launch文件夹下,系统找不到这个launch文件 
或者如果事先source了该工作空间,可以在任意目录下运行roslaunch usb_cam usb_cam-test.launch都行 
2、对于有些节点没有跑起来的情况,可以从下载的catkin_ws/src/usb_cam中找到相应的.py文件然后用cp命令复制到opt/ros/hydro/的相应文件夹下 
这篇文章:配置ROS工作空间catkin+rosbuild对于理解ROS的文件系统很有帮助 
3、如果出现报错“sh: 1: v4l2-ctl: not found”则需要安装v4l2 
运行:sudo apt-get install v4l-utils

猜你喜欢

转载自blog.csdn.net/weixin_41213648/article/details/85245041