5.1.2. ROS 2
5.1.2.1. Ubuntu packages
Install ROS 2 following instructions from www.ros.org. The following packages might not be installed along the ROS desktop but are needed for all ROS distributions:
sudo apt install python-is-python3 # set Python 3 as default Python
sudo apt install python3-vcstool python3-colcon-common-extensions # for colcon
sudo apt install python3-pykdl # for the CRTK Python client library
For cisst/SAW and dVRK, you will also need the following Ubuntu packages:
Ubuntu 24.04 with ROS Jazzy:
sudo apt install libraw1394-dev libncurses5-dev qtcreator swig sox espeak cmake-curses-gui cmake-qt-gui git subversion libcppunit-dev libqt5xmlpatterns5-dev libbluetooth-dev libhidapi-dev python3-pyudev libgraphviz-dev # dVRK
sudo apt install ros-jazzy-joint-state-publisher* ros-jazzy-xacro ros-jazzy-camera-info-manager ros-jazzy-image-transport ros-jazzy-image-transport-plugins # ROS
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libcairo2-dev libjsoncpp-dev python3-opencv python3-numpy libgtk-3-dev libgtkmm-3.0-dev # stereo viewer & data collection
Ubuntu 22.04 with ROS Humble:
sudo apt install libraw1394-dev libncurses5-dev qtcreator swig sox espeak cmake-curses-gui cmake-qt-gui git subversion libcppunit-dev libqt5xmlpatterns5-dev libbluetooth-dev libhidapi-dev python3-pyudev # dVRK
sudo apt install ros-humble-joint-state-publisher* ros-humble-xacro ros-humble-camera-info-manager ros-humble-image-transport ros-humble-image-transport-plugins # ROS
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libcairo2-dev libjsoncpp-dev python3-opencv python3-numpy libgtk-3-dev libgtkmm-3.0-dev # stereo viewer & data collection
Ubuntu 20.04 with ROS Galactic:
sudo apt install libraw1394-dev libncurses5-dev qtcreator swig sox espeak cmake-curses-gui cmake-qt-gui git subversion gfortran libcppunit-dev libqt5xmlpatterns5-dev libbluetooth-dev libhidapi-dev python3-pyudev # dVRK
sudo apt install ros-galactic-joint-state-publisher* ros-galactic-xacro # ROS
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libcairo2-dev libjsoncpp-dev python3-opencv python3-numpy libgtk-3-dev # stereo viewer & data collection
5.1.2.2. Colcon workspace, clone and build
Create your ROS 2 workspace and clone all repositories using vcs:
# this depends on the ROS version you're using
source /opt/ros/jazzy/setup.bash
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
# make sure you use the correct vcs file
vcs import --input https://raw.githubusercontent.com/jhu-saw/vcs/main/ros2-dvrk-main.vcs --recursive
Warning
If you get some errors related to access denied, it is possible GitHub blocks you because vcs uses multiple threads. If this is the case, try something like: vcs import --input https://raw.githubusercontent.com/jhu-saw/vcs/main/ros2-dvrk-main.vcs --recursive --retry 10 --workers 1.
Note
If you forgot the --recursive option, go in ~/ros2_ws/src/cisst-saw/sawRobotIO1394 and run git submodule init; git submodule update (this is to pull the “AmpIO” code).
Hint
To update an existing source directory, simply go in the directory (cd ~/ros2_ws/src) and call vcs pull. This will update all the repositories checked out under src.
To use a specific release, replace the vcs line with:
vcs import --input https://raw.githubusercontent.com/jhu-saw/vcs/main/ros2-dvrk-2.4.0.vcs --recursive
Compile using colcon:
cd ~/ros2_ws
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --symlink-install
source ~/ros2_ws/install/setup.bash
Note
colcon build is not as smart as catkin build: you need
to be in the top directory of your workspace to build (for example
~/ros2_ws). Do not try to build in a subdirectory in your
workspace, colcon will create a new set of build, install
and log directories. catkin build recursively look in
parent directories until it finds the workspace root, colcon
doesn’t.
5.1.2.3. Testing
Environment variables
If you have a single ros2 workspace for a given user account, you
might want to automatically source the setup.bash when you log
in. To do so, you should add the following lines at the end of your
~/.bashrc (hidden file in your home directory):
# for ROS
if [ -f ~/ros2_ws/install/setup.bash ]; then
. ~/ros2_ws/install/setup.bash
fi
Note
There is no need to source cisstvars.sh for ROS 2. It is added
as a hook in the cisst colcon.pkg file.
Examples
Use a ROS launch file to start the dVRK in simulated mode with the patient cart only:
source ~/ros2_ws/install/setup.bash
ros2 launch dvrk_model patient_cart.launch.py generation:=Classic
dVRK with Classic patient cart simulated in RViz
In the dVRK GUI, open the Arm PSM1 tab and select an instrument to use.
In a second terminal, use a Python test script to make an arm move:
source ~/ros2_ws/install/setup.bash
ros2 run dvrk_python dvrk_arm_test.py -a PSM1
The main dVRK ROS node is dvrk_system from
the dvrk_robot. This node requires configuration files specific
to your system.
You can also find more launch examples in the Usage/Simulation section.
Notes
ROS2 will broadcast on your subnet. That means that other computers on the same subnet might send ROS messages you don’t want. Reciprocally, your topics will be broadcasted to others. To prevent this, you can use the environment variables
ROS_AUTOMATIC_DISCOVERY_RANGEorROS_DOMAIN_ID. These are documented on docs.ros.org.