System Requirements
Operating System
Linux, macOS, or Windows with WSL2
Memory
Minimum 4GB RAM (8GB recommended)
Storage
At least 2GB free disk space
Browser
Modern browser with WebAssembly support
Installing Rust
Install rustup
The Rust toolchain manager After installation, restart your terminal or run:
rustup is the recommended way to install Rust.Project Dependencies
Mars-RS relies on three primary dependencies defined inCargo.toml:
Core Dependencies
macroquad 0.3
macroquad 0.3
A simple and easy-to-use game library for graphics rendering and input handling.Key Features:
- Cross-platform graphics rendering
- WebAssembly support out of the box
- Built-in UI system for buttons and controls
- Input handling for keyboard and mouse
- Rendering the VEX field and game objects
- Drawing the robot and triballs
- Handling user input in Driver mode
- Creating the UI for mode switching
rapier2d 0.17.2
rapier2d 0.17.2
A 2D physics engine for Rust with WebAssembly support.Configuration:The
simd-stable feature enables SIMD optimizations for better performance while maintaining stability across platforms.nalgebra 0.32.3
nalgebra 0.32.3
A linear algebra library for graphics and physics computations.Configuration:This feature enables conversion between nalgebra and glam math types, which is necessary for interoperability with macroquad.Used in Mars-RS for:
- Vector and matrix transformations
- Rotation calculations
- Position and velocity computations
Building the Project
Install dependencies
Cargo will automatically download and compile all dependencies:This may take several minutes on the first build as Cargo compiles all dependencies.
Build for WebAssembly
Compile the project to WebAssembly:The
--release flag enables optimizations for better performance.The output file will be at
target/wasm32-unknown-unknown/release/mars-rs.wasmProject Structure
Understanding the codebase organization:Key Modules
main.rs
Contains the main game loop using macroquad’s
#[macroquad::main] attributerobot.rs
Defines the
Robot struct with position, heading, and differential drive kinematicsfield.rs
Renders the VEX field with checkerboard tiles, goals, barriers, and triballs
movement.rs
Implements PID control, Pure Pursuit, and Boomerang path following
Development Workflow
Fast Iteration
For quick development iterations, use cargo’s watch mode:Debugging
Web Server Setup
Mars-RS requires a web server to load the WASM module due to browser security restrictions.Python (Built-in)
Python (Built-in)
If you have Python installed:Navigate to
http://localhost:8000Node.js http-server
Node.js http-server
Install and run with npx:Or install globally:
Rust basic-http-server
Rust basic-http-server
Install a Rust-based server:Defaults to port 4000
HTML Setup
Theindex.html file loads the WebAssembly module:
The macroquad JavaScript bundle (
mq_js_bundle.js) is loaded from a CDN. Make sure you have an internet connection when running the simulation.Troubleshooting
rustup: command not found
rustup: command not found
If Then restart your terminal or run:
rustup is not in your PATH after installation:wasm32-unknown-unknown target not found
wasm32-unknown-unknown target not found
Make sure you’ve added the WebAssembly target:
Compilation errors with dependencies
Compilation errors with dependencies
Try updating the Rust toolchain and cleaning the build:
WASM file not loading in browser
WASM file not loading in browser
Check the browser console for errors. Common issues:
- CORS errors: Use a proper web server, not
file://URLs - Wrong path: Verify
index.htmlreferences the correct WASM filename - Missing JavaScript: Ensure the macroquad bundle loads before your WASM
Next Steps
Now that you have Mars-RS installed and building:Quickstart
Run your first simulation and try the controls
Robot API
Learn about the Robot struct and movement functions
Movement Algorithms
Explore PID tuning and path following
Field Rendering
Understand the VEX field layout and game objects