Skip to main content
Mars-RS is a WebAssembly-based robotics simulation tool designed for VEX competitions. This guide will help you run your first simulation quickly.

Prerequisites

Before you begin, make sure you have:
  • Rust toolchain (1.56 or later)
  • A modern web browser with WebAssembly support
  • Basic familiarity with Rust programming
If you don’t have Rust installed yet, check out the Installation guide first.

Running the Simulation

1

Clone the repository

Get the Mars-RS source code:
git clone https://github.com/your-org/mars-rs.git
cd mars-rs
2

Build the WebAssembly binary

Compile the Rust code to WebAssembly:
cargo build --target wasm32-unknown-unknown --release
The compiled WASM file will be located at:
target/wasm32-unknown-unknown/release/mars-rs.wasm
3

Serve the application

You’ll need a local web server to run the simulation. Use any static file server:
python -m http.server 8000
4

Open in browser

Navigate to http://localhost:8000 in your web browser. You should see the VEX field rendered with a purple checkerboard pattern.

Understanding the Interface

When you first open Mars-RS, you’ll see:
  • VEX Field: A 12×12 foot field with triballs, goals, and barriers
  • Robot: A red robot controlled by keyboard or autonomous code
  • Mode Indicator: Shows current mode (Driver/Auton/Create)
  • Control Buttons: Switch between different modes

Control Modes

Control the robot manually using keyboard inputs:
  • W: Move forward
  • S: Move backward
  • A: Turn left
  • D: Turn right
  • T: Toggle between Driver and Auton modes
The robot uses differential drive with arcade-style controls, where linear and angular velocities are combined to calculate individual wheel speeds.
Run autonomous routines programmed with path following algorithms:
  • Pure Pursuit path following
  • PID-based movement to point
  • Boomerang controller for smooth curved paths
Switch to this mode by pressing T or clicking the Auton button.
Design custom autonomous paths by drawing waypoints on the field. Click the Create button to enter path creation mode.

Your First Autonomous Routine

Here’s a simple example of moving the robot to a target position using the built-in movement functions:
use std::sync::{Arc, Mutex};

// Create a robot instance
let robot = Arc::new(Mutex::new(robot::Robot {
    position: (screen_width()/2.0, screen_height()/3.8),
    heading: 0.0,
    robotSize: 0.0
}));

// Define PID constants for movement
const lCons: util::PidConstants = util::PidConstants{
    p: 0.03,
    i: 0.0,
    d: 0.0,
    tolerance: 0.0,
    integralThreshold: 0.0,
    maxIntegral: 0.0
};

const rCons: util::PidConstants = util::PidConstants{
    p: 0.015,
    i: 0.0,
    d: 0.0,
    tolerance: 0.0,
    integralThreshold: 0.0,
    maxIntegral: 0.0
};

// Move to a target position
let target = (width / 2.0, height / 2.0);
movement::pidMTP(&robot, target, 115.0, 800, lCons, rCons, 10.0);

Next Steps

Installation

Learn about dependencies and build configuration

Movement Algorithms

Explore PID control and path following

Field Elements

Understand game objects and physics

Robot Configuration

Customize your robot’s properties
The WebAssembly build requires the wasm32-unknown-unknown target. Make sure to add it using:
rustup target add wasm32-unknown-unknown

Troubleshooting

Simulation not loading?
  • Ensure your browser supports WebAssembly
  • Check browser console for JavaScript errors
  • Verify the WASM file path in index.html matches your build output
Robot not moving?
  • Make sure you’re in Driver mode (press T to switch)
  • Check that the keyboard focus is on the canvas element
  • Verify velocity limits aren’t capping your movement
Build errors?
  • Run cargo clean and rebuild
  • Check that all dependencies are compatible versions
  • Ensure Rust toolchain is up to date with rustup update

Build docs developers (and LLMs) love