Welcome to Raspberry Pi 5 repository
2.ROS2 install Humble
ROS2 Installation Guide
If you are using the factory image we provided, manual installation and configuration are not required.
ROS2-Humble corresponds to Ubuntu system 22.04
If you need to install other versions of ROS2, you only need to change the humble version identifier in the corresponding installation command to the desired version. This applies to all other ROS2-specific version software in the ROS2 tutorial series. Subsequent tutorials will not repeat this.
1. Set Up Locale
First, check if your locale supports UTF-8 encoding. You can run the following command to check and set UTF-8 encoding:
xlocale # Check if UTF-8 is supported
sudo apt update && sudo apt install localessudo locale-gen en_US en_US.UTF-8sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8export LANG=en_US.UTF-8
locale # Verify the settingsNote: The locale can be different, but it must support UTF-8 encoding.
2. Set Up Software Sources
Enable Ubuntu universe repository:
xxxxxxxxxxsudo apt install software-properties-commonsudo add-apt-repository universeAdd the ROS 2 apt repository to your system and authorize our GPG key with apt:
xxxxxxxxxxsudo apt update && sudo apt install curl gnupg lsb-release -ysudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpgAdd the repository to the source list:
xxxxxxxxxxecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
3. Install Humble
First, update the apt repository cache:
xxxxxxxxxxsudo apt updateThen upgrade installed software (ROS2 packages are built on frequently updated Ubuntu systems. Please ensure your system is up to date before installing new packages):
xxxxxxxxxxsudo apt upgradeInstall ROS2 desktop version (recommended), which includes: ROS, RViz, examples and tutorials. The installation command is as follows. To install other versions, replace humble in the command with the corresponding version number:
xxxxxxxxxxsudo apt install ros-humble-desktop python3-argcompleteInstall colcon build tools:
xxxxxxxxxxsudo apt install python3-colcon-common-extensions
4. Configure Environment
If you are using another version of ROS2, replace the humble version identifier with the corresponding version. For example, for the foxy version, replace humble with foxy in the command.
When running ROS2 programs in the terminal, you need to run the following command to configure the environment:
xxxxxxxxxxsource /opt/ros/humble/setup.bashEvery time you open a new terminal, you need to run the above command. Alternatively, you can run the following command to write the environment configuration instruction to the "~/.bashrc" file. Then every time you start a new terminal, you don't need to manually configure the environment:
xxxxxxxxxxecho "source /opt/ros/humble/setup.bash" >> ~/.bashrcAt this point, ROS2 has been installed and configured.
5. Run Publisher and Subscriber Example Nodes
The ROS2 desktop version comes with some example nodes pre-integrated. We can test if ROS2 is installed successfully by running example nodes.
Run the publisher node:
xxxxxxxxxxros2 run demo_nodes_cpp talkerRun the subscriber node:
xxxxxxxxxxros2 run demo_nodes_cpp listener
6. Run the TurtleSim Tutorial
The turtlesim simulator is a classic teaching tool in ROS. Through turtlesim, you can quickly understand core concepts in ROS.
Run the turtle simulator:
xxxxxxxxxxros2 run turtlesim turtlesim_nodeRun the keyboard control node:
xxxxxxxxxxros2 run turtlesim turtle_teleop_keyView velocity topic data:
xxxxxxxxxxros2 topic echo /turtle1/cmd_vel
7. About Uninstall
After ROS2 is installed, if you want to uninstall ROS2, you can run the following command:
xxxxxxxxxxsudo apt remove ~nros-humble-* && sudo apt autoremoveYou can also delete the ROS2 corresponding repository:
sudo rm /etc/apt/sources.list.d/ros2.listsudo apt updatesudo apt autoremove