ROS1 Installation
Main introduction to setting up the ROS1 Noetic version environment.
- It is recommended to perform the following operations based on VNC / NoMachine remote desktop or by connecting a display.
- The ROS environment is built in a Docker container. It is recommended to install and learn how to use Docker first.
- Ubuntu is the officially preferred and primarily supported distribution for ROS. We will build the ROS environment based on Docker's Ubuntu image.
Pull Docker Image
Use the docker pull command to pull the Ubuntu 20.04 Docker image.
docker pull ubuntu:20.04
Write Docker Script
Use a script to start the Ubuntu 20.04 Docker container.
You need to write a startup script ros_noetic.sh:
vi ros_noetic.sh
Add the following content to the ros_noetic.sh script:
#!/bin/bash
xhost +
docker run -it \
--net=host \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--name ros1 \
ubuntu:20.04 /bin/bash
Parameter description:
xhost +: Allow Docker container to access X11 server-it: Run container in interactive mode--net=host: Use host's network stack--env="DISPLAY": Set environment variable for displaying X11 graphical interface--env="QT_X11_NO_MITSHM=1": Set environment variable for Qt application display-v /tmp/.X11-unix:/tmp/.X11-unix: Mount X11 Unix domain socket for displaying X11 graphical interface--name ros1: Specify name for the containerubuntu:20.04: Use Ubuntu 20.04 image/bin/bash: Start Bash shell inside the container
Start Docker Container
Use the bash command to start the script.
bash ros_noetic.sh
Install Noetic
Check Encoding Environment
Ensure that the environment for installing Noetic supports UTF-8 encoding.
locale
If the system encoding format is UTF-8, you can see similar information output in the terminal:
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
If the terminal output information is not UTF-8 encoded, you can enter the following commands in the terminal to install and modify the encoding environment:
apt update && apt install locales
locale-gen en_US en_US.UTF-8
echo "export LANG=en_US.UTF-8" >> ~/.bashrc
source ~/.bashrc
Set Software Sources and Keys
Ensure the system is in the latest environment, then add Tsinghua software sources and keys.
apt update && apt upgrade
apt install lsb-core
sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
Install Noetic
Use the following command to install Noetic full desktop version.
apt update && apt upgrade
apt install ros-noetic-desktop-full -y
Install Dependencies
Use the following command to install Noetic dependency packages.
apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential -y
Initialize rosdep
Use the following command to initialize rosdep.
rosdep init
rosdep update
If rosdep init shows the error ERROR: cannot download default sources list from: https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list Website may be down., visit https://www.ipaddress.com/ to search for the raw.githubusercontent.com domain, and add the resulting IP address to the /etc/hosts file.
vi /etc/hosts
Add the following content:
185.199.110.133 raw.githubusercontent.com
Then re-run the rosdep initialization command.
Set Environment Variables
Use the following command to set environment variables:
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
Verify ROS Environment
Enter the following command in the terminal to verify whether the ROS environment was installed successfully.
roscore
If the installation is successful, you will see similar information output:
... logging to /root/.ros/log/a9473172-5731-11f0-9a87-5acb6b3cedae/roslaunch-rock-4d-spi-27211.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://rock-4d-spi:34861/
ros_comm version 1.17.4
# SUMMARY
PARAMETERS
- /rosdistro: noetic
- /rosversion: 1.17.4
NODES
auto-starting new master
process[master]: started with pid [27219]
ROS_MASTER_URI=http://rock-4d-spi:11311/
setting /run_id to a9473172-5731-11f0-9a87-5acb6b3cedae
process[rosout-1]: started with pid [27229]
started core service [/rosout]
You can use Ctrl + C to stop roscore.
Save Docker Image
Currently, all our modifications are based on the Ubuntu 20.04 Docker container. We need to save this modified container as an image for direct use next time.
Note: If not saved as an image, you will need to reinstall the ROS environment when starting the container next time.
docker commit ros1 ros_noetic:1.0
Parameter description:
ros1: The previously specified container nameros_noetic:1.0: The name of the saved image
Wait for the commit to complete. After completion, you will see similar information output:
sha256:43b559a4d879c83477764730e0af90e8904e8fb8aeeeb9b653967e665bb7a7ca
Modify Startup Script
Modify the startup image in the startup script ros_noetic.sh to the image name just saved:
#!/bin/bash
xhost +
docker run -it \
--net=host \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
ros_noetic:1.0 /bin/bash