Setting up the ROS (Robot Operating System) environment on the Raspberry Pi 4B development board requires a series of steps. Below is a detailed beginner’s tutorial:
Prerequisites:
-
Hardware Requirements:
• Raspberry Pi 4B development board
• At least a 16GB MicroSD card, 32GB is recommended
• A valid power adapter and Micro USB data cable
• Keyboard, mouse, and monitor (or HDMI cable to connect to a TV or computer screen)
• Network connection (Ethernet or Wi-Fi)
2. Software Requirements:
• Download the latest official Raspberry Pi OS image, typically choose Raspberry Pi OS Lite or Desktop version (the Desktop version may be more user-friendly for first-time users as it includes a graphical interface). The Raspberry Pi development board does not come with onboard FLASH as it supports booting from SD cards, and the system is loaded from the SD card.
Download Raspberry Pi official system: https://www.raspberrypi.com/software/
Step 1: Flash the Operating System
-
Download and install the Raspberry Pi Imager tool, or use third-party tools like Etcher, Win32DiskImager, etc., to flash the official system image onto the MicroSD card.
2. After flashing is complete, insert the MicroSD card into the Raspberry Pi slot.
Step 2: Initialize the Raspberry Pi
-
Connect the keyboard, mouse, monitor, and power, then start the Raspberry Pi.
2. Follow the on-screen prompts to complete the initial setup, including region, language, username, password, etc., and connect to the network.
Step 3: Update the System
-
Log in to the Raspberry Pi terminal and use the following commands to update the system and install necessary packages:
sudo apt update
sudo apt full-upgrade
Step 4: Install ROS
-
Add the official ROS source to sources.list:
sudo sh -c ‘echo “deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main” > /etc/apt/sources.list.d/ros-latest.list’
2. Set up key trust:
sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
3. Update the apt cache and install ROS Noetic (or any other version you want, such as Melodic) and related dependencies:
sudo apt update
sudo apt install ros-noetic-desktop-full # or ros-melodic-desktop-full
4. Initialize the ROS environment:
sudo rosdep init
rosdep update
echo “source /opt/ros/noetic/setup.bash” >> ~/.bashrc
source ~/.bashrc
5. Install ROS utilities:
sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
Step 5: Create and Manage ROS Workspace
-
Create a new workspace (for example, create a workspace named catkin_ws):
mkdir -p ~/catkin_ws/
cd ~/catkin_ws
catkin_make
source devel/setup.bash
2. To automatically load the ROS environment every time you start a terminal, you can add the following line to the .bashrc file:
echo “source ~/catkin_ws/devel/setup.bash” >> ~/.bashrc
3. Compile projects in the workspace (when adding new ROS packages):
cd ~/catkin_ws
catkin_make
Now you have successfully installed ROS on the Raspberry Pi 4B and created a workspace. Next, you can obtain the ROS package source code from the ROS official website or other resources, place it in the workspace src directory for compilation and execution. Meanwhile, learn the basic concepts and APIs of ROS for deeper development and practice.
Developing Raspberry Pi 4B requires a long-term process and some embedded experience, such as Linux experience and Python experience.