Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save zhaoyanpeng/718bd874d7a44854b929b639c5cb2bdc to your computer and use it in GitHub Desktop.

Select an option

Save zhaoyanpeng/718bd874d7a44854b929b639c5cb2bdc to your computer and use it in GitHub Desktop.

Install ROS1-Noetic and ROS2-Humble from Source on Unubtu 22.04 Jammy

ATTENTION: Please use the default system-wide compiler tools like cmake, gcc, g++, and python, deactivate all conda/mamba environments, and remove all customized $PATH; otherwise, the compiler cmake may complain that necessary headers and libraries are missing, for example, "Could NOT find boost," "Compatibility with CMake < 3.5 has been removed from CMake," and "/usr/include/pybind11/detail/common.h:215:10: fatal error: Python.h: No such file or directory."

ROS2-Humble [REF]

There should not be any issues if you have been following the tutorial on a fresh OS, but there might be some pitfalls casued by your OS setups.

If it complains "Unable to locate package python3-rosdep" when installing development tools and ROS tools, simply change python3-rosdep to python3-rosdep2.

I followed this tutorial to get the code of ROS2 Humble and install dependencies using rosdep. Append --os=ubuntu:jammy to the rosdep install command if you receive an error message like Unsupported OS [mint].

Building the code relies on Numpy, so if you wanna use the latest Numpy, upgrade it before running colcon build. If it complains fatal error: Python.h: No such file or directory, locate the header by running locate Python.h (which outputs /usr/include/python3.10/Python.h on my machine), and append it to CPATH:

export CPATH=/usr/include/python3.10:$CPATH

If it complains some libraries are missing, you can similarly specify them by:

export LD_LIBRARY_PATH=/path/to/your/lib:$LD_LIBRARY_PATH

See this post on python3-config.

I have ROS2 installed in ~/bin/ros2_humble, it contains these new folders after building build/, install/, log/, src/. We are not rushing to test it; we will do that after installing ROS1-Noetic and ros1_bridge.

ROS1-Noetic [REF]

First, let's prepare the Python env. by running pip install catkin_pkg colorama, then I followed the tutorial until Sec 2. My setups slightly deviates the post in the ROS1 version.

If you have installed hddtemp but still can not fix the error 'diagnostic_common_diagnostics: [hddtemp] defined as "not available" for OS version [*]', try 'sudo apt-get purge *hddtemp*' and reinstall it.

If you encounter error messages like this:

The following packages have unmet dependencies:
 ros-core-dev : Depends: catkin but it is not installable
E: Unable to correct problems, you have held broken packages.

Just purge it by running sudo apt-get purge *catkin*.

The source code i used was desktop_full (cf. desktop):

rosinstall_generator desktop_full --rosdistro noetic --deps --tar > noetic-desktop-full.rosinstall
mkdir ./src
vcs import --input noetic-desktop-full.rosinstall ./src

Then install dependencies

rosdep install --from-paths ./src --ignore-packages-from-source --rosdistro noetic -y --os=ubuntu:jammy

Note that I appended --os=ubuntu:jammy to avoid potential errors.

Finally, I can build locally as:

./src/catkin/bin/catkin_make_isolated -DCMAKE_BUILD_TYPE=Release

Fix potential errors

It will complain 'Compatibility with CMake < 3.5 has been removed from CMake' if your cmake version is too high; in that case, append '-DCMAKE_POLICY_VERSION_MINIMUM=3.5.' You can also append 'DPYTHON_EXECUTABLE=/usr/bin/python3' to specify the Python you wanna use, and '-DCMAKE_CXX_FLAGS="-I /usr/include"' to include necessary headers.

Fix the rosconsole error

Outside the src folder, run these commands:

wget https://raw.githubusercontent.com/ros/rosconsole/9f930c007dd40aa7ede771b8859b529e024d7bfb/src/rosconsole/impl/rosconsole_log4cxx.cpp -O src/rosconsole/src/rosconsole/impl/rosconsole_log4cxx.cpp
wget https://raw.githubusercontent.com/ros/rosconsole/9f930c007dd40aa7ede771b8859b529e024d7bfb/test/thread_test.cpp -O src/rosconsole/test/thread_test.cpp
wget https://raw.githubusercontent.com/ros/rosconsole/9f930c007dd40aa7ede771b8859b529e024d7bfb/test/utest.cpp -O src/rosconsole/test/utest.cpp

Fix the std::share_mutex error

If you encounter error messages like this:

/usr/include/log4cxx/boost-std-configuration.h:10:18: error: ‘shared_mutex’ in namespace ‘std’ does not name a type
/usr/include/log4cxx/boost-std-configuration.h:10:18: note: ‘std::shared_mutex’ is only available from C++17 onwards 10 | typedef std::shared_mutex shared_mutex...

Modify the header

sudo vi /usr/include/log4cxx/boost-std-configuration.h

and change

#define STD_SHARED_MUTEX_FOUND 1
#define Boost_SHARED_MUTEX_FOUND 0

into

#define STD_SHARED_MUTEX_FOUND 0
#define Boost_SHARED_MUTEX_FOUND 1

I have ROS21installed in ~/bin/ros1_noetic, it contains these new folders after building
devel_isolated/, devel_isolated/, src/. We will test it after installing ros1_bridge.

ros1_bridge [REF]

First, i will define two env. variables indicating the installation paths of ROS1 and ROS2

export ROS1_INSTALL_PATH=~/bin/ros1_noetic/devel_isolated
export ROS2_INSTALL_PATH=~/bin/ros2_humble/install

Since I have installed ROS1 and ROS2, I can start out with cloning the source:

mkdir -p ~/bin/ros1_bridge/src & cd ~/bin/ros1_bridge/src
git clone https://github.com/ros2/ros1_bridge
cd ~/bin/ros1_bridge

and building it following the referred tutorial:

source ${ROS1_INSTALL_PATH}/setup.bash
source ${ROS2_INSTALL_PATH}/setup.bash
colcon build --symlink-install --packages-select ros1_bridge --cmake-force-configure

Play with some examples

check the link!

A specific use case

Actually, I do not have to install ROS2 and ROS1 bridge at all; all I need is ROS1, as in my case, I have ROS1 running on a machine A (Ubuntu 20.04) attached to a robot, and a machine B (Ubuntu 22.04 Server). I wanna run a policy model on B and get observations from A and send back predicted actions to control the robot. So all I need is to wire up A and B (or using wireless connection).

Machine A has its IPv4 manually set to

Address: 192.168.1.1 Netmask: 255.255.255.0 Gateway: 192.168.1.1

and IPv4 of machine B is manually set to

Address: 192.168.1.2 Netmask: 255.255.255.0 Gateway: 192.168.1.1

One ROS node (machine A) is set as (see NetworkSetup):

export ROS_IP=192.168.1.2
export ROS_HOSTNAME=$ROS_IP
export ROS_MASTER_URI=http://$ROS_IP:11311

and the other node (machine B) is set as:

export ROS_IP=192.168.1.1
export ROS_HOSTNAME=$ROS_IP
export ROS_STUDENT_IP=192.168.1.2
export ROS_MASTER_URI=http://$ROS_STUDENT_IP:11311

You can test it by starting roscore and A and publishing some topics, which are visible on B when you run rostopic list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment