# ============================================================================= # Drone Simulation - Windows Installation Script (PowerShell) # ============================================================================= # 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 # ============================================================================= Write-Host "==============================================" -ForegroundColor Cyan Write-Host " Drone Simulation - Windows Installation" -ForegroundColor Cyan Write-Host "==============================================" -ForegroundColor Cyan Write-Host "" # Get script and project paths $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $ProjectRoot = Split-Path -Parent $ScriptDir $VenvDir = Join-Path $ProjectRoot "venv" Write-Host "[INFO] Project root: $ProjectRoot" -ForegroundColor Gray Write-Host "[INFO] Virtual environment: $VenvDir" -ForegroundColor Gray # Check for Administrator privileges $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 "" } # Function to refresh environment PATH function Refresh-Path { $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") $chocoPath = "$env:ProgramData\chocolatey\bin" if (Test-Path $chocoPath) { $env:Path = "$chocoPath;$env:Path" } } # ----------------------------------------------------------------------------- # Step 1: Install Chocolatey (Package Manager) # ----------------------------------------------------------------------------- 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" -ForegroundColor Green } } catch { $chocoInstalled = $false } if (-not $chocoInstalled) { Write-Host "[INFO] Installing Chocolatey..." -ForegroundColor Yellow try { Set-ExecutionPolicy Bypass -Scope Process -Force [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-Path Write-Host "[INFO] Chocolatey installed" -ForegroundColor Green } catch { Write-Host "[WARN] Chocolatey installation failed, continuing..." -ForegroundColor Yellow } } # ----------------------------------------------------------------------------- # Step 2: Install Python # ----------------------------------------------------------------------------- Write-Host "" Write-Host "[STEP 2/5] Checking Python..." -ForegroundColor Green $pythonInstalled = $false try { $pythonVersion = python --version 2>$null if ($pythonVersion -match "Python 3") { $pythonInstalled = $true Write-Host "[INFO] Python already installed ($pythonVersion)" -ForegroundColor Green } } catch { $pythonInstalled = $false } if (-not $pythonInstalled) { Write-Host "[INFO] Installing Python 3.11..." -ForegroundColor Yellow $chocoExe = "$env:ProgramData\chocolatey\bin\choco.exe" if (Test-Path $chocoExe) { & $chocoExe install python311 -y } else { Write-Host "[ERROR] Please install Python 3.11 manually from https://python.org" -ForegroundColor Red exit 1 } Refresh-Path } # ----------------------------------------------------------------------------- # Step 3: Create Python Virtual Environment # ----------------------------------------------------------------------------- Write-Host "" Write-Host "[STEP 3/5] Creating Python virtual environment..." -ForegroundColor Green if (Test-Path $VenvDir) { Remove-Item -Recurse -Force $VenvDir } python -m venv $VenvDir Write-Host "[INFO] Virtual environment created" -ForegroundColor Green # ----------------------------------------------------------------------------- # Step 4: Install Python Dependencies # ----------------------------------------------------------------------------- Write-Host "" Write-Host "[STEP 4/5] Installing Python dependencies..." -ForegroundColor Green & "$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 { 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" -ForegroundColor Green # ----------------------------------------------------------------------------- # Step 5: Create Activation Scripts # ----------------------------------------------------------------------------- Write-Host "" 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 Drone Simulation - Environment Activation (Windows CMD) call "%~dp0venv\Scripts\activate.bat" echo. 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 (Windows PowerShell) # Usage: . .\activate.ps1 `$ScriptDir = Split-Path -Parent `$MyInvocation.MyCommand.Path # Activate Python virtual environment & "`$ScriptDir\venv\Scripts\Activate.ps1" Write-Host "" 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 # ----------------------------------------------------------------------------- # Verification # ----------------------------------------------------------------------------- Write-Host "" Write-Host "==============================================" -ForegroundColor Cyan Write-Host " Verifying Installation..." -ForegroundColor Cyan Write-Host "==============================================" -ForegroundColor Cyan Write-Host "" $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 } $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 } $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 " Installation Complete!" -ForegroundColor Cyan Write-Host "==============================================" -ForegroundColor Cyan Write-Host "" Write-Host "Quick start:" -ForegroundColor Yellow Write-Host " . .\activate.ps1" -ForegroundColor White Write-Host " python standalone_simulation.py" -ForegroundColor White Write-Host "" Write-Host "With moving rover:" -ForegroundColor Yellow Write-Host " python standalone_simulation.py --pattern circular --speed 0.3" -ForegroundColor White Write-Host "" Write-Host "======================================================" -ForegroundColor Cyan Write-Host " Want ROS 2 + Gazebo + ArduPilot? Use WSL2" -ForegroundColor Cyan Write-Host "======================================================" -ForegroundColor Cyan Write-Host "" Write-Host "For the full simulation with Gazebo and ArduPilot:" -ForegroundColor Gray Write-Host "" Write-Host "Step 1: Install WSL2" -ForegroundColor Yellow Write-Host " wsl --install -d Ubuntu-24.04" -ForegroundColor White Write-Host " # Restart your computer when prompted" -ForegroundColor DarkGray Write-Host "" Write-Host "Step 2: Open Ubuntu and install" -ForegroundColor Yellow Write-Host " cd /mnt/c/path/to/RDC_Simulation" -ForegroundColor White Write-Host " ./setup/install_ubuntu.sh --with-ardupilot" -ForegroundColor White Write-Host " source ~/.bashrc" -ForegroundColor White Write-Host "" Write-Host "Step 3: Run simulation (2 terminals)" -ForegroundColor Yellow Write-Host " Terminal 1: ./scripts/run_ardupilot_sim.sh runway" -ForegroundColor White Write-Host " Terminal 2: ./scripts/run_ardupilot_controller.sh" -ForegroundColor White Write-Host "" Write-Host "GPU Acceleration in WSL:" -ForegroundColor Yellow Write-Host " - Windows 11: WSLg auto-enabled (no setup needed)" -ForegroundColor DarkGray Write-Host " - NVIDIA GPU: Install WSL driver from nvidia.com/cuda/wsl" -ForegroundColor DarkGray Write-Host " - Check: glxinfo | grep 'OpenGL renderer'" -ForegroundColor DarkGray Write-Host "" Write-Host "WSL Tips:" -ForegroundColor Yellow Write-Host " - Access Windows files: /mnt/c/Users/YourName/" -ForegroundColor DarkGray Write-Host " - Open folder in Explorer: explorer.exe ." -ForegroundColor DarkGray Write-Host " - Increase memory: Create %UserProfile%\.wslconfig" -ForegroundColor DarkGray Write-Host "" Write-Host "See docs/installation.md for detailed instructions." -ForegroundColor Gray Write-Host ""