Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions .obk_aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# >>> obelisk aliases >>>
# !! Contents in this block are managed by obelisk !!

# alias for setting up obelisk global settings in current shell
function obk {
cmd='
export OBELISK_ROOT=$OBELISK_ROOT
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export RCUTILS_COLORIZED_OUTPUT=1
'

# Check if the --permanent flag is passed
if [[ "$1" == "--permanent" ]]; then
sed '/# >>> obk >>>/,/# <<< obk <<</d' ~/.bashrc > ~/.bashrc.tmp && cp ~/.bashrc.tmp ~/.bashrc && rm ~/.bashrc.tmp
echo "# >>> obk >>>" >> ~/.bashrc
echo "$cmd" >> ~/.bashrc
echo "# <<< obk <<<" >> ~/.bashrc
echo -e "\033[1;32mObelisk global settings added to ~/.bashrc!\033[0m"
fi

# Check if the --remove flag is passed
if [[ "$1" == "--remove" ]]; then
sed '/# >>> obk >>>/,/# <<< obk <<</d' ~/.bashrc > ~/.bashrc.tmp && cp ~/.bashrc.tmp ~/.bashrc && rm ~/.bashrc.tmp
echo -e "\033[1;32mObelisk global settings removed from ~/.bashrc!\033[0m"
return
fi

if [[ -z "$HAS_OBK_ACTIVATED" ]]; then
# globally useful obelisk settings
eval "$cmd"

# edits the shell prompt to include [obk] the first time obk is called in this shell
echo -e "\033[1;32mObelisk global settings applied!\033[0m"
BLUE="\[\033[0;34m\]"
RESET="\[\033[0m\]"
PS1="${BLUE}[obk]${RESET} $PS1"
export PS1
export HAS_OBK_ACTIVATED=true
fi

# checks if current shell is a conda or pixi shell - if not, source base ros if /opt/ros/humble/setup.bash exists
# in the case of conda, it will source base ros if $CONDA_DEFAULT_ENV is "base" still
if [[ -z "$CONDA_DEFAULT_ENV" || "$CONDA_DEFAULT_ENV" == "base" ]] && [[ -z "$PIXI_ENVIRONMENT_NAME" ]]; then
if [ -f "/opt/ros/humble/setup.bash" ]; then
echo -e "\033[1;32mSourcing base ROS2 Humble installation...\033[0m"
source /opt/ros/humble/setup.bash
fi
fi

# regardless of whether obk has been run, source the obelisk ros packages
if [ -d "$OBELISK_ROOT/obelisk_ws/install" ]; then
source $OBELISK_ROOT/obelisk_ws/install/setup.bash
else
source $OBELISK_ROOT/scripts/build_obelisk.sh --leap --zed
source $OBELISK_ROOT/obelisk_ws/install/setup.bash
fi
}

# convenience aliases for building/cleaning obelisk source packages
alias obk-build='source $OBELISK_ROOT/scripts/build_obelisk.sh --leap --zed '
alias obk-clean='bash $OBELISK_ROOT/scripts/clean_obelisk.sh'

# convenience aliases for lifecycle commands
function obk-lifecycle {
if [[ -z "$1" || -z "$2" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-lifecycle <node> <state>\033[0m"
return 1
fi
ros2 lifecycle set "$1" "$2"
}

function obk-configure {
if [[ -z "$1" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-configure <config_name>\033[0m"
return 1
fi
obk-lifecycle "$1" configure
}

function obk-activate {
if [[ -z "$1" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-activate <config_name>\033[0m"
return 1
fi
obk-lifecycle "$1" activate
}

function obk-deactivate {
if [[ -z "$1" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-deactivate <config_name>\033[0m"
return 1
fi
obk-lifecycle "$1" deactivate
}

function obk-cleanup {
if [[ -z "$1" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-cleanup <config_name>\033[0m"
return 1
fi
obk-lifecycle "$1" cleanup
}

function obk-shutdown {
if [[ -z "$1" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-shutdown <config_name>\033[0m"
return 1
fi
obk-lifecycle "$1" shutdown
}

function obk-start {
if [[ -z "$1" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-start <config_name>\033[0m"
return 1
fi
obk-lifecycle "$1" configure
}

function obk-stop {
if [[ -z "$1" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-stop <config_name>\033[0m"
return 1
fi
obk-lifecycle "$1" deactivate
obk-lifecycle "$1" cleanup
}

function obk-kill {
if [[ -z "$1" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-kill <config_name>\033[0m"
return 1
fi
obk-lifecycle "$1" shutdown
}

# convenience function for ros2 launch command
function obk-launch {
local config_file_path=""
local device_name=""
local auto_start="True"
local bag="True"

while [[ $# -gt 0 ]]; do
key="$1"
case $key in
config_file_path=*)
config_file_path="${key#*=}"
shift
;;
device_name=*)
device_name="${key#*=}"
shift
;;
auto_start=*)
auto_start="${key#*=}"
shift
;;
bag=*)
bag="${key#*=}"
shift
;;
*)
echo "Unknown option $key"
return 1
;;
esac
done

# Check if any of the required arguments are empty
if [[ -z "$config_file_path" || -z "$device_name" ]]; then
echo -e "\033[1;34mError: Missing required arguments.\033[0m"
echo -e "\033[1;34mUsage: obk-launch config_file_path=<path> device_name=<name> auto_start=<True|False>\033[0m"
return 1
fi

ros2 launch obelisk_ros obelisk_bringup.launch.py config_file_path:=${config_file_path} device_name:=${device_name} auto_start:=${auto_start} bag:=${bag}
}

# help command
alias obk-help='echo -e "\033[1;34m================\nObelisk Commands\n================\nobk:\nSets up global environment variables for Obelisk in the current shell.\nUsage: obk [--permanent|--remove]\nOptions:\n --permanent: Adds the global settings to ~/.bashrc.\n --remove: Removes the global settings from ~/.bashrc.\n\nobk-build:\nBuilds Obelisk nodes after you have activated a pixi environment.\n\nobk-launch:\nLaunches the obelisk_bringup.launch.py with specified arguments.\nUsage: obk-launch config_file_path=<path> device_name=<name> auto_start=<True|False> bag=<True|False>\nExample:\n obk-launch config_file_path=example.yaml device_name=onboard auto_start=True bag=True\n\nState Transitions:\nobk-configure:\n Configure all Obelisk nodes.\n Usage: obk-configure <config_name>\nobk-activate:\n Activate all Obelisk nodes.\n Usage: obk-activate <config_name>\nobk-deactivate:\n Deactivate all Obelisk nodes.\n Usage: obk-deactivate <config_name>\nobk-cleanup:\n Cleanup all Obelisk nodes.\n Usage: obk-cleanup <config_name>\nobk-shutdown:\n Shutdown all Obelisk nodes.\n Usage: obk-shutdown <config_name>\n\nConvenience Commands:\nobk-start:\n Alias for obk-configure.\n Usage: obk-start <config_name>\nobk-stop:\n Alias for obk-deactivate and obk-cleanup.\n Usage: obk-stop <config_name>\nobk-kill:\n Alias for obk-shutdown.\n Usage: obk-kill <config_name>\n\nobk-help:\n Display this help message.\nIn all the above commands, <config_name> refers to the config field of the config file used for launching obelisk.\033[0m"'
# <<< obelisk aliases <<<
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ARG OBELISK_DOCKER_CYCLONE_PERF=false
ARG OBELISK_DOCKER_LEAP=false
ARG OBELISK_DOCKER_ZED=false
ARG OBELISK_DOCKER_PIXI=false
ARG OBELISK_DOCKER_OBK_ALIASES=false

ENV USER=$USER
ENV UID=$UID
Expand All @@ -24,6 +25,7 @@ ENV OBELISK_DOCKER_CYCLONE_PERF=$OBELISK_DOCKER_CYCLONE_PERF
ENV OBELISK_DOCKER_LEAP=$OBELISK_DOCKER_LEAP
ENV OBELISK_DOCKER_ZED=$OBELISK_DOCKER_ZED
ENV OBELISK_DOCKER_PIXI=$OBELISK_DOCKER_PIXI
ENV OBELISK_DOCKER_OBK_ALIASES=$OBELISK_DOCKER_OBK_ALIASES

ENV XDG_RUNTIME_DIR=/run/user/${UID}

Expand Down Expand Up @@ -69,6 +71,7 @@ USER ${UID}
COPY user_setup.sh /tmp/user_setup.sh
RUN FLAGS=""; \
[ "$OBELISK_DOCKER_PIXI" = "true" ] && FLAGS="$FLAGS --pixi"; \
[ "$OBELISK_DOCKER_OBK_ALIASES" = "true" ] && FLAGS="$FLAGS --obk-aliases"; \
source /tmp/user_setup.sh $FLAGS && \
sudo rm /tmp/user_setup.sh

Expand Down
4 changes: 3 additions & 1 deletion docker/docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
GID: $UID
OBELISK_ROOT: $OBELISK_ROOT
OBELISK_DOCKER_PIXI: true
OBELISK_DOCKER_OBK_ALIASES: $OBELISK_DOCKER_OBK_ALIASES
dockerfile: Dockerfile
network_mode: host
ipc: host
Expand All @@ -19,6 +20,7 @@ services:
GID: $UID
OBELISK_ROOT: $OBELISK_ROOT
OBELISK_DOCKER_PIXI: true
OBELISK_DOCKER_OBK_ALIASES: $OBELISK_DOCKER_OBK_ALIASES
QT_X11_NO_MITSHM: 1
security_opt:
- seccomp=unconfined
Expand All @@ -29,7 +31,7 @@ services:
- /tmp/.X11-unix:/tmp/.X11-unix
- $HOME/.Xauthority:$HOME/.Xauthority:rw
- $HOME/.bashrc:$HOME/.bashrc
- $HOME/.bash_aliases:$HOME/.bash_aliases
- $OBELISK_ROOT/obk_aliases.sh:$OBELISK_ROOT/obk_aliases.sh
ports:
- 7007:7007
privileged: true
Expand Down
4 changes: 3 additions & 1 deletion docker/docker-compose-no-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
OBELISK_DOCKER_CYCLONE_PERF: $OBELISK_DOCKER_CYCLONE_PERF
OBELISK_DOCKER_LEAP: $OBELISK_DOCKER_LEAP
OBELISK_DOCKER_PIXI: $OBELISK_DOCKER_PIXI
OBELISK_DOCKER_OBK_ALIASES: $OBELISK_DOCKER_OBK_ALIASES
dockerfile: Dockerfile
network_mode: host
ipc: host
Expand All @@ -25,6 +26,7 @@ services:
OBELISK_DOCKER_CYCLONE_PERF: $OBELISK_DOCKER_CYCLONE_PERF
OBELISK_DOCKER_LEAP: $OBELISK_DOCKER_LEAP
OBELISK_DOCKER_PIXI: $OBELISK_DOCKER_PIXI
OBELISK_DOCKER_OBK_ALIASES: $OBELISK_DOCKER_OBK_ALIASES
QT_X11_NO_MITSHM: 1
security_opt:
- seccomp=unconfined
Expand All @@ -35,7 +37,7 @@ services:
- /tmp/.X11-unix:/tmp/.X11-unix
- $HOME/.Xauthority:$HOME/.Xauthority:rw
- $HOME/.bashrc:$HOME/.bashrc
- $HOME/.bash_aliases:$HOME/.bash_aliases
- $OBELISK_ROOT/obk_aliases.sh:$OBELISK_ROOT/obk_aliases.sh
- $HOME/.gitconfig:$HOME/.gitconfig
- $HOME/.ssh:$HOME/.ssh
ports:
Expand Down
4 changes: 3 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
OBELISK_DOCKER_LEAP: $OBELISK_DOCKER_LEAP
OBELISK_DOCKER_ZED: $OBELISK_DOCKER_ZED
OBELISK_DOCKER_PIXI: $OBELISK_DOCKER_PIXI
OBELISK_DOCKER_OBK_ALIASES: $OBELISK_DOCKER_OBK_ALIASES
dockerfile: Dockerfile
network_mode: host
ipc: host
Expand All @@ -28,6 +29,7 @@ services:
OBELISK_DOCKER_LEAP: $OBELISK_DOCKER_LEAP
OBELISK_DOCKER_ZED: $OBELISK_DOCKER_ZED
OBELISK_DOCKER_PIXI: $OBELISK_DOCKER_PIXI
OBELISK_DOCKER_OBK_ALIASES: $OBELISK_DOCKER_OBK_ALIASES
QT_X11_NO_MITSHM: 1
security_opt:
- seccomp=unconfined
Expand All @@ -38,7 +40,7 @@ services:
- /tmp/.X11-unix:/tmp/.X11-unix
- $HOME/.Xauthority:$HOME/.Xauthority:rw
- $HOME/.bashrc:$HOME/.bashrc
- $HOME/.bash_aliases:$HOME/.bash_aliases
- $OBELISK_ROOT/obk_aliases.sh:$OBELISK_ROOT/obk_aliases.sh
- $HOME/.gitconfig:$HOME/.gitconfig
- $HOME/.ssh:$HOME/.ssh
ports:
Expand Down
Loading