Skip to content

BuildROS2

Anton Deguet edited this page Sep 30, 2024 · 48 revisions

moved to https://dvrk.readthedocs.io

⚠️ ROS 2 broadcasts (a lot)

By default, ROS2 broadcasts messages based on your network mask settings. If you have multiple computers on the same subnet/mask, they will all share the same "space" by default. So if you start 2 instances of the dVRK console they will use the same topics, services, tf names... This is a bit dangerous as you might be controlling someone else's robot by accident. There are multiple ways to handle this but here are two simple solutions that should cover most cases:

  • All your ROS node will be on the same computer and nobody else has nodes running on the same computer, use the local host only approach
  • Your nodes might be spread on multiple computers or there's a chance another user has ROS nodes on any of the computers you're using, domain ID will work (as long as no one uses the same ID)
  • ⚠️ If you use any of the methods below and need to test the results, make sure you stop and restart the ROS 2 daemon after your export/unset since it will cache some of the discovery information: ros2 daemon stop; ros2 daemon start

Local host

You can set a unique ROS Domain ID , either in your own ~/.profile or for all users with /etc/profile.d/ros2.sh.

export ROS_LOCALHOST_ONLY=1

Note that the variable ROS_LOCALHOST_ONLY just has to be defined. Setting it to 0 doesn't turn this feature off, you would have to use unset to disable the local host only broadcast.

Domain ID

You can set a unique ROS Domain ID , either in your own ~/.profile or for all users with /etc/profile.d/ros2.sh.

export ROS_DOMAIN_ID=33

If your organization uses a centralized authentication server (SSO), one can use the Unix user ID to define the ROS Domain ID. Unfortunately the domain ID should be between 0 and 101 (see ROS_DOMAIN_ID) so we can't use the full Unix user Id To automatically set the ROS Domain ID. The following configuration file will generate the domain ID based on the last 2 digits of the user ID. Create or edit the file /etc/profile.d/ros2.sh to contain:

# set domain id based on last 2 digits of user id
export ROS_DOMAIN_ID=$(id -u | rev | cut -c 1-2 | rev)

⚠️ Since this relies on the last two digits of the user ID, there is still a strong possibility 2 users will have the same ROS Domain ID. Make sure you run ros2 node list to check nobody is using your domain.

Usage

Example of session

  • Terminal 1: starting the dVRK main console
    • with a real system:
      source ~/ros2_ws/install/setup.bash
      cd ~/ros2_ws/install/dvrk_config_jhu # we assume each group has created their own configuration file repository!
      ros2 run dvrk_robot dvrk_console_json -j share/jhu-dVRK-Si/console-PSM1.json
    • with a simulated arm:
      source ~/ros2_ws/install/setup.bash
      cd ~/ros2_ws/install/sawIntuitiveResearchKitAll/share/sawIntuitiveResearchKit
      ros2 run dvrk_robot dvrk_console_json -j share/console/console-PSM1_KIN_SIMULATED.json
  • Terminal 2: using a Python test script to make the arm move
    source ~/ros2_ws/install/setup.bash
    ros2 run dvrk_python dvrk_arm_test.py -a PSM1
  • Terminal 3: starting the ROS 2 joint and robot state publishers so we can visualize the arm in RViz
    source ~/ros2_ws/install/setup.bash
    ros2 launch dvrk_model dvrk_state_publisher.launch.py arm:=PSM1
  • Terminal 4: starting RViz
    source ~/ros2_ws/install/setup.bash
    ros2 run rviz2 rviz2 -d ~/ros2_ws/install/dvrk_model/share/dvrk_model/rviz/PSM1.rviz

Note that all the configuration files are installed in the ros2_ws/install directory during the build so you can automatically locate them when you write your own ROS launch files.

Useful commands

  • tf2 to pdf: ros2 run tf2_tools view_frames (then evince frames.pdf to view)
Clone this wiki locally