19.2.5. ROS Installation
In general you can follow the official instruction in the ROS wiki to install ROS under Raspbian Buster on the Raspberry Pi. But the following instructions will use catkin tools
instead of catkin_make
or catkin_make_isolated
.
Note
If you use the 64bit Raspbian, you can follow the Debian standard installation guide and skip everything regarding ros_catkin_ws
.
Workspace Concept
Since ROS is not availabe as binary packages for Raspbian, all the ROS packages have to be installed from source. To not flood our normal Catkin workspace, we create two seperate workspaces.
- ~/ros_catkin_ws
This is the workspace, where the source code of the packages we just want to install lives. We will configure Catkin to install these packages in
/opt/ros/melodic
. This is the directory, where the installation via prebuilt packages would also create its files. It is not very likely you get in touch with this workspace often after the initial installation.- ~/catkin_ws
Your normal workspace directory. All the Hippocampus specific packages should be in here. Also other packages that you want to modify should be in this workspace.
Preparations
Adding keys
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
Update source lists
sudo apt update
Install dependencies
sudo apt install -y python3-rosdep python3-rosinstall-generator python3-vcstool python3-rosinstall build-essential cmake python3-catkin-tools
Initialize rosdep
sudo rosdep init
rosdep update
Setup Workspace
Create workspace
mkdir -p ~/ros_catkin_ws/src && cd ~/ros_catkin_ws
Fetch source code
Attention
The following commands will fetch the sources for the
ros_comm
meta package and theperception
meta package. If you do not need all of them or if you need even more packages feel free to modify the following commands accordingly. Building unnecessary packages might be a waste of time.rosinstall_generator ros_comm perception --rosdistro noetic --deps --wet-only --tar > noetic-ros_comm-perception-wet.rosinstall
vcs import --input noetic-ros_comm-perception-wet.rosinstall ./src
Resolve dependencies
rosdep install -y --from-paths src --ignore-src --rosdistro noetic -r --os=debian:buster
Build the Code
Set the install space
catkin config --install-space /opt/ros/noetic
Use the
install
configuration instead ofdevel
catkin config --install
Start the build process
Note
Depending on your package configuration the next command may take some time, i.e. a few hours if you want to build many packages.
sudo catkin build --cmake-args -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=/usr/bin/python3
Initialize User Workspace
Source your ROS installation
source /opt/ros/noetic/setup.zsh
source /opt/ros/noetic/setup.bash
Create workspace
mkdir -p ~/catkin_ws/src && cd ~/catkin_ws
Initialize workspace
catkin init
Build empty workspace
catkin build
This command created the devel directory inside your catkin workspace. To source your workspace you can either source it manually for each terminal session by executing source ~/catkin_ws/devel/setup.bash
. A better way to handle this automatically is to append this command to your .bashrc
file.
echo 'source $HOME/catkin_ws/devel/setup.zsh' >> ~/.zshrc
echo 'source $HOME/catkin_ws/devel/setup.bash' >> ~/.bashrc
For this change of the .bashrc
to take effect immediately execute:
source ~/.zshrc
source ~/.bashrc
up