3/5 checks for analyze.rs

master
Andrew Johnson 6 years ago
parent 2ab06f2f47
commit cdcc3e10cf

@ -12,13 +12,13 @@ use std::env;
use std::fs::File;
use std::io::{self, Read, Write, BufRead, BufReader};
use std::io::prelude::*;
use std::cmp;
fn main()
{
let simlog = File::open("simulation.log").expect("read simulation log");
let mut simlog = BufReader::new(&simlog);
let mut esp = None;
let mut prev_est: Option<ElevatorState> = None;
for line in simlog.lines() {
let l = line.unwrap();
match esp.clone() {
@ -28,6 +28,26 @@ fn main()
},
Some(esp) => {
let (est, dst): (ElevatorState,u64) = serde_json::from_str(&l).unwrap();
if let Some(prev_est) = prev_est {
let dt = est.timestamp - prev_est.timestamp;
let da = est.acceleration - prev_est.acceleration;
let jerk = da / dt;
if jerk.abs() > 0.21 {
panic!("jerk is outside of acceptable limits: {:?}", est)
}
}
if est.acceleration.abs() > 2.1 {
panic!("acceleration is outside of acceptable limits: {:?}", est)
}
if est.velocity.abs() > 5.1 {
panic!("velocity is outside of acceptable limits: {:?}", est)
}
prev_est = Some(est);
//elevator should never backup
//trips should finish within 20% of theoretical limit
}
}
}

@ -3,14 +3,14 @@ use std::time::Instant;
use floating_duration::{TimeAsFloat, TimeFormat};
use std::{thread, time};
#[derive(Clone,Serialize,Deserialize)]
#[derive(Clone,Serialize,Deserialize,Debug)]
pub enum MotorInput
{
Up { voltage: f64 },
Down { voltage: f64 }
}
#[derive(Clone,Serialize,Deserialize)]
#[derive(Clone,Serialize,Deserialize,Debug)]
pub struct ElevatorSpecification
{
pub floor_count: u64,
@ -18,7 +18,7 @@ pub struct ElevatorSpecification
pub carriage_weight: f64
}
#[derive(Clone,Serialize,Deserialize)]
#[derive(Clone,Serialize,Deserialize,Debug)]
pub struct ElevatorState
{
pub timestamp: f64,

Loading…
Cancel
Save