From 7b6e43cbe779b3c6c3edffa13d94c8114ada0047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=A0togl?= Date: Sat, 16 Jan 2021 16:30:31 +0100 Subject: [PATCH] Ported scripts for workspace setup and environment sourcing. --- scripts/_RosTeamWs_Defines.bash | 113 +++++++++++++++++++++++++++++++ scripts/environment/setup.bash | 39 +++++++++++ scripts/setup-ros-workspace.bash | 106 +++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100755 scripts/_RosTeamWs_Defines.bash create mode 100644 scripts/environment/setup.bash create mode 100755 scripts/setup-ros-workspace.bash diff --git a/scripts/_RosTeamWs_Defines.bash b/scripts/_RosTeamWs_Defines.bash new file mode 100755 index 00000000..a0b23f7b --- /dev/null +++ b/scripts/_RosTeamWs_Defines.bash @@ -0,0 +1,113 @@ +## BEGIN: definitions +DEFAULT_ROS_DISTRO="foxy" +DEFAULT_ROS_VERSION=2 + + +# We have two example teams. On is working with industrial and other with mobile robots +TEAM_TEAM_NAMES=("Industrial" "Mobile") + +## END: definitions + + +## BEGIN: Team setup + +setup_ros1_exports () { + +export ROSCONSOLE_FORMAT='[${severity}] [${walltime}: ${logger}] [${node}@${file}.${function}:${line}]: ${message}' +export ROSCONSOLE_CONFIG_FILE='~/workspace/ros_ws/rosconsole.config' + +} + +setup_ros1_aliases () { + + alias cb="catkin build" + +} + + +setup_ros2_exports () { + +export RTI_LICENSE_FILE=/opt/rti.com/rti_connext_dds-5.3.1/rti_license.dat + +# export RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity} {time}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})" +# export RCUTILS_COLORIZED_OUTPUT=1 +# export RCUTILS_LOGGING_USE_STDOUT=1 +#export RCUTILS_LOGGING_BUFFERED_STREAM= + +} + + +setup_ros2_aliases () { + + alias cba="colcon build --symlink-install" + alias cbap="colcon build --symlink-install --packages-select" + #colcon_build() + #{ + # local pkg=\$1 + # colcon build --symlink-install --packages-select \${pkg} + #} + #alias colcon_build="colcon_build \$@" + + # Author: Jordan Palacios + #colcon_run_test() + #{ + # local pkg=\$1 + # colcon build --symlink-install --packages-select \${pkg} && \ + # colcon test --packages-select \${pkg} && \ + # colcon test-result + #} + #alias colcon_run_test=colcon_run_test \$@ + +} + +## END: Team setup + + +## BEGIN: Framework functions + +framework_default_paths () { + ros_distro=$1 + + FRAMEWORK_NAME="ros_team_workspace" + FRAMEWORK_BASE_PATH="/opt/RosTeamWS" + FRAMEWORK_REPO_PATH="$FRAMEWORK_BASE_PATH/ros_ws_$ros_distro" + REMOTE_FRAMEWORK_BASE_PATH="/vol64_remote/IPR-Framework" + REMOTE_FRAMEWORK_PATH="$REMOTE_FRAMEWORK_BASE_PATH/IPR_ros_ws_$ros_distro" + #TODO: use this in the future + SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" + if [ ! -d "$FRAMEWORK_REPO_PATH" ]; then + echo "FRAMEWORK_REPO_PATH: local not found, set to remote..." + FRAMEWORK_REPO_PATH="$REMOTE_FRAMEWORK_PATH/src/intelligent_robotic_automation/scripts" + fi + FRAMEWORK_REPO_PATH="$REMOTE_FRAMEWORK_PATH/src/intelligent_robotic_automation/scripts" +} + +check_ros_distro () { + ros_distro=$1 + if [ -z "$1" ]; then + ros_distro=$DEFAULT_ROS_DISTRO + echo "No ros_distro defined. Using default: '$ros_distro'" + if [ ! -d "/opt/ros/$ros_distro" ]; then + echo "FATAL: ROS '$ros_distro' not installed on this computer! Exiting..." + exit + fi + echo "Press to continue or +C to exit." + read + fi + + if [ ! -d "/opt/ros/$ros_distro" ]; then + echo "FATAL: ROS '$ros_distro' not installed on this computer! Exiting..." + exit + fi + + ros_version=$DEFAULT_ROS_VERSION + if [[ $ros_distro == "foxy" ]]; then + ros_version=2 + elif [[ $ros_distro == "noetic" ]]; then + ros_version=1 + fi + + framework_default_paths $ros_distro +} + +# END: Framework functions diff --git a/scripts/environment/setup.bash b/scripts/environment/setup.bash new file mode 100644 index 00000000..86248bd3 --- /dev/null +++ b/scripts/environment/setup.bash @@ -0,0 +1,39 @@ + +usage='setup-new-package.bash "ros_distro" "ros_ws_suffix" "workspace_folder"' + +# Load Framework defines +script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )" +source $script_own_dir/../_RosTeamWs_Defines.bash + +# ros distribution name will be set in $ros_distro +check_ros_distro $1 + +ws_suffix=$2 +if [ -z "$2" ]; then + ws_suffix="" +else + ws_suffix="_$2" +fi + +ws_folder="$3" +if [ -z "$3" ]; then + ws_folder="workspace" +fi + +if [[ $ros_version == 1 ]]; then + + setup_ros1_exports + setup_ros1_aliases + + source ~/$ws_folder/ros_ws_$ros_distro$ws_suffix/devel/setup.bash + source `rospack find intelligent_robotic_automation`/scripts/environment/ros_setup.bash + +elif [[ $ros_version == 2 ]]; then + + setup_ros2_exports + setup_ros2_aliases + + /opt/rti.com/rti_connext_dds-5.3.1/setenv_ros2rti.bash + # export LANG=de_DE.UTF-8 + source ~/$ws_folder/ros_ws_$ros_distro$ws_suffix/install/setup.bash +fi diff --git a/scripts/setup-ros-workspace.bash b/scripts/setup-ros-workspace.bash new file mode 100755 index 00000000..fb4045d9 --- /dev/null +++ b/scripts/setup-ros-workspace.bash @@ -0,0 +1,106 @@ +#!/bin/bash + +# workspace folder is relative to your home + +usage='Usage: ./setup-ros-workspace.bash "ros_distro" "ros_ws_suffix" "workspace_folder"' + +# Load Framework defines +script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )" +source $script_own_dir/_RosTeamWs_Defines.bash + +# ros distribution name will be set in $ros_distro +check_ros_distro $1 + +ros_ws_suffix="$2" +if [ -z "$2" ]; then + ros_ws_suffix="" + echo "No ros_ws_suffix used..." +fi + +ws_folder="$3" +if [ -z "$3" ]; then + ws_folder="workspace" + echo "Using default '~/workspace' folder to setup ros workspace" +fi + +# TODO: Write this automatically from the user's definitions +echo "Please choose which workspace should be basis for yours:" +echo "(0) " +echo "(1) Industrial" +echo "(2) Mobile" +read choice + +if [ -z "$choice" ]; then + echo "No workspace is chosen! Exiting..." + exit +fi + +case "$choice" in +"1") + base_ws=Industrial + ;; +"2") + base_ws=Mobile + ;; +"0") + base_ws="" + ;; +*) + echo "No workspace chosen! Exiting..." + exit +esac + +# TODO: Add here output of the WS +echo "Creating a new workspace in folder '$ws_folder' for ROS '$ros_distro' (ROS$ros_version) with suffix '$ros_ws_suffix' using '$base_ws' as base workspace. Press to continue..." +read + +# Create and initalise ROS-Workspace +if [[ $base_ws != "" ]]; then + if [[ $ros_version == 1 ]]; then + source $FRAMEWORK_BASE_PATH/${base_ws}_ros_ws_$ros_distro/devel/setup.bash + else + source $FRAMEWORK_BASE_PATH/${base_ws}_ros_ws_$ros_distro/install/setup.bash + fi +fi + +mkdir -p ~/$ws_folder/ros_ws_${ros_distro}_$ros_ws_suffix +cd ~/$ws_folder/ros_ws_${ros_distro}_$ros_ws_suffix + +if [[ $ros_version == 1 ]]; then + wstool init src + catkin config -DCMAKE_BUILD_TYPE=RelwithDebInfo + catkin build +elif [[ $ros_version == 2 ]]; then + mkdir src + colcon build --symlink-install +fi + +cd + +fun_name="RosTeamWS_setup_ros$ros_version" + +cp ~/.bashrc ~/.bashrc.bkp +# Comment out the old configuration is such exists - this is hard if using functions... +sed -i -e '/'"$fun_name"'/ s/^#*/OLD_/' ~/.bashrc +sed -i -e '/alias st_ros'"$ros_version=$fun_name"'/ s/^#*/#/' ~/.bashrc + +echo "" >> ~/.bashrc +echo "$fun_name () {" >> ~/.bashrc +echo " RosTeamWS_BASE_WS=\"$base_ws\"" >> ~/.bashrc +echo " RosTeamWS_DISTRO=$ros_distro" >> ~/.bashrc +echo " RosTeamWS_WS_FOLDER=$ws_folder" >> ~/.bashrc +echo " RosTeamWS_WS_SUFFIX=$ros_ws_suffix" >> ~/.bashrc +echo " source $FRAMEWORK_BASE_PATH/ros_ws_\$RosTeamWS_DISTRO/src/$FRAMEWORK_NAME/scripts/environment/setup.bash \$RosTeamWS_DISTRO \$RosTeamWS_WS_SUFFIX \$RosTeamWS_WS_FOLDER" >> ~/.bashrc +echo "}" >> ~/.bashrc +echo "alias st_ros$ros_version=$fun_name" >> ~/.bashrc + +# Setup new workspace +source ~/.bashrc + +if [[ $ros_version == 1 ]]; then + rosdep update + rospack profile +fi + +echo "------------------------------------------------------" +echo "Fnished: Please open new terminal and execute 'st_ros$ros_version'"