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