Running Ros on a Raspbery Pi 4 with Raspberry Pi OS

Introduction

Installing ROS on a Raspberry Pi 4 is difficult because, though the ubuntu images seem good to go, I experienced unknown problems setting up a headless install of ubuntu 18. Ubuntu 20.04 worked eventually, but initial startup took over 5 minutes for the device to show up on my network. Plus I was interested in installing ros melodic, which is built for ubuntu 18. So here are the steps I used. I installed raspbian buster and compiled ros from scratch.

Instructions

  1. Download the Raspberry Pi Imager: https://www.raspberrypi.org/downloads/

    Alternate imagers:

  2. Download an Image: I used the lite version and then added packages as needed

  3. Install raspbian using the instructions for a headless install located here: https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-a-headless-raspberry-pi

    Alternate instructions:

  4. Make sure you follow the instructions below for setting up wireless & ssh

    Other information:

  5. Find the Pi on your network (in linux). You can use a virtual machine to do this

    sudo apt install -y net-tools nmap
    arp -na
    nmap -sn 10.0.0.*
    

    Note the IP address

  6. log on using putty

  7. Define a static IP address (derived from here)

    1. edit dhcpcd.conf

      sudo nano /etc/dhcpcd.conf
      
    2. uncomment out lines for static ip/subnet and router and define them to what you need.

    3. Restart

      sudo reboot
      

    Alternate Instructions(I didn’t use):

  8. install xrdp (using this tutorial):

  9. install gedit

    sudo apt install -y gedit
    
  10. Install ROS using this tutorial

    Alternate Instructions(didn’t use):

  11. change password for user pi

    passwd
    
  12. Set up camera using this tutorial

Note: This section may be outdated. Please see this section about libcamera

1. install other packages for viewing and programming

    ```
    sudo apt install -y gpicview vlc thonny
    pip3 install picamera
    ```

1. After installing picamera there may be a warning.  use the next lines to fix:

    ```
    echo "export PATH=\$PATH:/home/pi/.local/bin" >> ~/.bashrc
    source ~/.bashrc
    ```
  1. install opencv using this tutorial

    Notes:

    • I used option 4a
    • I didn’t use virtualenv…space reasons.
    • use sudo pip3 install instead of pip install to install in python3
  2. install other necessary packages

    sudo apt install -y libilmbase-dev libopenexr-dev libgstreamer1.0-dev
    
  3. clone raspicam node

    git clone https://github.com/idealabasu/raspicam_node.git
    
  4. not sure these packages are needed:

    sudo apt install -y python3-catkin-pkg
    sudo apt install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
    sudo apt install -y python3-empy
    
  5. update ros install with joystick and compressed image transport packages, following instructions here:

    and using

    rosinstall_generator ros_comm joystick_drivers compressed_image_transport camera_info_manager dynamic_reconfigure diagnostic_updater cv_bridge --rosdistro melodic --deps --wet-only --tar > melodic-custom_ros.rosinstall
    
  6. Add idealab ros workspace: (see other tutorial)

  7. checkout rpi4 branch

    git checkout rpi4
    
  8. (Mental Note) cloned and copied raspicam_node into code_idealab_ros/src (don’t do, already done)

    1. Make projects

      cd ~/code/code_idealab_ros
      catkin_make
      
  9. optional: change ros master uri to remote. Only necessary if you want the raspberry pi to work within a bigger ros network. Modify ip addresses to match desired network topology

    echo "export MY_MASTER_IP=10.0.0.201" >> .bashrc
    echo "export MY_IP=10.0.0.200" >> .bashrc
    echo "export ROS_MASTER_URI=http://\$MY_MASTER_IP:11311" >> .bashrc
    echo "export ROS_IP=\$MY_IP" >> .bashrc
    source .bashrc
    
  10. Run Roslaunchp (modified from here

    #roslaunch raspicam_node camerav2_1280x720.launch
    #roslaunch raspicam_node camerav2_410x308_30fps.launch
    roslaunch raspicam_node dan_cam1.launch
    
  11. on the host:

    1. in one terminal:

      roscore
      
    2. in a second terminal:

      rosrun rqt_image_view rqt_image_view