⌚ Time to complete: 3 min

Planned outcomes

You will have a ROS workspace set up, ready to be used for developing and testing robot packages.

Prerequisites

This guide is written for ROS Noetic. Before you proceed, make sure that you have installed ROS Noetic (How to install ROS Noetic).

Steps

  1. Crate a folder for your new ROS workspace (or ws for short):

    WORKSPACE_NAME="ws_unity_x_ros"
    ROS_WS_PATH=~/ros/${WORKSPACE_NAME}
    
    mkdir -p ${ROS_WS_PATH}
    

    <aside> 💡 You can change ROS_WORKSPACE_PATH variable to any path you like. However, we recommend keeping your workspaces inside the corresponding ~/ros/<WORKSPACE_NAME>/ folders to avoid cluttering your home directory.

    </aside>

  2. Initialize a new catkin workspace:

    wstool init ${ROS_WS_PATH}/src
    
  3. Configure the new catkin workspace:

    cd ${ROS_WS_PATH}
    
    # Configure and run initial build to create the folder structure
    catkin config --extend /opt/ros/${ROS_DISTRO} --cmake-args -DCMAKE_BUILD_TYPE=Release
    catkin build
    
  4. Add workspace setup script to your rc file.

    <aside> 💡 This step is optional, but it is recommended if you intend to use this workspace on a regular basis.

    </aside>

    # Define variables
    SHELL_NAME=$(basename $(echo $0))  # gets the name of the current shell automatically
    WS_INIT_ENTRY="# Initialize ROS workspace ('${WORKSPACE_NAME}')
    source ${ROS_WS_PATH}/devel/setup.${SHELL_NAME}"
    RC_FILE_PATH=~/.${SHELL_NAME}rc
    
    # Patch RC file (using grep to make sure that the entry is not duplicated)
    grep -xqF ${WS_INIT_ENTRY} ${RC_FILE_PATH} || echo "\n${WS_INIT_ENTRY}\n" >> ${RC_FILE_PATH}
    
    # Source the RC file
    source ${RC_FILE_PATH}
    
  5. Done! 🎉

Notes

Workspace setup logic taken from MoveIt setup guide:

Getting Started - moveit_tutorials Noetic documentation