/
std_rng.rs
29 lines (24 loc) · 993 Bytes
/
std_rng.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2022, Todd Stellanova
// License: see LICENSE file
/// Example using the standard RNG, using std
///
use sensulator::{MeasureVal, Sensulator};
use rand::SeedableRng;
use rand::rngs::StdRng;
/// Latitude of Berkeley, California
const HOME_LAT:MeasureVal = 37.8716;
/// Absolute error of a typical GPS sensor (degrees)
const GPS_HORIZ_ABS_ERROR:MeasureVal = 2e-6;
/// Relative error of a typical GPS sensor (degrees)
const GPS_HORIZ_REL_ERROR:MeasureVal = 4.5e-5;
fn main() {
// create an unpredictable RNG using std-provided entropy source
let mut my_rng = StdRng::from_entropy();
let mut fake_gps_lat = Sensulator::new(HOME_LAT, GPS_HORIZ_ABS_ERROR, GPS_HORIZ_REL_ERROR, &mut my_rng);
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());
}
}