Skip to Content
VectorLib

Simulator and tests

Run autonomous routines on your laptop with the sim feature.

The sim feature swaps vexide's runtime for a deterministic virtual clock and a simulated drivetrain, with simulated motors, tracking wheels, IMU, distance sensors and controller. A whole autonomous runs in milliseconds, so you can test routines on your laptop.

Cargo.toml
[dev-dependencies]
vectorlib = { git = "https://github.com/sathvikloke/VectorLib", features = ["sim"] }
use vectorlib::sim::{self, RobotConfig, World};

sim::run(async {
    World::install(RobotConfig::default()); // LemLib's example robot
    // build the chassis from sim::devices (SimMotor, SimRotation, SimImu),
    // as tests/behaviour.rs does
    let chassis = example_chassis();
    chassis.calibrate(true).await;
    chassis.move_to_pose(20.0, 15.0, 90.0, 4000).run_async(false).await;
    println!("{}", chassis.get_pose());
});
Simulated deviceStands in for
SimMotor::new(side, reversed)A drive motor
SimRotation::new(mount, diameter) / SimAdiEncoderA tracking wheel's sensor
SimImu::new()The inertial sensor (can be made to fail calibration)
SimDistance::field(facing, x, y, wall)A distance sensor measuring the field walls
SimController::new()The controller: press buttons and read back the screen

Running the tests

cargo test --features sim                 # unit, behaviour and parity tests
cargo test --features sim -- --nocapture  # also print how many values were compared

The parity tests need clang++ to compile the original C++. Set VECTORLIB_REQUIRE_PARITY=1 to make a missing compiler a failure instead of a printed warning.

On this page