Skip to content

Commit a76cc56

Browse files
committed
Update setup_workspace script to install mini-forge, robotstack, required ros packages, and fix portaudio for MacOS
1 parent 8b5bc43 commit a76cc56

File tree

1 file changed

+91
-39
lines changed

1 file changed

+91
-39
lines changed

scripts/setup_workspace.sh

Lines changed: 91 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@
4444
#
4545
# REQUIREMENTS:
4646
# Ubuntu: sudo privileges, apt package manager
47-
# macOS: miniforge/mamba installed (script will guide if missing)
47+
# macOS: internet connection (script installs miniforge automatically if needed)
4848
#
4949
# WHAT IT DOES:
5050
# 1. Detects platform (Ubuntu vs macOS)
51-
# 2. Installs platform-specific dependencies
51+
# 2. Installs platform-specific infrastructure (miniforge, RoboStack, etc.)
5252
# 3. Creates appropriate environment (venv vs conda)
53-
# 4. Installs ROS2 and development tools
54-
# 5. Builds all ROS2 packages in workspace
55-
# 6. Validates the setup
53+
# 4. Installs ROS2 and all required development tools
54+
# 5. Initializes git submodules (DynamixelSDK, hardware interfaces)
55+
# 6. Builds all ROS2 packages in workspace
56+
# 7. Validates the complete setup
5657

5758
set -e # Exit on any error
5859

@@ -184,16 +185,35 @@ detect_platform() {
184185
fi
185186
}
186187

187-
# Check if mamba/conda is available (for macOS)
188+
# Check and install mamba/conda if needed (for macOS)
188189
check_mamba() {
189190
if ! command -v mamba &> /dev/null; then
190191
if ! command -v conda &> /dev/null; then
191-
log_error "Neither mamba nor conda found!"
192-
log_error "Please install miniforge first:"
193-
log_error " curl -L -O https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-$(uname -m).sh"
194-
log_error " bash Miniforge3-MacOSX-$(uname -m).sh"
195-
log_error "Then restart your terminal and run this script again."
196-
exit 1
192+
log_info "Neither mamba nor conda found. Installing miniforge automatically..."
193+
194+
# Download and install miniforge
195+
local installer="Miniforge3-MacOSX-$(uname -m).sh"
196+
local url="https://github.com/conda-forge/miniforge/releases/latest/download/$installer"
197+
198+
log_info "Downloading miniforge installer..."
199+
if ! curl -L -O "$url"; then
200+
log_error "Failed to download miniforge installer"
201+
exit 1
202+
fi
203+
204+
log_info "Installing miniforge..."
205+
if ! bash "$installer" -b -p "$HOME/miniforge3"; then
206+
log_error "Failed to install miniforge"
207+
exit 1
208+
fi
209+
210+
# Clean up installer
211+
rm -f "$installer"
212+
213+
# Initialize conda for the current shell
214+
eval "$($HOME/miniforge3/bin/conda shell.$(basename $SHELL) hook)"
215+
216+
log_success "Miniforge installed successfully"
197217
else
198218
log_warning "conda found but mamba not available. Installing mamba..."
199219
conda install mamba -c conda-forge -y
@@ -243,7 +263,7 @@ setup_ubuntu() {
243263
log_info "Setting up Ubuntu environment..."
244264

245265
# Step 1: Install system dependencies
246-
log_info "[1/5] Installing system dependencies..."
266+
log_info "[1/6] Installing system dependencies..."
247267
sudo apt update
248268
sudo apt install -y \
249269
portaudio19-dev \
@@ -259,7 +279,7 @@ setup_ubuntu() {
259279
software-properties-common
260280

261281
# Step 2: Install ROS2 if not already installed
262-
log_info "[2/5] Setting up ROS2 $ROS_DISTRO..."
282+
log_info "[2/6] Setting up ROS2 $ROS_DISTRO..."
263283
if ! command -v ros2 &> /dev/null; then
264284
log_info "Installing ROS2 $ROS_DISTRO..."
265285

@@ -282,7 +302,7 @@ setup_ubuntu() {
282302
fi
283303

284304
# Step 3: Create Python virtual environment
285-
log_info "[3/5] Setting up Python virtual environment..."
305+
log_info "[3/6] Setting up Python virtual environment..."
286306
VENV_PATH="$REPO_ROOT/$ENV_NAME"
287307

288308
if [ -d "$VENV_PATH" ]; then
@@ -294,7 +314,7 @@ setup_ubuntu() {
294314
fi
295315

296316
# Step 4: Install Python packages
297-
log_info "[4/5] Installing Python packages..."
317+
log_info "[4/6] Installing Python packages..."
298318
source "$VENV_PATH/bin/activate"
299319
pip install --upgrade pip
300320

@@ -305,8 +325,16 @@ setup_ubuntu() {
305325
log_warning "requirements.txt not found, skipping Python package installation"
306326
fi
307327

308-
# Step 5: Build ROS2 packages
309-
log_info "[5/5] Building ROS2 packages..."
328+
# Step 5: Initialize git submodules and build ROS2 packages
329+
log_info "[5/6] Initializing git submodules..."
330+
cd "$REPO_ROOT"
331+
if ! git submodule update --init --recursive; then
332+
log_error "Failed to initialize git submodules"
333+
return 1
334+
fi
335+
log_success "Git submodules initialized successfully"
336+
337+
log_info "[6/6] Building ROS2 packages..."
310338
cd "$REPO_ROOT/coffee_ws"
311339
source /opt/ros/$ROS_DISTRO/setup.bash
312340
colcon build --symlink-install
@@ -393,13 +421,31 @@ install_regular_packages_macos() {
393421

394422
package_name=$(echo "$package" | cut -d'=' -f1 | cut -d'>' -f1 | cut -d'<' -f1)
395423

396-
# Try conda-forge first
397-
if mamba install -c conda-forge "$package_name" -y 2>/dev/null; then
398-
log_info "Installed $package_name via conda"
424+
# Special handling for PyAudio (avoid Homebrew/conda conflicts)
425+
if [[ "$package_name" == "PyAudio" ]]; then
426+
log_info "Installing PyAudio via conda (avoiding Homebrew conflicts)..."
427+
if mamba install -c conda-forge pyaudio -y 2>/dev/null; then
428+
log_success "PyAudio installed via conda"
429+
continue
430+
else
431+
log_warning "PyAudio conda installation failed, trying pip with Homebrew PortAudio..."
432+
# Ensure PortAudio is available via Homebrew
433+
if command -v brew &> /dev/null; then
434+
if ! brew list portaudio &>/dev/null; then
435+
brew install portaudio
436+
fi
437+
fi
438+
pip install "$package"
439+
fi
399440
else
400-
# Fallback to pip
401-
log_info "Installing $package_name via pip..."
402-
pip install "$package"
441+
# Try conda-forge first for other packages
442+
if mamba install -c conda-forge "$package_name" -y 2>/dev/null; then
443+
log_info "Installed $package_name via conda"
444+
else
445+
# Fallback to pip
446+
log_info "Installing $package_name via pip..."
447+
pip install "$package"
448+
fi
403449
fi
404450
done < "$REQUIREMENTS_FILE"
405451
}
@@ -409,7 +455,7 @@ setup_macos() {
409455
log_info "Setting up macOS environment with RoboStack..."
410456

411457
# Step 1: Check mamba installation
412-
log_info "[1/5] Checking mamba installation..."
458+
log_info "[1/6] Checking mamba installation..."
413459
check_mamba
414460
log_success "Mamba is available"
415461

@@ -429,7 +475,7 @@ setup_macos() {
429475
fi
430476

431477
# Step 2: Create conda environment
432-
log_info "[2/5] Setting up conda environment '$ENV_NAME'..."
478+
log_info "[2/6] Setting up conda environment '$ENV_NAME'..."
433479

434480
# Check if already in target environment
435481
local already_in_target_env=false
@@ -458,12 +504,17 @@ setup_macos() {
458504
conda config --env --add channels robostack-$ROS_DISTRO
459505

460506
# Step 3: Install ROS2 and development tools
461-
log_info "[3/5] Installing ROS2 $ROS_DISTRO and development tools..."
507+
log_info "[3/6] Installing ROS2 $ROS_DISTRO and development tools..."
462508
mamba install -y \
463509
ros-$ROS_DISTRO-desktop \
464510
ros-$ROS_DISTRO-xacro \
465511
ros-$ROS_DISTRO-joint-state-publisher-gui \
466512
ros-$ROS_DISTRO-robot-state-publisher \
513+
ros-$ROS_DISTRO-hardware-interface \
514+
ros-$ROS_DISTRO-controller-interface \
515+
ros-$ROS_DISTRO-controller-manager \
516+
ros-$ROS_DISTRO-ros2-control \
517+
ros-$ROS_DISTRO-ros2-controllers \
467518
compilers \
468519
cmake \
469520
pkg-config \
@@ -477,7 +528,7 @@ setup_macos() {
477528
log_success "ROS2 and development tools installed"
478529

479530
# Step 4: Install additional Python packages
480-
log_info "[4/5] Installing additional Python packages..."
531+
log_info "[4/6] Installing additional Python packages..."
481532
if [ -f "$REQUIREMENTS_FILE" ]; then
482533
# Step 4a: Handle git-based packages separately (macOS Homebrew/conda conflict workaround)
483534
handle_git_packages_macos
@@ -494,8 +545,16 @@ setup_macos() {
494545
mamba deactivate
495546
mamba activate "$ENV_NAME"
496547

497-
# Step 5: Build ROS2 packages
498-
log_info "[5/5] Building ROS2 packages..."
548+
# Step 5: Initialize git submodules and build ROS2 packages
549+
log_info "[5/6] Initializing git submodules..."
550+
cd "$REPO_ROOT"
551+
if ! git submodule update --init --recursive; then
552+
log_error "Failed to initialize git submodules"
553+
return 1
554+
fi
555+
log_success "Git submodules initialized successfully"
556+
557+
log_info "[6/6] Building ROS2 packages..."
499558
cd "$REPO_ROOT/coffee_ws"
500559
colcon build --symlink-install
501560
log_success "ROS2 packages built successfully"
@@ -613,15 +672,8 @@ main() {
613672
echo "🎉 Setup complete!"
614673
echo ""
615674
echo "Next steps:"
616-
if [[ "$PLATFORM" == "macos" ]]; then
617-
echo " 1. To activate your development environment:"
618-
echo " mamba activate $ENV_NAME"
619-
echo " cd $REPO_ROOT/coffee_ws"
620-
echo " source install/setup.bash"
621-
else
622-
echo " 1. To activate your development environment:"
623-
echo " source $REPO_ROOT/scripts/activate_workspace.sh $ENV_NAME"
624-
fi
675+
echo " 1. To activate your development environment for daily use:"
676+
echo " source $REPO_ROOT/scripts/activate_workspace.sh"
625677
echo ""
626678
echo " 2. Test your setup:"
627679
echo " ros2 run coffee_voice_agent_ui voice_agent_monitor"

0 commit comments

Comments
 (0)