1.找到要使用的例程代码的位置,一般在/opt/tros/share目录下,对比例程运行命令找到要运行的laun文件名称,去到对应的目录下,例如使用人手关键点检测,启动命令为ros2 launch hand_lmk_detection hobot_hand_lmk_detection.launch.py ,则进入/opt/tros/share/hand_lmk_detection/launch文件夹,要更改的文件名是hobot_hand_lmk_detection.launch.py。
2.更改摄像头启动节点代码
原代码 :
Node(
package='mipi_cam',
executable='mipi_cam',
output='screen',
parameters=[
{"out_format": "nv12"},
{"image_width": 960},
{"image_height": 544},
{"io_method": "shared_mem"},
{"video_device": "F37"}
],
arguments=['--ros-args', '--log-level', 'error']
),
更改后:
Node(
package='hobot_usb_cam',
executable='hobot_usb_cam',
output='screen',
name='hobot_usb_cam',
parameters=[
#{"out_format": "nv12"},
{"frame_id": "default_usb_cam"},
{"image_width": 640},
{"image_height": 480},
{"io_method": "mmap"},
{"zero_copy": False},
{"pixel_format": "mjpeg"},
{"video_device": "/dev/video8"}#更改为自己设备的位置
],
arguments=['--ros-args', '--log-level', 'error']
),
3.更改图片发布节点代码
原代码:
Node(
package='hobot_codec',
executable='hobot_codec_republish',
output='screen',
parameters=[
{"channel": 1},
{"in_mode": "shared_mem"},
{"in_format": "nv12"},
{"out_mode": "ros"},
{"out_format": "jpeg"},
{"sub_topic": "/hbmem_img"},
{"pub_topic": "/image"}
],
arguments=['--ros-args', '--log-level', 'error']
),
更改后:
Node(
package='hobot_codec',
executable='hobot_codec_republish',
output='screen',
parameters=[
{"channel": 1},
{"in_mode": "ros"},
{"in_format": "jpeg"},
{"out_mode": "shared_mem"},
{"out_format": "nv12"},
{"sub_topic": "/image"},
{"pub_topic": "/hbmem_img"}
],
arguments=['--ros-args', '--log-level', 'error']
),
4.更改完保存后即可按照手册里的启动方式启动。
# 配置TogetherROS环境
source /opt/tros/setup.bash
# 从TogetherROS的安装路径中拷贝出运行示例需要的配置文件。
cp -r /opt/tros/lib/mono2d_body_detection/config/ .
cp -r /opt/tros/lib/hand_lmk_detection/config/ .
# 启动launch文件
ros2 launch hand_lmk_detection hobot_hand_lmk_detection.launch.py
由于截图不是太方便我就截出来这一张比较模糊的效果图。
其他几个例程也能这样修改后使用usb摄像头。
