Scripts and simulation packaging update

This commit is contained in:
2026-01-01 00:50:28 +00:00
parent b740994185
commit 7a1c4ba227
10 changed files with 750 additions and 570 deletions

View File

@@ -2,35 +2,28 @@
# =============================================================================
# Drone Simulation - macOS Installation Script
# =============================================================================
# Installs ROS 2 Humble via robostack (conda), PyBullet, and dependencies
# Uses a conda environment for all packages
# Installs PyBullet and Python dependencies (Gazebo not supported on macOS)
#
# Usage:
# chmod +x install_macos.sh
# ./install_macos.sh
#
# Tested on: macOS Ventura, Sonoma (Apple Silicon & Intel)
# Usage: ./install_macos.sh
# =============================================================================
set -e # Exit on error
set -e
echo "=============================================="
echo " Drone Simulation - macOS Installation"
echo "=============================================="
echo ""
# Get the script directory and project root
# Get script directory and project root
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
ENV_NAME="drone_simulation"
VENV_DIR="$PROJECT_ROOT/venv"
echo "[INFO] Project root: $PROJECT_ROOT"
# Detect architecture
ARCH=$(uname -m)
echo "[INFO] Detected architecture: $ARCH"
echo "[INFO] Virtual environment: $VENV_DIR"
# -----------------------------------------------------------------------------
# Step 1: Install Homebrew (if not present)
# Step 1: Check Homebrew
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 1/5] Checking Homebrew..."
@@ -38,70 +31,34 @@ echo "[STEP 1/5] Checking Homebrew..."
if ! command -v brew &> /dev/null; then
echo "[INFO] Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH for Apple Silicon
if [[ "$ARCH" == "arm64" ]]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
else
echo "[INFO] Homebrew already installed"
fi
# Update Homebrew
brew update
# -----------------------------------------------------------------------------
# Step 2: Install Miniforge (conda)
# Step 2: Install Python
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 2/5] Installing Miniforge (conda)..."
echo "[STEP 2/5] Installing Python..."
if ! command -v conda &> /dev/null; then
echo "[INFO] Downloading Miniforge..."
if [[ "$ARCH" == "arm64" ]]; then
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh"
bash Miniforge3-MacOSX-arm64.sh -b -p $HOME/miniforge3
rm Miniforge3-MacOSX-arm64.sh
else
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-x86_64.sh"
bash Miniforge3-MacOSX-x86_64.sh -b -p $HOME/miniforge3
rm Miniforge3-MacOSX-x86_64.sh
fi
# Initialize conda
$HOME/miniforge3/bin/conda init zsh bash
# Source conda for this session
source $HOME/miniforge3/etc/profile.d/conda.sh
if ! command -v python3 &> /dev/null; then
brew install python@3.11
else
echo "[INFO] Conda already installed"
# Ensure conda is available in this session
source $(conda info --base)/etc/profile.d/conda.sh
echo "[INFO] Python already installed: $(python3 --version)"
fi
# -----------------------------------------------------------------------------
# Step 3: Create conda environment with ROS 2
# Step 3: Create Virtual Environment
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 3/5] Creating conda environment with ROS 2..."
echo "[STEP 3/5] Creating Python virtual environment..."
# Remove existing environment if present
conda deactivate 2>/dev/null || true
conda env remove -n $ENV_NAME 2>/dev/null || true
if [ -d "$VENV_DIR" ]; then
rm -rf "$VENV_DIR"
fi
# Create new environment
conda create -n $ENV_NAME python=3.11 -y
# Activate environment
conda activate $ENV_NAME
# Add robostack channels
conda config --env --add channels conda-forge
conda config --env --add channels robostack-staging
echo "[INFO] Installing ROS 2 Humble via robostack (this may take a while)..."
conda install ros-humble-desktop ros-humble-geometry-msgs ros-humble-std-msgs -y
python3 -m venv "$VENV_DIR"
echo "[INFO] Virtual environment created at: $VENV_DIR"
# -----------------------------------------------------------------------------
# Step 4: Install Python Dependencies
@@ -109,7 +66,18 @@ conda install ros-humble-desktop ros-humble-geometry-msgs ros-humble-std-msgs -y
echo ""
echo "[STEP 4/5] Installing Python dependencies..."
pip install pybullet pyinstaller
source "$VENV_DIR/bin/activate"
pip install --upgrade pip
if [ -f "$PROJECT_ROOT/requirements.txt" ]; then
echo "[INFO] Installing from requirements.txt..."
pip install -r "$PROJECT_ROOT/requirements.txt"
else
echo "[INFO] Installing packages manually..."
pip install pybullet numpy pillow pyinstaller
fi
echo "[INFO] Python packages installed"
# -----------------------------------------------------------------------------
# Step 5: Create Activation Script
@@ -117,73 +85,54 @@ pip install pybullet pyinstaller
echo ""
echo "[STEP 5/5] Creating activation script..."
ACTIVATE_SCRIPT="$PROJECT_ROOT/activate.sh"
cat > "$ACTIVATE_SCRIPT" << 'EOF'
cat > "$PROJECT_ROOT/activate.sh" << 'EOF'
#!/bin/bash
# =============================================================================
# Drone Competition - Environment Activation Script (macOS)
# =============================================================================
# This script activates the conda environment with ROS 2.
#
# Usage:
# source activate.sh
# =============================================================================
# Drone Simulation - Environment Activation (macOS)
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Initialize conda
if [ -f "$HOME/miniforge3/etc/profile.d/conda.sh" ]; then
source "$HOME/miniforge3/etc/profile.d/conda.sh"
elif [ -f "$(conda info --base)/etc/profile.d/conda.sh" ]; then
source "$(conda info --base)/etc/profile.d/conda.sh"
# Activate Python venv
if [ -f "$SCRIPT_DIR/venv/bin/activate" ]; then
source "$SCRIPT_DIR/venv/bin/activate"
echo "[OK] Python venv activated"
fi
# Activate conda environment
conda activate drone_competition
echo "[OK] Conda environment 'drone_competition' activated"
echo ""
echo "Environment ready! You can now run:"
echo " python simulation_host.py"
echo " python ros_bridge.py"
echo "Environment ready!"
echo ""
echo "Run: python standalone_simulation.py"
echo ""
echo "Note: ROS 2 and Gazebo are not supported on macOS."
echo " Use standalone_simulation.py for the complete experience."
echo ""
EOF
chmod +x "$ACTIVATE_SCRIPT"
echo "[INFO] Created activation script: $ACTIVATE_SCRIPT"
chmod +x "$PROJECT_ROOT/activate.sh"
echo "[INFO] Created: $PROJECT_ROOT/activate.sh"
# -----------------------------------------------------------------------------
# Verification
# -----------------------------------------------------------------------------
echo ""
echo "Verifying installation..."
source "$PROJECT_ROOT/activate.sh"
echo ""
echo "Checking Python packages:"
python3 -c "import pybullet; print(' PyBullet: OK')" || echo " PyBullet: FAILED"
python3 -c "import numpy; print(' NumPy: OK')" || echo " NumPy: FAILED"
python3 -c "from PIL import Image; print(' Pillow: OK')" || echo " Pillow: FAILED"
echo ""
echo "=============================================="
echo " Installation Complete!"
echo "=============================================="
echo ""
echo "Verifying installation..."
echo "Quick start:"
echo " source activate.sh"
echo " python standalone_simulation.py"
echo ""
echo -n " ROS 2: "
ros2 --version 2>/dev/null && echo "" || echo "FAILED"
echo -n " PyBullet: "
python3 -c "import pybullet; print('OK')" 2>/dev/null || echo "FAILED"
echo -n " rclpy: "
python3 -c "import rclpy; print('OK')" 2>/dev/null || echo "FAILED"
echo -n " PyInstaller: "
python3 -c "import PyInstaller; print('OK')" 2>/dev/null || echo "FAILED"
echo ""
echo "=============================================="
echo " IMPORTANT: Activate the environment first!"
echo "=============================================="
echo ""
echo "Before running any scripts, activate the environment:"
echo " source $ACTIVATE_SCRIPT"
echo ""
echo "Then run the simulation:"
echo " python simulation_host.py"
echo "With moving rover:"
echo " python standalone_simulation.py --pattern circular --speed 0.3"
echo ""