Skip to content
Snippets Groups Projects
Commit b5d72f5e authored by Montaño Sarria, Andres Felipe's avatar Montaño Sarria, Andres Felipe
Browse files

Tested ros.sh functions

parent 6443a0d8
Branches
No related tags found
No related merge requests found
......@@ -7,6 +7,11 @@ RUN echo "Building devenv for ROS" $ROS_DISTRO "with shell" $EXT_SHELL
# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
# Import the key in order to be able to use the packages from the repository
# RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7E72C5B4111A50084C63C9489E7A9B1D990CF897
# NOV - 2023
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA
# Setup environment
RUN apt-get update && apt-get install -y apt-utils
......@@ -68,9 +73,6 @@ RUN if [ "$EXT_SHELL" = "zsh" ]; \
# Configure system to look for debian packages in the Artifactory repository
COPY auth.conf /etc/apt/auth.conf.d/tecnalia.conf
# Import the key in order to be able to use the packages from the repository
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7E72C5B4111A50084C63C9489E7A9B1D990CF897
RUN curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
# Configure rosdep
......
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# docker common commands
export dockerfiles_path=~/srcs/development_environment/dockerfiles;
......@@ -25,8 +18,7 @@ else
ext=$(basename ${SHELL});
fi
# Build docker image
# usage: dockbuild {noetic, melodic}
# Build a docker image
function dockbuild(){
current_dir=$(pwd)
......@@ -105,6 +97,7 @@ function dockrun() {
case $key in
--ws)
workspace="${HOME}/ros/${container_name}/$3"
export ROS_WORKSPACE=$workspace
shift
shift
;;
......@@ -222,7 +215,7 @@ function dockexec() {
echo "shell: ${docker_shell}${NC}"
# Attach to container
echo "${GREEN}docker exec -it ${container_name} ${docker_shell}${NC}"
docker exec -it ${container_name} ${docker_shell}
docker exec -it ${container_name} ${docker_shell} -c "sc"
else
# Launch container
echo "${RED}Container ${1} does not exist${NC}"
......
......@@ -2,84 +2,106 @@
# ROS aliases and functions
###################################################################
# Define ROS_DISTRO before source ROS on native OS
# if [ -z $ROS_DISTRO ]; then export ROS_DISTRO=noetic; fi
if [[ -z "${ROS_DISTRO}" ]]; then
ROS_DIR=/opt/ros
if [ -d "$ROS_DIR" ];
then
export ROS_DISTRO=$(basename $(find /opt/ros/* -maxdepth 0 -type d | head -1))
else
unset ROS_DISTRO
fi
if [[ "${ROS_DISTRO}" == "noetic" || "${ROS_DISTRO}" == "melodic" ]]; then
export ROS_VERSION=1
else
export ROS_VERSION=2
fi
# Determine shell extension
if [ ! -z $EXT_SHELL ]; then
if [ -z $SHELL ]; then
echo "SHELL not set"
export SHELL=/usr/bin/zsh
ext=$(basename ${SHELL});
else
ext=$(basename ${SHELL});
# Enable colcon tools
if [[ "${ROS_VERSION}" = 2 ]]; then
# Quick directory change
if [[ -f "/usr/share/colcon_cd/function/colcon_cd.sh" ]]; then
source /usr/share/colcon_cd/function/colcon_cd.sh
fi
# Completion
if [[ -f "/usr/share/colcon_argcomplete/hook/colcon-argcomplete.${ext}" ]]; then
source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.${ext}
fi
fi
# Source rosmon
function smon(){
if [[ -f "/opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}" ]]; then
source /opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}
if [[ ${ROS_VERSION} = 1 ]]; then
if [[ -f "/opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}" ]]; then
source /opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}
else
echo "rosmon not found."
fi
fi
}
# cd to the root of the workspace
function roshome(){
if command -v roscd &> /dev/null
if [ "${ROS_VERSION}" = 1 ]
then
roscd && cd ..
ROS_HOME=${PWD}
if command -v roscd &> /dev/null
then
roscd && cd ..
export ROS_HOME=$(pwd)
else
echo "command ** roscd ** not found"
fi
else
echo "command ** roscd ** not found"
if command -v colcon_cd &> /dev/null
then
colcon_cd
else
echo "command ** colcon_cd ** not found"
fi
fi
}
# Source the current workspace
function sourcews(){
current_dir=$(pwd)
cropped=${PWD#${HOME}/ros/${ROS_DISTRO}/}
ws_name=${cropped%%/*}
ws_path=${HOME}/ros/${ROS_DISTRO}/${ws_name}
if [ "${ROS_VERSION}" = 1 ]
then
source ./devel/setup.${ext} && smon
FILE=${ws_path}/devel/setup.${ext}
else
source ./install/setup.${ext}
FILE=${ws_path}/install/setup.${ext}
fi
}
# Source the current workspace
function sourceros(){
source /opt/ros/${ROS_DISTRO}/setup.${ext} && smon
ROS_HOME="/opt/ros/${ROS_DISTRO}/"
# if PWD belongs to ROS workspace then source it
if [[ -f $FILE ]]; then
cd ${ws_path}
echo "${GREEN}Sourcing workspace: ${FILE}${NC}"
source $FILE && smon
cd ${current_dir}
export ROS_HOME=${ws_path}
else
echo "${RED}Workspace not found: ${FILE}${NC}"
fi
}
# Source the current workspace
function sourcethis(){
pwd_st=${PWD}
roshome && sourcews
echo "Sourcing: ${ROS_HOME}"
cd ${pwd_st}
function sourceros(){
source /opt/ros/${ROS_DISTRO}/setup.${ext}
export ROS_HOME="/opt/ros/${ROS_DISTRO}/"
# In ROS 1 source rosmon
if [ "${ROS_VERSION}" = 1 ]
then
smon
fi
}
# Automatic catkin build
function cb() {
pwd_cb=$(pwd)
if [ "${ROS_VERSION}" = 1 ]
then
pwd_cb=${PWD}
roshome
catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release -- "$@"
sourcethis
cd ${pwd_cb}
else
colcon build --parallel-workers 6 "$@"
source ./install/setup.zsh
fi
sourcews
cd ${pwd_cb}
}
# Clean workspace (delete the generated folders, then catkin build)
......@@ -109,23 +131,19 @@ function runci(){
fi
}
# if a new terminal starts in a ws, auto source it (useful for vscode)
if [ -z ${ROS_DISTRO+x} ]; then ;
else
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 PWD belongs to ROS ws then source it
if [[ -f $FILE ]]; then
cd ${WS_path}
source $FILE
cd ${pwd_init}
ROS_HOME=${WS_path}
alias sc=sourcews
# Check if ROS_DISTRO is set.
if [[ -z "${ROS_DISTRO}" ]]; then
ROS_DIR=/opt/ros
if [ -d "$ROS_DIR" ];
then
export ROS_DISTRO=$(basename $(find /opt/ros/* -maxdepth 0 -type d | head -1))
#echo "ROS_DISTRO set to ${ROS_DISTRO}"
else
sourceros
unset ROS_DISTRO
#echo "${YELLOW}ROS is not installed.${NC}"
fi
fi
#alias sc=sourcethis
\ No newline at end of file
else
sourcews
fi
\ No newline at end of file
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Override globalalias config
# space expands all aliases, including global
bindkey -M emacs "^ " globalias
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment