Table of Contents
Overview#
This guide covers setting up a USB camera on Raspberry Pi and streaming the video to a PC for visualization in RViz.
System Architecture#
┌─────────────────────┐ ┌─────────────────────┐
│ Raspberry Pi │ │ PC │
│ ┌───────────────┐ │ │ ┌───────────────┐ │
│ │ USB Camera │ │ WiFi │ │ RViz │ │
│ └───────┬───────┘ │ ──────► │ │ Visualization│ │
│ ┌───────┴───────┐ │ │ └───────────────┘ │
│ │ usb_cam │ │ │ │
│ │ ros node │ │ │ │
│ └───────────────┘ │ │ │
└─────────────────────┘ └─────────────────────┘Raspberry Pi Setup#
Install ROS Noetic#
# Add repository
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros-latest.list'
# Add key
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
# Install
sudo apt update
sudo apt install ros-noetic-ros-baseInstall USB Camera Package#
sudo apt install ros-noetic-usb-camCreate Catkin Workspace#
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin_make
source devel/setup.bashCreate Launch File#
Create ~/catkin_ws/src/usb_cam.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>
</launch>Configure Environment#
Add to ~/.bashrc:
source /opt/ros/noetic/setup.bash
source ~/catkin_ws/devel/setup.bash
export ROS_MASTER_URI=http://<PC_IP>:11311
export ROS_HOSTNAME=<PI_IP>Apply:
source ~/.bashrcPC Setup#
Install ROS Noetic#
sudo apt install ros-noetic-desktop-fullConfigure Environment#
Add to ~/.bashrc:
source /opt/ros/noetic/setup.bash
export ROS_MASTER_URI=http://<PC_IP>:11311
export ROS_HOSTNAME=<PC_IP>Running the System#
Terminal 1: PC - roscore#
roscoreTerminal 2: Pi (SSH) - Camera#
roslaunch usb_cam usb_cam.launchOr use the custom launch file:
roslaunch ~/catkin_ws/src/usb_cam.launchTerminal 3: PC - RViz#
rosrun rviz rvizAdd Camera Display in RViz#
- Click “Add” button
- Select “Image”
- Set Image Topic:
/usb_cam/image_raw - Image should appear in RViz
Verify Image Stream#
Check Topic#
rostopic list | grep imageShould show:
/usb_cam/image_rawCheck Bandwidth#
rostopic bw /usb_cam/image_rawView with image_view#
rosrun image_view image_view image:=/usb_cam/image_rawTroubleshooting#
Camera Not Found#
# Check device
ls /dev/video*
# Test camera
v4l2-ctl --list-devicesPermission Denied#
sudo chmod 666 /dev/video0
# Or add user to video group
sudo usermod -a -G video $USERLow Frame Rate#
Reduce resolution or use compressed topic:
rostopic echo /usb_cam/image_raw/compressedAdvanced Options#
Camera Parameters#
| Parameter | Description | Default |
|---|---|---|
| video_device | Camera device | /dev/video0 |
| image_width | Frame width | 640 |
| image_height | Frame height | 480 |
| framerate | Frames per second | 30 |
| pixel_format | Color format | yuyv |