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 ""

View File

@@ -2,23 +2,19 @@
# =============================================================================
# Drone Simulation - Ubuntu/Debian Installation Script
# =============================================================================
# Installs ROS 2 Humble/Jazzy, PyBullet, and all required dependencies
# Uses a Python virtual environment for pip packages (PEP 668 compliant)
# Installs ROS 2, Gazebo, PyBullet, and all required dependencies
#
# Usage:
# chmod +x install_ubuntu.sh
# ./install_ubuntu.sh
#
# Tested on: Ubuntu 22.04 LTS, Ubuntu 24.04 LTS
# Usage: ./install_ubuntu.sh
# =============================================================================
set -e # Exit on error
set -e
echo "=============================================="
echo " Drone Simulation - Ubuntu 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")"
VENV_DIR="$PROJECT_ROOT/venv"
@@ -27,71 +23,87 @@ echo "[INFO] Project root: $PROJECT_ROOT"
echo "[INFO] Virtual environment: $VENV_DIR"
# Detect Ubuntu version
UBUNTU_VERSION=$(lsb_release -rs)
echo "[INFO] Detected Ubuntu version: $UBUNTU_VERSION"
# Determine ROS 2 distribution based on Ubuntu version
if [[ "$UBUNTU_VERSION" == "22.04" ]]; then
ROS_DISTRO="humble"
elif [[ "$UBUNTU_VERSION" == "24.04" ]]; then
ROS_DISTRO="jazzy"
if [ -f /etc/os-release ]; then
. /etc/os-release
UBUNTU_VERSION=$VERSION_ID
echo "[INFO] Detected: $NAME $VERSION_ID"
else
echo "[WARN] Ubuntu $UBUNTU_VERSION may not be officially supported."
echo " Attempting to install ROS 2 Humble..."
echo "[WARN] Could not detect Ubuntu version, assuming 22.04"
UBUNTU_VERSION="22.04"
fi
# -----------------------------------------------------------------------------
# Step 1: System Dependencies
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 1/8] Installing system dependencies..."
sudo apt-get update
sudo apt-get install -y \
curl \
gnupg \
lsb-release \
software-properties-common \
python3 \
python3-pip \
python3-venv \
git
echo "[INFO] System dependencies installed"
# -----------------------------------------------------------------------------
# Step 2: ROS 2 Repository Setup
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 2/8] Setting up ROS 2 repository..."
# Add ROS 2 GPG key
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
# Determine ROS 2 distro based on Ubuntu version
if [ "$UBUNTU_VERSION" = "24.04" ]; then
ROS_DISTRO="jazzy"
elif [ "$UBUNTU_VERSION" = "22.04" ]; then
ROS_DISTRO="humble"
else
echo "[WARN] Ubuntu $UBUNTU_VERSION not officially supported, trying humble"
ROS_DISTRO="humble"
fi
echo "[INFO] Will install ROS 2 $ROS_DISTRO"
echo "[INFO] Using ROS 2 $ROS_DISTRO"
# -----------------------------------------------------------------------------
# Step 1: Set Locale
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 1/7] Setting locale..."
sudo apt update && sudo apt install -y locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
# -----------------------------------------------------------------------------
# Step 2: Add ROS 2 Repository
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 2/7] Adding ROS 2 apt repository..."
sudo apt install -y software-properties-common
sudo add-apt-repository -y universe
sudo apt update && sudo apt install -y curl
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key \
-o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" \
| sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
# Add repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
# -----------------------------------------------------------------------------
# Step 3: Install ROS 2
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 3/8] Installing ROS 2 $ROS_DISTRO..."
sudo apt update
sudo apt install -y ros-${ROS_DISTRO}-desktop
# Install development tools
sudo apt install -y python3-colcon-common-extensions python3-rosdep
sudo apt-get update
sudo apt-get install -y ros-${ROS_DISTRO}-ros-base ros-${ROS_DISTRO}-geometry-msgs ros-${ROS_DISTRO}-std-msgs ros-${ROS_DISTRO}-nav-msgs ros-${ROS_DISTRO}-sensor-msgs
# Install Gazebo and ROS-Gazebo bridge
echo "[INFO] Installing Gazebo and ros_gz_bridge..."
sudo apt install -y ros-${ROS_DISTRO}-ros-gz ros-${ROS_DISTRO}-ros-gz-bridge
echo "[INFO] ROS 2 $ROS_DISTRO installed"
# -----------------------------------------------------------------------------
# Step 4: Initialize rosdep
# Step 4: Install Gazebo (optional)
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 4/8] Initializing rosdep..."
if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then
sudo rosdep init
echo "[STEP 4/8] Installing Gazebo..."
if [ "$ROS_DISTRO" = "jazzy" ]; then
GZ_VERSION="harmonic"
else
GZ_VERSION="fortress"
fi
rosdep update
sudo apt-get install -y ros-${ROS_DISTRO}-ros-gz || {
echo "[WARN] Could not install ros-gz, Gazebo simulation will not be available"
echo "[INFO] PyBullet simulation will still work"
}
echo "[INFO] Gazebo installation complete"
# -----------------------------------------------------------------------------
# Step 5: Create Python Virtual Environment
@@ -99,35 +111,34 @@ rosdep update
echo ""
echo "[STEP 5/8] Creating Python virtual environment..."
# Install venv package if not present
sudo apt install -y python3-venv python3-full
# Remove existing venv if present
if [ -d "$VENV_DIR" ]; then
rm -rf "$VENV_DIR"
fi
# Create virtual environment with access to system site-packages
# This allows access to ROS 2 packages installed via apt
python3 -m venv "$VENV_DIR" --system-site-packages
# Create virtual environment
python3 -m venv "$VENV_DIR"
echo "[INFO] Virtual environment created at: $VENV_DIR"
# -----------------------------------------------------------------------------
# Step 6: Install Python Dependencies in venv
# Step 6: Install Python Dependencies
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 6/8] Installing Python dependencies in virtual environment..."
echo "[STEP 6/8] Installing Python dependencies..."
# Activate venv and install packages
source "$VENV_DIR/bin/activate"
# Upgrade pip
pip install --upgrade pip
# Install from requirements.txt if it exists
if [ -f "$PROJECT_ROOT/requirements.txt" ]; then
echo "[INFO] Installing from requirements.txt..."
pip install -r "$PROJECT_ROOT/requirements.txt"
else
pip install pybullet pyinstaller
echo "[INFO] Installing packages manually..."
pip install pybullet numpy pillow pyinstaller
fi
echo "[INFO] Python packages installed in venv"
echo "[INFO] Python packages installed"
# -----------------------------------------------------------------------------
# Step 7: Create Activation Script
@@ -135,81 +146,67 @@ echo "[INFO] Python packages installed in venv"
echo ""
echo "[STEP 7/8] 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
# =============================================================================
# This script activates both ROS 2 and the Python virtual environment.
#
# Usage:
# source activate.sh
# =============================================================================
# Drone Simulation - Environment Activation
# Get the directory where this script is located
SCRIPT_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source ROS 2
source /opt/ros/${ROS_DISTRO}/setup.bash
echo "[OK] ROS 2 ${ROS_DISTRO} sourced"
if [ -f "/opt/ros/jazzy/setup.bash" ]; then
source /opt/ros/jazzy/setup.bash
echo "[OK] ROS 2 jazzy sourced"
elif [ -f "/opt/ros/humble/setup.bash" ]; then
source /opt/ros/humble/setup.bash
echo "[OK] ROS 2 humble sourced"
else
echo "[WARN] ROS 2 not found - standalone_simulation.py will work"
fi
# Activate Python virtual environment
source "\$SCRIPT_DIR/venv/bin/activate"
echo "[OK] Python venv activated"
# Activate Python venv
if [ -f "$SCRIPT_DIR/venv/bin/activate" ]; then
source "$SCRIPT_DIR/venv/bin/activate"
echo "[OK] Python venv activated"
fi
# Set Gazebo model path
export GZ_SIM_RESOURCE_PATH="$SCRIPT_DIR/gazebo/models:$GZ_SIM_RESOURCE_PATH"
echo ""
echo "Environment ready! You can now run:"
echo " python simulation_host.py # PyBullet"
echo " python gazebo_bridge.py # Gazebo"
echo " python ros_bridge.py"
echo "Environment ready! Run one of:"
echo " python standalone_simulation.py (No ROS 2 required)"
echo " python simulation_host.py (With ROS 2)"
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
# Step 8: Verification
# -----------------------------------------------------------------------------
echo ""
echo "[STEP 8/8] 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 ""
# Ensure we're in venv
source "$VENV_DIR/bin/activate"
source /opt/ros/${ROS_DISTRO}/setup.bash
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 " geometry_msgs: "
python3 -c "from geometry_msgs.msg import Twist; print('OK')" 2>/dev/null || echo "FAILED"
echo -n " std_msgs: "
python3 -c "from std_msgs.msg import String; 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 "Or with ROS 2:"
echo " python simulation_host.py # Terminal 1"
echo " python ros_bridge.py # Terminal 2"
echo " python controllers.py # Terminal 3"
echo ""

View File

@@ -1,15 +1,13 @@
# =============================================================================
# Drone Simulation - Windows Installation Script (PowerShell)
# =============================================================================
# Installs ROS 2 Humble, PyBullet, and all required dependencies
# Uses a Python virtual environment for pip packages
# Installs PyBullet and Python dependencies
# ROS 2 is optional (complex setup, not required for standalone mode)
#
# Usage:
# 1. Open PowerShell as Administrator
# 2. Run: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# 3. Run: .\install_windows.ps1
#
# Tested on: Windows 10/11
# =============================================================================
Write-Host "==============================================" -ForegroundColor Cyan
@@ -29,14 +27,12 @@ Write-Host "[INFO] Virtual environment: $VenvDir" -ForegroundColor Gray
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "[WARN] Not running as Administrator. Some installations may fail." -ForegroundColor Yellow
Write-Host " Consider running PowerShell as Administrator." -ForegroundColor Yellow
Write-Host ""
}
# Function to refresh environment PATH
function Refresh-Path {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# Also add common Chocolatey paths
$chocoPath = "$env:ProgramData\chocolatey\bin"
if (Test-Path $chocoPath) {
$env:Path = "$chocoPath;$env:Path"
@@ -46,14 +42,14 @@ function Refresh-Path {
# -----------------------------------------------------------------------------
# Step 1: Install Chocolatey (Package Manager)
# -----------------------------------------------------------------------------
Write-Host "[STEP 1/7] Checking Chocolatey..." -ForegroundColor Green
Write-Host "[STEP 1/5] Checking Chocolatey..." -ForegroundColor Green
$chocoInstalled = $false
try {
$chocoVersion = choco --version 2>$null
if ($chocoVersion) {
$chocoInstalled = $true
Write-Host "[INFO] Chocolatey already installed (version $chocoVersion)" -ForegroundColor Green
Write-Host "[INFO] Chocolatey already installed" -ForegroundColor Green
}
} catch {
$chocoInstalled = $false
@@ -67,23 +63,10 @@ if (-not $chocoInstalled) {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# Refresh environment to find choco
Refresh-Path
# Verify installation
$chocoPath = "$env:ProgramData\chocolatey\bin\choco.exe"
if (Test-Path $chocoPath) {
Write-Host "[INFO] Chocolatey installed successfully" -ForegroundColor Green
} else {
Write-Host "[ERROR] Chocolatey installation failed. Please install manually:" -ForegroundColor Red
Write-Host " https://chocolatey.org/install" -ForegroundColor Yellow
Write-Host "[INFO] After installing Chocolatey, close and reopen PowerShell, then run this script again." -ForegroundColor Yellow
exit 1
}
Write-Host "[INFO] Chocolatey installed" -ForegroundColor Green
} catch {
Write-Host "[ERROR] Failed to install Chocolatey: $_" -ForegroundColor Red
Write-Host "[INFO] Please install Chocolatey manually: https://chocolatey.org/install" -ForegroundColor Yellow
exit 1
Write-Host "[WARN] Chocolatey installation failed, continuing..." -ForegroundColor Yellow
}
}
@@ -91,7 +74,7 @@ if (-not $chocoInstalled) {
# Step 2: Install Python
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "[STEP 2/7] Installing Python..." -ForegroundColor Green
Write-Host "[STEP 2/5] Checking Python..." -ForegroundColor Green
$pythonInstalled = $false
try {
@@ -107,241 +90,137 @@ try {
if (-not $pythonInstalled) {
Write-Host "[INFO] Installing Python 3.11..." -ForegroundColor Yellow
# Use full path to choco if needed
$chocoExe = "$env:ProgramData\chocolatey\bin\choco.exe"
if (Test-Path $chocoExe) {
& $chocoExe install python311 -y
} else {
choco install python311 -y
Write-Host "[ERROR] Please install Python 3.11 manually from https://python.org" -ForegroundColor Red
exit 1
}
Refresh-Path
# Verify
try {
$pythonVersion = python --version
Write-Host "[INFO] Python installed ($pythonVersion)" -ForegroundColor Green
} catch {
Write-Host "[ERROR] Python installation failed" -ForegroundColor Red
Write-Host "[INFO] Please install Python 3.11 manually from https://python.org" -ForegroundColor Yellow
exit 1
}
}
# -----------------------------------------------------------------------------
# Step 3: Install Visual C++ Build Tools (optional but recommended)
# Step 3: Create Python Virtual Environment
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "[STEP 3/7] Checking Visual C++ Build Tools..." -ForegroundColor Green
Write-Host "[STEP 3/5] Creating Python virtual environment..." -ForegroundColor Green
# Check if cl.exe exists (Visual C++ compiler)
$vsInstalled = $false
$vsPaths = @(
"C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC",
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC",
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC"
)
foreach ($path in $vsPaths) {
if (Test-Path $path) {
$vsInstalled = $true
Write-Host "[INFO] Visual C++ Build Tools found" -ForegroundColor Green
break
}
}
if (-not $vsInstalled) {
Write-Host "[INFO] Visual C++ Build Tools not found" -ForegroundColor Yellow
Write-Host "[INFO] Attempting to install (this may take 10-20 minutes)..." -ForegroundColor Yellow
try {
$chocoExe = "$env:ProgramData\chocolatey\bin\choco.exe"
if (Test-Path $chocoExe) {
& $chocoExe install visualstudio2022-workload-vctools -y
} else {
choco install visualstudio2022-workload-vctools -y
}
Write-Host "[INFO] Visual C++ Build Tools installed" -ForegroundColor Green
} catch {
Write-Host "[WARN] Could not install Visual C++ Build Tools automatically" -ForegroundColor Yellow
Write-Host "[INFO] PyBullet may fail to install. If it does, install Visual Studio Build Tools manually:" -ForegroundColor Yellow
Write-Host " https://visualstudio.microsoft.com/visual-cpp-build-tools/" -ForegroundColor Yellow
}
}
# -----------------------------------------------------------------------------
# Step 4: Download and Install ROS 2
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "[STEP 4/7] Installing ROS 2 Humble..." -ForegroundColor Green
$ros2Path = "C:\dev\ros2_humble"
if (-not (Test-Path $ros2Path)) {
Write-Host "[INFO] Downloading ROS 2 Humble..." -ForegroundColor Yellow
# Create installation directory
New-Item -ItemType Directory -Force -Path "C:\dev" | Out-Null
# Download ROS 2 binary
$ros2Url = "https://github.com/ros2/ros2/releases/download/release-humble-20240523/ros2-humble-20240523-windows-release-amd64.zip"
$ros2Zip = "$env:TEMP\ros2-humble.zip"
Write-Host "[INFO] This may take a while (1-2 GB download)..." -ForegroundColor Yellow
try {
# Use BITS for more reliable download
Start-BitsTransfer -Source $ros2Url -Destination $ros2Zip -DisplayName "Downloading ROS 2"
} catch {
# Fallback to Invoke-WebRequest
Write-Host "[INFO] Using alternative download method..." -ForegroundColor Yellow
Invoke-WebRequest -Uri $ros2Url -OutFile $ros2Zip
}
Write-Host "[INFO] Extracting ROS 2..." -ForegroundColor Yellow
Expand-Archive -Path $ros2Zip -DestinationPath "C:\dev" -Force
Remove-Item $ros2Zip
Write-Host "[INFO] ROS 2 installed to $ros2Path" -ForegroundColor Green
} else {
Write-Host "[INFO] ROS 2 already installed at $ros2Path" -ForegroundColor Green
}
# -----------------------------------------------------------------------------
# Step 5: Create Python Virtual Environment
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "[STEP 5/7] Creating Python virtual environment..." -ForegroundColor Green
# Remove existing venv if present
if (Test-Path $VenvDir) {
Remove-Item -Recurse -Force $VenvDir
}
# Create virtual environment
python -m venv $VenvDir
Write-Host "[INFO] Virtual environment created at: $VenvDir" -ForegroundColor Green
Write-Host "[INFO] Virtual environment created" -ForegroundColor Green
# -----------------------------------------------------------------------------
# Step 6: Install Python Dependencies in venv
# Step 4: Install Python Dependencies
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "[STEP 6/7] Installing Python dependencies in virtual environment..." -ForegroundColor Green
Write-Host "[STEP 4/5] Installing Python dependencies..." -ForegroundColor Green
# Activate venv and install packages
& "$VenvDir\Scripts\Activate.ps1"
python -m pip install --upgrade pip
$requirementsFile = Join-Path $ProjectRoot "requirements.txt"
if (Test-Path $requirementsFile) {
Write-Host "[INFO] Installing from requirements.txt..." -ForegroundColor Gray
pip install -r $requirementsFile
} else {
pip install pybullet pyinstaller pillow
Write-Host "[INFO] Installing packages manually..." -ForegroundColor Gray
pip install pybullet
pip install numpy
pip install pillow
pip install pyinstaller
}
Write-Host "[INFO] Python packages installed in venv" -ForegroundColor Green
Write-Host "[INFO] Python packages installed" -ForegroundColor Green
# -----------------------------------------------------------------------------
# Step 7: Create Activation Script
# Step 5: Create Activation Scripts
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "[STEP 7/7] Creating activation scripts..." -ForegroundColor Green
Write-Host "[STEP 5/5] Creating activation scripts..." -ForegroundColor Green
# Create batch file for cmd.exe
$activateBat = Join-Path $ProjectRoot "activate.bat"
@"
@echo off
REM =============================================================================
REM Drone Simulation - Environment Activation Script (Windows CMD)
REM =============================================================================
REM Usage: activate.bat
REM =============================================================================
REM Drone Simulation - Environment Activation (Windows CMD)
echo Activating ROS 2 Humble...
call C:\dev\ros2_humble\local_setup.bat
echo Activating Python virtual environment...
call "%~dp0venv\Scripts\activate.bat"
echo.
echo [OK] Environment ready! You can now run:
echo python simulation_host.py
echo python ros_bridge.py
echo python controllers.py
echo [OK] Environment ready!
echo.
echo Run: python standalone_simulation.py
echo.
"@ | Out-File -FilePath $activateBat -Encoding ASCII
# Create PowerShell script
$activatePs1 = Join-Path $ProjectRoot "activate.ps1"
@"
# =============================================================================
# Drone Simulation - Environment Activation Script (Windows PowerShell)
# =============================================================================
# Drone Simulation - Environment Activation (Windows PowerShell)
# Usage: . .\activate.ps1
# =============================================================================
`$ScriptDir = Split-Path -Parent `$MyInvocation.MyCommand.Path
Write-Host "Activating ROS 2 Humble..." -ForegroundColor Yellow
& "C:\dev\ros2_humble\local_setup.ps1"
Write-Host "Activating Python virtual environment..." -ForegroundColor Yellow
# Activate Python virtual environment
& "`$ScriptDir\venv\Scripts\Activate.ps1"
Write-Host ""
Write-Host "[OK] Environment ready! You can now run:" -ForegroundColor Green
Write-Host " python simulation_host.py"
Write-Host " python ros_bridge.py"
Write-Host " python controllers.py"
Write-Host "[OK] Environment ready!" -ForegroundColor Green
Write-Host ""
Write-Host "Run: python standalone_simulation.py" -ForegroundColor White
Write-Host ""
"@ | Out-File -FilePath $activatePs1 -Encoding UTF8
Write-Host "[INFO] Created activation scripts:" -ForegroundColor Green
Write-Host " $activateBat (for CMD)" -ForegroundColor Gray
Write-Host " $activatePs1 (for PowerShell)" -ForegroundColor Gray
Write-Host "[INFO] Created activation scripts" -ForegroundColor Green
# -----------------------------------------------------------------------------
# Verification
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host " Installation Complete!" -ForegroundColor Cyan
Write-Host " Verifying Installation..." -ForegroundColor Cyan
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Verifying installation..." -ForegroundColor Yellow
Write-Host ""
try {
python -c "import pybullet; print(' PyBullet: OK')"
} catch {
$pybulletOk = python -c "import pybullet; print(' PyBullet: OK')" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host $pybulletOk -ForegroundColor Green
} else {
Write-Host " PyBullet: FAILED" -ForegroundColor Red
}
try {
python -c "import PyInstaller; print(' PyInstaller: OK')"
} catch {
Write-Host " PyInstaller: FAILED" -ForegroundColor Red
$numpyOk = python -c "import numpy; print(' NumPy: OK')" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host $numpyOk -ForegroundColor Green
} else {
Write-Host " NumPy: FAILED" -ForegroundColor Red
}
try {
python -c "import PIL; print(' Pillow: OK')"
} catch {
Write-Host " Pillow: FAILED" -ForegroundColor Red
$pillowOk = python -c "from PIL import Image; print(' Pillow: OK')" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host $pillowOk -ForegroundColor Green
} else {
Write-Host " Pillow: FAILED (install with: pip install pillow)" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host " IMPORTANT: Activate the environment first!" -ForegroundColor Cyan
Write-Host " Installation Complete!" -ForegroundColor Cyan
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Before running any scripts, activate the environment:" -ForegroundColor Yellow
Write-Host " CMD: $activateBat" -ForegroundColor White
Write-Host " PowerShell: . $activatePs1" -ForegroundColor White
Write-Host "Quick start:" -ForegroundColor Yellow
Write-Host " . .\activate.ps1" -ForegroundColor White
Write-Host " python standalone_simulation.py" -ForegroundColor White
Write-Host ""
Write-Host "Then run the simulation:" -ForegroundColor Yellow
Write-Host " python simulation_host.py" -ForegroundColor White
Write-Host " python ros_bridge.py" -ForegroundColor White
Write-Host " python controllers.py" -ForegroundColor White
Write-Host "With moving rover:" -ForegroundColor Yellow
Write-Host " python standalone_simulation.py --pattern circular --speed 0.3" -ForegroundColor White
Write-Host ""
Write-Host "Note: ROS 2 and Gazebo are not supported on Windows." -ForegroundColor Gray
Write-Host " standalone_simulation.py provides the complete experience." -ForegroundColor Gray
Write-Host ""