ROS2相机驱动如何选择Video编号?

大家好,我是小鱼。今天早上有个鱼粉在群里问在ROS2中选择相机编号?

在这里插入图片描述

问题

在ROS2的Foxy版本中,你可以使用下面的命令来运行相机。

source /opt/ros/foxy/setup.bash
ros2 run image_tools cam2image 

我们如果电脑中有多个video设备怎么办?

使用下面的命令来查看video

ll /dev/video*
crw-rw----+ 1 root video 81, 0 3月   7 11:02 /dev/video0
crw-rw----+ 1 root video 81, 1 3月   7 11:02 /dev/video1
crw-rw----+ 1 root video 81, 2 3月   7 11:02 /dev/video2
crw-rw----+ 1 root video 81, 3 3月   7 11:02 /dev/video3
crw-rw----+ 1 root video 81, 4 3月   8 20:50 /dev/video4
crw-rw----+ 1 root video 81, 5 3月   8 20:50 /dev/video5
crw-rw----+ 1 root video 81, 6 3月   8 01:32 /dev/video6

可以看到小鱼有7个video,那我们先要在运行的时候指定video编号该怎么办?我们看看这个节点的help信息。

$ ros2 run image_tools cam2image --help
Usage: cam2image [-h] [--ros-args [-p param:=value] ...]
Publish images from a camera stream.
Example: ros2 run image_tools cam2image --ros-args -p reliability:=best_effort

Options:
  -h, --help	Display this help message and exit

Parameters:
  reliability	Reliability QoS setting. Either 'reliable' (default) or 'best_effort'
  history	History QoS setting. Either 'keep_last' (default) or 'keep_all'.
		If 'keep_last', then up to N samples are stored where N is the depth
  depth		Depth of the publisher queue. Only honored if history QoS is 'keep_last'. Default value is 10
  frequency	Publish frequency in Hz. Default value is 30
  burger_mode	Produce images of burgers rather than connecting to a camera
  show_camera	Show camera stream. Either 'true' or 'false' (default)
  width		Width component of the camera stream resolution. Default value is 320
  height	Height component of the camera stream resolution. Default value is 240
  frame_id		ID of the sensor frame. Default value is 'camera_frame'
Note: try running v4l2-ctl --list-formats-ext to obtain a list of valid values.

很遗憾,没有指定video编号这个参数。

解决方案

查阅Github可以看到,在foxy的下一个版本galactic中增加了这个功能。

使用--ros-args -p device_id:=id号即可指定video编号。

source /opt/ros/galactic/setup.bash
ros2 run image_tools cam2image --ros-args -p device_id:=0

你可以选择同时安装两个版本的ros2,运行相机时使用galactic,经小鱼测试,foxy版本依然可以正常收到话题数据。

还有一种办法就是下载源码编译,依然可以在foxy版本下正常使用~

扫描二维码关注公众号,回复: 13729801 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_27865227/article/details/123363119
今日推荐