#sensor #update #simulator #behavior #measurement #measurements

bin+lib sensulator

Simple sensor simulator, provides noisy readings of ideal measurements

2 releases

✓ Uses Rust 2018 edition

0.4.2 Apr 9, 2019
0.4.0 Mar 24, 2019

29 downloads per month


129 lines


A rust library for simulating sensor measurement behavior. You can initialize or update a sensulator with a central "ideal" value, and the sensulator will subsequently provide noisy sensor measurements centered around that value.


See main.rs

  use sensulator::Sensulator;
  /// Latitude of Berkeley, California
  const HOME_LAT:f32 = 37.8716;
  /// Absolute error of a typical GPS sensor (degrees)
  const GPS_HORIZ_ABS_ERROR:f32 = 2e-6;
  /// Relative error of a typical GPS sensor (degrees)
  const GPS_HORIZ_REL_ERROR:f32 = 4.5e-5;
  let mut fake_gps_lat = Sensulator::new(HOME_LAT, GPS_HORIZ_ABS_ERROR, GPS_HORIZ_REL_ERROR);
  loop {
    // update the sensor reading and display (requires a mutable sensulator reference)
    println!("new lat: {}", fake_gps_lat.measure());
    // simply display the last measured value (may use an immutable reference)
    println!("old lat: {}", fake_gps_lat.peek());

Testing with quickcheck

A brief quickcheck is run as part of cargo test; however, if you want to run more extensive tests, you can use something like:

export QUICKCHECK_TESTS=1000000; cargo test -- --nocapture