Skip to content

Commit

Permalink
Merge pull request #112 from Caltech-AMBER/patch-obelisk-build-x-vars
Browse files Browse the repository at this point in the history
Patch `OBELISK_BUILD_X` vars for local install
  • Loading branch information
Zolkin1 authored Aug 7, 2024
2 parents ef07bf5 + 4df7673 commit 6af91e2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
42 changes: 38 additions & 4 deletions obelisk/cpp/zoo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,25 @@ add_library(Obelisk::Zoo ALIAS Zoo)
target_include_directories(Zoo INTERFACE include)

# conditionally add leap subdirectory if OBELISK_BUILD_LEAP is set
message(STATUS "OBELISK_BUILD_LEAP: ${OBELISK_BUILD_LEAP}")
if((DEFINED OBELISK_BUILD_LEAP) OR (DEFINED ENV{OBELISK_BUILD_LEAP}))
# Check if both conditions are met using if
if(DEFINED OBELISK_BUILD_LEAP AND OBELISK_BUILD_LEAP STREQUAL "true")
set(LEAP_VAR_CMAKE TRUE)
else()
set(LEAP_VAR_CMAKE FALSE)
endif()

# Check the environment variable using if
if(DEFINED ENV{OBELISK_BUILD_LEAP} AND "$ENV{OBELISK_BUILD_LEAP}" STREQUAL "true")
set(LEAP_VAR_ENV TRUE)
else()
set(LEAP_VAR_ENV FALSE)
endif()

message(STATUS "LEAP_VAR_CMAKE: ${LEAP_VAR_CMAKE}")
message(STATUS "LEAP_VAR_ENV env variable: ${LEAP_VAR_ENV}")
message(STATUS "If either variable is true, the Zed interface will be built.")

if(LEAP_VAR_CMAKE OR LEAP_VAR_ENV)
message(STATUS "Configuring Leap Hand Interface")
add_subdirectory(hardware/robots/leap)
target_include_directories(Zoo INTERFACE hardware/robots/leap)
Expand All @@ -34,8 +51,25 @@ else()
endif()

# conditionally add zed subdirectory if OBELISK_BUILD_ZED is set
message(STATUS "OBELISK_BUILD_ZED: ${OBELISK_BUILD_ZED}")
if((DEFINED OBELISK_BUILD_ZED) OR (DEFINED ENV{OBELISK_BUILD_ZED}))
# Check if both conditions are met using if
if(DEFINED OBELISK_BUILD_ZED AND OBELISK_BUILD_ZED STREQUAL "true")
set(ZED_VAR_CMAKE TRUE)
else()
set(ZED_VAR_CMAKE FALSE)
endif()

# Check the environment variable using if
if(DEFINED ENV{OBELISK_BUILD_ZED} AND "$ENV{OBELISK_BUILD_ZED}" STREQUAL "true")
set(ZED_VAR_ENV TRUE)
else()
set(ZED_VAR_ENV FALSE)
endif()

message(STATUS "ZED_VAR_CMAKE: ${ZED_VAR_CMAKE}")
message(STATUS "ZED_VAR_ENV env variable: ${ZED_VAR_ENV}")
message(STATUS "If either variable is true, the Zed interface will be built.")

if(ZED_VAR_CMAKE OR ZED_VAR_ENV)
message(STATUS "Configuring Zed2 Sensors")
add_subdirectory(hardware/sensing/zed)
target_include_directories(Zoo INTERFACE hardware/sensing/zed)
Expand Down
3 changes: 3 additions & 0 deletions scripts/_source_bash_rc.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo -e "\033[1;32mSourcing .bashrc after updating aliases!\033[0m"
source ${HOME}/.bashrc
18 changes: 14 additions & 4 deletions scripts/build_obelisk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

leap=false
zed=false
verbose=false

for arg in "$@"; do
case $arg in
Expand All @@ -14,17 +15,20 @@ for arg in "$@"; do
zed=true
shift # Adds ZED ROS packages to colcon build command
;;
--verbose)
verbose=true
shift
;;
*)
# Unknown option
echo "Unknown option: $arg"
echo "Usage: $0 [--leap] [--zed]"
echo "Usage: $0 [--leap] [--zed] [--verbose]"
exit 1
;;
esac
done

MESSAGE_PKGS=" obelisk_control_msgs obelisk_estimator_msgs obelisk_sensor_msgs obelisk_std_msgs"

# configuring which packages to skip
SKIP_PKGS=""
if [ "$leap" = false ]; then
Expand All @@ -33,21 +37,27 @@ fi
if [ "$zed" = false ]; then
SKIP_PKGS+=" obelisk_zed_cpp"
fi
VERBOSE_STR=""
if [ "$verbose" = true ]; then
VERBOSE_STR="--event-handlers console_direct+"
fi

# building Obelisk packages
OBELISK_ROOT=$(dirname $(dirname $(readlink -f ${BASH_SOURCE[0]})))

echo -e "\033[1;32mBuilding Obelisk ROS messages...\033[0m"
curr_dir=$(pwd)
cd $OBELISK_ROOT/obelisk_ws

colcon build --symlink-install --parallel-workers $(nproc) \
--packages-select $MESSAGE_PKGS
$VERBOSE_STR --packages-select $MESSAGE_PKGS

# for debugging, add `--event-handlers console_direct+` to the colcon build command
echo -e "\033[1;32mBuilding remainder of Obelisk ROS packages...\033[0m"
source $OBELISK_ROOT/obelisk_ws/install/setup.bash
colcon build --symlink-install --parallel-workers $(nproc) \
--packages-skip $MESSAGE_PKGS $SKIP_PKGS
$VERBOSE_STR --packages-skip $MESSAGE_PKGS $SKIP_PKGS

source $OBELISK_ROOT/obelisk_ws/install/setup.bash
cd $curr_dir

Expand Down
9 changes: 9 additions & 0 deletions scripts/user_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ fi'
if [ "$leap" = true ]; then
OBELISK_BUILD_OPTIONS+="--leap "
OBELISK_BUILD_LEAP=true
else
OBELISK_BUILD_LEAP=false
fi
if [ "$zed" = true ]; then
OBELISK_BUILD_OPTIONS+="--zed "
OBELISK_BUILD_ZED=true
else
OBELISK_BUILD_ZED=false
fi

obk_aliases=$(cat << EOF
Expand Down Expand Up @@ -312,3 +316,8 @@ EOF
else
echo -e "\033[1;33mObelisk aliases not added to ~/.bash_aliases. To add, pass the --obk-aliases flag.\033[0m"
fi

# Only source if the file exists. In the docker build this file does not exists and does not need to be run, so we can skip it.
if test -f ${OBELISK_ROOT}/scripts/_source_bash_rc.bash; then
source ${OBELISK_ROOT}/scripts/_source_bash_rc.bash
fi

0 comments on commit 6af91e2

Please sign in to comment.