How to use USB camera with ROS on Raspberry Pi - image_view and web streaming



Today's tutorial is about to connect USB Camera to Raspberry Pi and use it with ROS (Robot Operating System) - read data though ROS image_view and even stream to web browser!


 Video transcript:

1) As a bonus, we will make a distributed ROS system.

2) Roscore and image view app will run on PC (master) and camera ros node on Raspberry Pi (slave).

3) To configure master and slave, we need to update environment variables on both devices

4) On maser: find IP address of device. For ethernet net_dev could be like enpXXs0 or ethX:
    $ ifconfig {net_dev} ifconfig enp61s0 

5) Use IP address as value for ROS_IP variable:
    $ export ROS_IP="10.42.0.1" 

6) And for ROS_MASTER_URI:
    $ export ROS_MASTER_URI="http://10.42.0.1:11311

7) If you want to use these values for future sessions, you can save exports to .bashrc in your home dir
    $ echo 'export ROS_IP="10.42.0.1"' >> ~/.bashrc 
   $echo 'export ROS_MASTER_URI="http://10.42.0.1:11311"' >> ~/.bashrc

8) Connect to Raspberry Pi via ssh:
    $ ssh {user}@{raspberry_ip} 

9) For RPi as a slave add master IP for ROS_MASTER_URI

10) And Raspberry Pi's IP address as ROS_IP
    $ export ROS_IP="10.42.0.65" 
    $ export ROS_MASTER_URI="http://10.42.0.1:11311
    or   
    $ echo 'export ROS_IP="10.42.0.65"' >> ~/.bashrc 
    $ echo 'export ROS_MASTER_URI="http://10.42.0.1:11311"' >> ~/.bashrc

11) Now it's time to plug in USB camera

12) Check if camera was recognized by system:
    $ lsusb 
    $ ls /dev | grep video* 

13) Install usb_cam ROS node with needed dependencies:
    $ sudo apt install ros-kinetic-usb-cam

14) usb_cam node already have test launch file:
     $ cat /opt/ros/kinetic/share/usb_cam/launch/usb_cam-test.launch

15) Before run this launch file, let's start ROS core on master:
    $ roscore

16) And now start usb_cam node on slave:
    $ roslaunch usb_cam usb_cam-test.launch

17) Now we can see created topics. We can check them either on master or slave.

 18) Bring running process to background with CTRL+Z and execute bg command to continue execution it in background

19) To see topics in terminal:
    $ rostopic list

20) ...or in GUI:
    $ rqt_graph

21) Read camera data with image_view:
    $ rosrun image_view image_view image:=/usb_cam/image_raw

22) Or Using rqt_image_view

23) To bring background task to foreground:
    $ fg

24) Last experiment for today - web streaming

25) Install web-video-server ROS node
    $ sudo apt install ros-kinetic-web-video-server

26) To make it right, create catkin workspace for our custom launch file:
    $ mkdir -p ~/rosvid_ws/src 
    $ cd ~/rosvid_ws 
    $ catkin_make 
    $ source devel/setup.bash

27) Then create ROS package:
    $ cd src 
    $ catkin_create_pkg vidsrv std_msgs rospy roscpp 

28) And create launch file using nano, vim, etc.:
    $ mkdir -p vidsrv/launch 
    $ nano vidsrv/launch/vidsrv.launch 

place there code from
https://gist.github.com/WinKILLER/3de...

29) Build package:
    $ cd .. 
    $ catkin_make 

30) Again, start ROS core on master
    $ roscore 

31) And run created launch file:
    $ roslaunch vidsrv vidsrv.launch 

32) Default web-video-server port is 8080

33) Open URL in web browser: {RPi_IP}:8080

Links:

4 комментария:

  1. hello, first, excellent blog, has a lot of useful information. i would like to know what linux distribution do you use in the pi?

    ОтветитьУдалить
    Ответы
    1. Hi. Thanks! I'm using Ubuntu 16.04. Please check one of my previous posts on how to install ubuntu, if you need it.

      Удалить
    2. thank you for your quick response, I already found your other videos very good explained, but I have a raspberry pi 3b+ I tried to install a version of ubuntu, but I could not make it work has enough incompatibilities yet.

      I'm going to install the Rasbian version of ROS and try to follow your videos.

      Удалить
    3. I have an idea to make the same video as for ubuntu, but for raspbian. But I am pretty sure that you figure out how to do it much faster than I release my video:)

      Удалить