Jetson Nano 2G ROS 调用 CSI摄像头



1.安装ROS的CSI摄像头软件包

TX2推荐安装jetson_csi_cam,而Nano推荐安装jetson_nano_csi_cam



1.1 jetson_csi_cam

注意:与下面的jetson_nano_csi_cam二选一。
参考:GitHub - peter-moran/jetson_csi_cam: A ROS package making it simple to use CSI cameras on the Nvidia Jetson TK1, TX1, or TX2 with ROS.

1.1.1安装 GStreamer-1.0

sudo add-apt-repository universe
sudo add-apt-repository multiverse
sudo apt-get update
sudo apt-get install gstreamer1.0-tools gstreamer1.0-alsa \
 gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
 gstreamer1.0-libav
sudo apt-get install libgstreamer1.0-dev \
 libgstreamer-plugins-base1.0-dev \
 libgstreamer-plugins-good1.0-dev \
 libgstreamer-plugins-bad1.0-dev

查看 GStreamer-1.0 版本

gst-inspect-1.0 --version

1.1.2下载包jetson_csi_camgscam

cd ~/ccmslam_ws/src
git clone https://github.com/peter-moran/jetson_csi_cam.git
git clone https://github.com/ros-drivers/gscam.git

修改gscamMakefile

gedit ~/ccmslam_ws/gscam/Makefile

第一行后面加上-DGSTREAMER_VERSION_1_x=On变成:

EXTRA_CMAKE_FLAGS = -DUSE_ROSBUILD:BOOL=1 -DGSTREAMER_VERSION_1_x=On

保存退出,返回工作空间编译:

cd ../..
catkin_make

如果catkin_make失败,则用

catkin_make_isolated

测试:

roscore
roslaunch jetson_csi_cam jetson_csi_cam.launch

若出现错误:gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
解决方法转自:https://github.com/peter-moran/jetson_csi_cam/issues/1

修改jetson_csi_cam.launch

gedit ~/ccmslam_ws/src/jetson_csi_cam/jetson_csi_cam.launch

把关于GSCAM_CONFIG的那一段改为:

1.1.3 再运行roslaunch:

roslaunch jetson_csi_cam jetson_csi_cam.launch

如果出现错误:Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvargus
则终端运行:

sudo systemctl restart nvargus-daemon

再运行roslaunch

查看ROS话题:

rostopic list

发现出现了/csi_cam_0/image_raw
查看捕获的图像:

rqt_image_view

如果能正确显示图像,则成功了。




1.2 jetson_nano_csi_cam

注意:与上面的jetson_csi_cam二选一。
参考:https://github.com/rt-net/jetson_nano_csi_cam_ros

1.2.1安装 GStreamer-1.0

sudo add-apt-repository universe
sudo add-apt-repository multiverse
sudo apt-get update
sudo apt-get install gstreamer1.0-tools gstreamer1.0-alsa \
 gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
 gstreamer1.0-libav
sudo apt-get install libgstreamer1.0-dev \
 libgstreamer-plugins-base1.0-dev \
 libgstreamer-plugins-good1.0-dev \
 libgstreamer-plugins-bad1.0-dev

查看 GStreamer-1.0 版本

gst-inspect-1.0 --version

1.2.2下载包jetson_nano_csi_camgscam

cd ~/ccmslam_ws/src
git clone https://github.com/rt-net/jetson_nano_csi_cam_ros.git 
git clone https://github.com/ros-drivers/gscam.git

修改gscam的Makefile:

gedit ~/ccmslam_ws/gscam/Makefile

第一行后面加上-DGSTREAMER_VERSION_1_x=On变成:

EXTRA_CMAKE_FLAGS = -DUSE_ROSBUILD:BOOL=1 -DGSTREAMER_VERSION_1_x=On

保存退出,返回工作空间编译:

cd ../..
catkin_make

1.2.3 运行roslaunch:

roslaunch jetson_nano_csi_cam jetson_nano_csi_cam.launch

查看ROS话题:

rostopic list

发现出现了/csi_cam_0/image_raw

查看捕获的图像:

rqt_image_view

如果能正确显示图像,则成功了。




2.修改Client0_euroc.launch

gedit ~/ccmslam_ws/src/ccm_slam/cslam/launch/EuRoC/Client0_euroc.launch

将参数cam更改为新相机文件的路径:
即,将

 

改为:

 



3.编写启动文件

编写ccm-csi.sh

gnome-terminal -t "cam" -x bash -c "roslaunch jetson_csi_cam jetson_csi_cam.launch;exec bash;"

sleep 3
gnome-terminal -t "server" -x bash -c "roslaunch ccmslam Server.launch;exec bash;"
sleep 3

gnome-terminal -t "agent0" -x bash -c "roslaunch ccmslam Client0_euroc.launch;exec bash;"

sleep 3 
gnome-terminal -t "rviz" -x bash -c "roscd ccmslam ;rviz -d conf/rviz/ccmslam.rviz ;exec bash;"

如果上面用的是jetson_nano_csi_cam包,则:

gnome-terminal -t "cam" -x bash -c "roslaunch jetson_nano_csi_cam jetson_nano_csi_cam.launch;exec bash;"

sleep 3
gnome-terminal -t "server" -x bash -c "roslaunch ccmslam Server.launch;exec bash;"
sleep 3

gnome-terminal -t "agent0" -x bash -c "roslaunch ccmslam Client0_euroc.launch;exec bash;"

sleep 3 
gnome-terminal -t "rviz" -x bash -c "roscd ccmslam ;rviz -d conf/rviz/ccmslam.rviz ;exec bash;"



4.启动

命令行输入:

chmod +x ccm-csi.sh
sh ccm-csi.sh



如果出现错误:Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvargus
则终端运行:

sudo systemctl restart nvargus-daemon

转载:Jetson Nano 调用CSI摄像头运行CCMSLAM_不能再吃了OvO的博客-CSDN博客

附录:

1、另外一个2g+sci+ros的教程:

机器人视觉(二) ROS Melodic + CSI 摄像头 + jetson Nano 2GB_smallEngineer的博客-CSDN博客

2、上面的程序使用之后摄像头可能画面需要翻转
官方给的修改方式如下:

$ cd ~/jetson-inference/utils/camera/
$ gedit gstCamera.cpp

目标修改代码片段:

#if NV_TENSORRT_MAJOR > 1 && NV_TENSORRT_MAJOR < 5 // if
JetPack 3.1-3.3 (different flip-method)
const int flipMethod = 0; // Xavier (w/TRT5) camera is mounted inverted
#else
const int flipMethod = 2;
#endif


官方的说明是将其中的filpMethod=2修改为filpMethod=0

其实这个方法,我进行了尝试,但是发现这个里面有一个漏洞,使用gedit编辑器进行编辑,发现目标代码片段不存在。

正确修改方法:

Jetson Nano 2G ROS 调用 CSI摄像头_第1张图片

将其中的进行180度旋转的代码进行注释掉

但是一定要重新进行make编译链接,才能使得修改生效,最终再次执行,发现摄像头已经完成了反转!

3、运行ros之后rqt_image_view打开摄像头画面

4、Camera feed frame_id - ROS Answers: Open Source Q&A Forum

你可能感兴趣的:(自动驾驶,ubuntu,ar)