# ROS2Lab - Try ROS 2 on your PC (Windows 10 21H2 or newer / Windows 11, 64-bit Intel/AMD). NORMAL PowerShell, no administrator. # # irm https://www.ros2lab.com/install/try.ps1 | iex # # The same line for the old black "Command Prompt" (CMD) or a PC that blocks scripts (works in PowerShell too): # powershell -ExecutionPolicy Bypass -c "irm https://www.ros2lab.com/install/try.ps1 | iex" # If your antivirus stops the line above ("This script contains malicious content and has been blocked by your antivirus # software"): download https://www.ros2lab.com/install/try.ps1, read it, then run it from its folder with # powershell -ExecutionPolicy Bypass -File .\try.ps1 # (-ExecutionPolicy Bypass applies to that one command only; never turn your antivirus off for this.) # # STATUS: tested on Ubuntu 24.04; Windows and macOS not yet run on a real machine # (this script was checked on Linux with PSScriptAnalyzer and a dry run with stand-ins). # A web page cannot install programs by itself. This one pasted command is the closest safe thing: you can read it first. # What it does: # 1. checks this PC (Windows 10 21H2+ / 11, 64-bit Intel/AMD, free space >= 2 GB, memory); every check prints OK or one line # saying what to do. A user folder with a space, an accent or OneDrive in its path cannot hold ROS 2 tools, so it then # installs to C:\ros2lab instead; # 2. puts pixi 0.84.2 (a package manager, one file: pixi.exe) in %USERPROFILE%\ros2lab-try\bin, checked against its # SHA256 below (the official release file from github.com/prefix-dev/pixi; the official install.ps1 is not used # because it would change your PATH); # 3. downloads pixi.toml, pixi.lock, ros2lab-try.py and SHA256SUMS and checks them against SHA256SUMS; # 4. "pixi install --frozen": ROS 2 Jazzy + turtlesim from RoboStack (conda-forge), about 350 MB of downloads, # exactly the versions in pixi.lock. No WSL, no Docker, no Visual Studio; # 5. starts ros2lab-try.py (bridge v3, source: www.ros2lab.com/install/try/ros2lab-try.py): it opens the turtlesim window, # connects OUT to the ROS2Lab relay (no port is opened on this PC) and opens your browser at www.ros2lab.com/pc with a # secret link (it also prints a short code for another browser). The page can then run ros2 commands for turtlesim # here, checked word by word on THIS PC, never through a shell. It stops by itself after 60 min with no page connected. # While it runs it talks to the relay (*.firebasedatabase.app, identitytoolkit/securetoken.googleapis.com): commands from # your page and their output, turtle positions, and a label like "Windows 11 PC" (never your PC's name or files). # Advanced: $env:ROS2LAB_DIRECT="1" (or a blocked relay) uses the older direct connection on 127.0.0.1:7777. # Windows may ask whether turtlesim/python may use networks: ROS 2 talks between its own programs this way. # "Cancel" is fine, the turtle still works on this PC. # Downloads, and nothing else is sent anywhere: github.com/prefix-dev/pixi (pixi), www.ros2lab.com/install/try/ (the 4 # files above), prefix.dev and conda.anaconda.org (the ROS 2 packages). # Where it writes: ONLY %USERPROFILE%\ros2lab-try. No administrator, no change to PATH, the registry or your profile. # Remove it: Ctrl+C here, then Remove-Item -Recurse -Force "$env:USERPROFILE\ros2lab-try" # Run it again: the same command. It upgrades in place (new files from the site, same folder) and opens the turtle again. # Everything runs inside one script block: it never calls exit (that would close the window when piped to iex) and # leaves no variables, functions or environment changes behind in your PowerShell session. & { $PixiVersion = "0.84.2" $PixiSha = "aa4f02efac31566176d639007e65a36740aa7b56c22673c44ecfd2611e7a6b2c" # pixi-x86_64-pc-windows-msvc.zip $Origin = "https://www.ros2lab.com"; if ($env:ROS2LAB_ORIGIN) { $Origin = $env:ROS2LAB_ORIGIN } $Try = Join-Path $env:USERPROFILE "ros2lab-try"; if ($env:ROS2LAB_TRY_DIR) { $Try = $env:ROS2LAB_TRY_DIR } $Cmd = "irm https://www.ros2lab.com/install/try.ps1 | iex" $inv = [System.Globalization.CultureInfo]::InvariantCulture $ProgressPreference = "SilentlyContinue" # the progress bar makes Invoke-WebRequest many times slower on PowerShell 5.1 $t0 = Get-Date # a ROS 2 or conda already set up in this window would mix in: cleared for this run, put back at the end (profile never edited). # ROS_DOMAIN_ID stays: it only picks the channel, and with ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST nothing leaves this PC. $mix = @(Get-ChildItem Env: | Where-Object { $_.Name -match '^(ROS_|RMW_|CONDA|AMENT_|COLCON_)' -and $_.Name -ne "ROS_DOMAIN_ID" } | ForEach-Object { $_.Name }) $saved = @{}; foreach ($n in @("PIXI_HOME", "PIXI_CACHE_DIR", "RATTLER_CACHE_DIR", "PIXI_NO_PATH_UPDATE", "ROS2LAB_TRY_CMD", "PYTHONPATH", "PYTHONHOME", "VIRTUAL_ENV") + $mix) { $saved[$n] = [Environment]::GetEnvironmentVariable($n, "Process") } $procs = @() function Exit-Try($why) { throw "ROS2LAB-STOP: $why" } function Get-Sha($file) { return (Get-FileHash -Algorithm SHA256 -LiteralPath $file).Hash.ToLowerInvariant() } function Get-File($url, $out) { try { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $out -ErrorAction Stop } catch { $m = $_.Exception.Message if ($m -match "SSL|TLS|trust relationship|certificate") { Write-Host " Download failed: this network inspects secure connections (common at schools and offices). Try a phone hotspot or set HTTPS_PROXY." } elseif ($m -match "proxy|407") { Write-Host " Download failed: the network's proxy did not let it through. Try a phone hotspot, or set HTTPS_PROXY to your network's proxy." } else { Write-Host " Download failed ($url): $m. Check the internet connection; behind a proxy set HTTPS_PROXY, or try a phone hotspot." } throw } } try { # PowerShell 5.1 may not offer TLS 1.2 by default; github.com and prefix.dev need it try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { Write-Verbose "TLS setting unchanged" } Write-Host "ROS2Lab - Try ROS 2 on your PC" Write-Host "Checking this PC..." $os = "Windows"; try { $os = (Get-CimInstance Win32_OperatingSystem -ErrorAction Stop).Caption } catch { Write-Verbose "no CIM" } $build = 0; try { $build = [int](Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -ErrorAction Stop).CurrentBuildNumber } catch { Write-Verbose "no build number" } Write-Host " system: $os (build $build)" if ($build -gt 0 -and $build -lt 19044) { Exit-Try "Windows 10 21H2 (build 19044) or newer is needed." } $arch = $env:PROCESSOR_ARCHITECTURE; if ($env:PROCESSOR_ARCHITEW6432) { $arch = $env:PROCESSOR_ARCHITEW6432 } Write-Host " processor: $arch" if ($arch -ne "AMD64") { Exit-Try "the ROS 2 packages here are for 64-bit Intel/AMD Windows; this PC is $arch." } # conda/ROS tools break on a path with a space or an accent (RoboStack #101, pixi #930/#1990) and a OneDrive folder syncs # 1.8 GB of small files: such a user folder gets the short C:\ros2lab instead if (-not $env:ROS2LAB_TRY_DIR -and ($Try -match '\s|[^\x21-\x7E]|OneDrive' -or $Try.Length -gt 60)) { Write-Host " folder: your user folder ($env:USERPROFILE) has a space, an accent or OneDrive in its path, which ROS 2 tools cannot use." Write-Host " OK: installing to C:\ros2lab instead (remove it later with Remove-Item -Recurse -Force C:\ros2lab)." $Try = "C:\ros2lab" } $drive = [System.IO.Path]::GetPathRoot($Try) if ($env:ROS2LAB_TEST_FREE_GB) { $free = [double]::Parse($env:ROS2LAB_TEST_FREE_GB, $inv) } else { $free = [math]::Round((New-Object System.IO.DriveInfo -ArgumentList $drive).AvailableFreeSpace / 1GB, 1) } Write-Host (" free space: {0} GB on {1} (needs 2 GB)" -f $free.ToString("0.0", $inv), $drive) if (-not (Test-Path (Join-Path $Try ".pixi\envs\default")) -and $free -lt 2) { Exit-Try ("only {0} GB free on {1}; ROS 2 needs 2 GB. Free some space (empty the Recycle Bin, delete big downloads) and run the command again." -f $free.ToString("0.0", $inv), $drive) } $ram = "?"; $ramGb = 0; try { $ramGb = (Get-CimInstance Win32_ComputerSystem -ErrorAction Stop).TotalPhysicalMemory / 1GB; $ram = $ramGb.ToString("0.0", $inv) } catch { Write-Verbose "no CIM" } Write-Host " memory: $ram GB" if ($ramGb -gt 0 -and $ramGb -lt 4) { Write-Host " (less than 4 GB: it works, but close other programs first)" } Write-Host " folder: $Try" $null = New-Item -ItemType Directory -Force -Path (Join-Path $Try "bin") $pixi = Join-Path $Try "bin\pixi.exe" $have = ""; if (Test-Path $pixi) { try { $have = (& $pixi --version) -join "" } catch { $have = "" } } if ($have -ne "pixi $PixiVersion") { Write-Host "Getting pixi $PixiVersion (one file, 32 MB) from github.com/prefix-dev/pixi ..." $zip = Join-Path $Try "pixi.zip" Get-File "https://github.com/prefix-dev/pixi/releases/download/v$PixiVersion/pixi-x86_64-pc-windows-msvc.zip" $zip if ((Get-Sha $zip) -ne $PixiSha) { Remove-Item -Force $zip; Exit-Try "the pixi download did not match its SHA256 (a broken or changed download)." } Expand-Archive -Force -LiteralPath $zip -DestinationPath (Join-Path $Try "bin"); Remove-Item -Force $zip Write-Host " pixi checked (SHA256 ok)" } Write-Host "Getting the ROS 2 list (pixi.toml, pixi.lock) from $Origin/install/try/ ..." $new = Join-Path $Try "new"; if (Test-Path $new) { Remove-Item -Recurse -Force $new }; $null = New-Item -ItemType Directory -Path $new $files = "pixi.toml", "pixi.lock", "ros2lab-try.py" $got = $true try { foreach ($f in @("SHA256SUMS") + $files) { Get-File "$Origin/install/try/$f" (Join-Path $new $f) } } catch { $got = $false } if ($got) { $sums = @{}; foreach ($line in Get-Content (Join-Path $new "SHA256SUMS")) { $p = $line -split '\s+'; if ($p.Count -ge 2) { $sums[$p[1].TrimStart('*')] = $p[0].ToLowerInvariant() } } foreach ($f in $files) { if ($sums[$f] -ne (Get-Sha (Join-Path $new $f))) { Remove-Item -Recurse -Force $new; Exit-Try "a downloaded file did not match SHA256SUMS." } } foreach ($f in @("SHA256SUMS") + $files) { Move-Item -Force (Join-Path $new $f) (Join-Path $Try $f) } Write-Host " files checked (SHA256SUMS ok)" } elseif (Test-Path (Join-Path $Try "pixi.lock")) { Write-Host " (no internet: using the files from last time)" } else { Exit-Try "could not download from $Origin." } if (Test-Path $new) { Remove-Item -Recurse -Force $new } # everything pixi keeps goes into the try folder (put back as it was when this script ends) $env:PIXI_HOME = Join-Path $Try "pixi-home"; $env:PIXI_CACHE_DIR = Join-Path $Try "cache"; $env:RATTLER_CACHE_DIR = $env:PIXI_CACHE_DIR; $env:PIXI_NO_PATH_UPDATE = "1" if ($mix.Count -gt 0) { Write-Host " OK: a ROS 2 or conda already set up in this window is ignored here; nothing in your profile changes." } foreach ($n in @("PYTHONPATH", "PYTHONHOME", "VIRTUAL_ENV") + $mix) { [Environment]::SetEnvironmentVariable($n, $null, "Process") } $manifest = Join-Path $Try "pixi.toml" Write-Host "Installing ROS 2 Jazzy + turtlesim into $Try (first time: about 350 MB, a few minutes) ..." & $pixi install --frozen --manifest-path $manifest if ($LASTEXITCODE -ne 0) { Exit-Try "pixi install failed (see the lines above)." } $size = (Get-ChildItem -LiteralPath $Try -Recurse -Force -File -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum Write-Host (" installed in {0:0} s; the folder is {1:0.0} GB" -f ((Get-Date) - $t0).TotalSeconds, ($size / 1GB)) Write-Host "" Write-Host "Keep this window open: Ctrl+C here stops the turtle and the bridge." Write-Host " Open it again later: $Cmd" Write-Host " Remove everything: Remove-Item -Recurse -Force `"$Try`"" # pixi run sets up ROS 2 for the bridge only; the bridge opens the turtle window and prints the pairing code. # Ctrl+C: the console sends it to the bridge (it stops its commands with CTRL_BREAK, each in its own process group). $env:ROS2LAB_TRY_CMD = $Cmd $bridge = Start-Process -FilePath $pixi -ArgumentList @("run", "--frozen", "--manifest-path", "`"$manifest`"", "python", "-I", "`"$(Join-Path $Try 'ros2lab-try.py')`"", "--turtlesim") -NoNewWindow -PassThru $procs = @($bridge) while (-not $bridge.HasExited) { Start-Sleep -Milliseconds 500 } Write-Host "Stopped. To open it again: $Cmd" } catch { $m = $_.Exception.Message Write-Host "" if ($m -like "ROS2LAB-STOP: *") { Write-Host ("Stopped: " + $m.Substring(14)) } else { Write-Host "Stopped: $m" } Write-Host "The Browser Lab on www.ros2lab.com needs no install." } finally { # Ctrl+C lands here too: stop pixi run and the programs it started (the whole process tree) foreach ($p in $procs) { if ($p -and -not $p.HasExited) { & taskkill.exe /T /F /PID $p.Id 2>&1 | Out-Null } } foreach ($n in $saved.Keys) { [Environment]::SetEnvironmentVariable($n, $saved[$n], "Process") } } }