Skip to content
Snippets Groups Projects
Select Git revision
  • ea18193c6b003a6761cf450fce0ad33890072e5c
  • main default
2 results

ros.bash

Blame
  • ros.bash 1.68 KiB
    ###################################################################
    # ROS aliases and functions
    ###################################################################
    
    # Define ROS_DISTRO before source ROS
    if [ -z $ROS_DISTRO ]; then export ROS_DISTRO=noetic; fi
    
    # Determine shell extension
    if [ -z $SHELL ]; then echo "SHELL not set"; else ext=$(basename ${SHELL}); fi
    
    # Source rosmon
    function smon(){
        source /opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}
    }
    
    # cd to the root of the workspace
    function roshome(){
        roscd && cd ..
    }
    
    # Source the current workspace
    function sourcews(){
        source ./devel/setup.${ext} && smon
    }
    
    # Source the current workspace
    function sourceros(){
        source /opt/ros/${ROS_DISTRO}/setup.${ext} && smon
    }
    
    # Source the current workspace
    function sourcethis(){
        pwd_st=${PWD}
        roshome && source ./devel/setup.${ext} && smon
        cd ${pwd_st}
    }
    
    # Automatic catkin build
    function cb() {
        pwd_cb=${PWD}
        roshome
        catkin build --summarize "$@"
        sourcethis
        cd ${pwd_cb}
    }
    
    # Clean workspace (delete the generated folders, then catkin build)
    function cbclean(){
        roshome && rm -rf build devel install && catkin build --summarize
    }
    
    # Initialize catkin workspace, configure and build it
    function cib(){
        catkin init && catkin config --extend /opt/ros/${ROS_DISTRO} && catkin build --summarize
    }
    
    # If terminal starts in a ws, auto source it (useful for vscode)
    pwd_init=${PWD}
    cropped=${PWD#${HOME}/ros/${ROS_DISTRO}/}
    WS_name=${cropped%%/*}
    WS_path=${HOME}/ros/${ROS_DISTRO}/${WS_name}
    FILE=${WS_path}/devel/setup.${ext}
    if [[ -f $FILE ]]; then
      cd ${WS_path}
      source $FILE
      cd ${pwd_init}
    else
      source /opt/ros/${ROS_DISTRO}/setup.${ext}
    fi