All checks passing

This commit is contained in:
Andrew Johnson 2018-04-08 12:22:03 -06:00
parent a33a8a5953
commit 3187d49254

View File

@ -13,6 +13,7 @@ use std::fs::File;
use std::io::{self, Read, Write, BufRead, BufReader}; use std::io::{self, Read, Write, BufRead, BufReader};
use std::io::prelude::*; use std::io::prelude::*;
#[derive(Clone)]
struct Trip { struct Trip {
dst: u64, dst: u64,
up: f64, up: f64,
@ -27,6 +28,7 @@ fn main()
let mut jerk = 0.0; let mut jerk = 0.0;
let mut prev_est: Option<ElevatorState> = None; let mut prev_est: Option<ElevatorState> = None;
let mut dst_timing: Vec<Trip> = Vec::new(); let mut dst_timing: Vec<Trip> = Vec::new();
let mut start_location = 0.0;
for line in simlog.lines() { for line in simlog.lines() {
let l = line.unwrap(); let l = line.unwrap();
match esp.clone() { match esp.clone() {
@ -36,13 +38,13 @@ fn main()
}, },
Some(esp) => { Some(esp) => {
let (est, dst): (ElevatorState,u64) = serde_json::from_str(&l).unwrap(); let (est, dst): (ElevatorState,u64) = serde_json::from_str(&l).unwrap();
if dst_timing.len()==0 || dst_timing[0].dst != dst { let dl = dst_timing.len();
if dst_timing.len()==0 || dst_timing[dl-1].dst != dst {
dst_timing.push(Trip { dst:dst, up:0.0, down:0.0 }); dst_timing.push(Trip { dst:dst, up:0.0, down:0.0 });
} }
if let Some(prev_est) = prev_est { if let Some(prev_est) = prev_est {
let dt = est.timestamp - prev_est.timestamp; let dt = est.timestamp - prev_est.timestamp;
let dl = dst_timing.len();
if est.velocity > 0.0 { if est.velocity > 0.0 {
dst_timing[dl-1].up += dt; dst_timing[dl-1].up += dt;
} else { } else {
@ -53,6 +55,8 @@ fn main()
if jerk.abs() > 0.22 { if jerk.abs() > 0.22 {
panic!("jerk is outside of acceptable limits: {} {:?}", jerk, est) panic!("jerk is outside of acceptable limits: {} {:?}", jerk, est)
} }
} else {
start_location = est.location;
} }
if est.acceleration.abs() > 2.2 { if est.acceleration.abs() > 2.2 {
panic!("acceleration is outside of acceptable limits: {:?}", est) panic!("acceleration is outside of acceptable limits: {:?}", est)
@ -61,8 +65,6 @@ fn main()
panic!("velocity is outside of acceptable limits: {:?}", est) panic!("velocity is outside of acceptable limits: {:?}", est)
} }
prev_est = Some(est); prev_est = Some(est);
} }
} }
} }
@ -70,7 +72,7 @@ fn main()
//elevator should not backup //elevator should not backup
let mut total_time = 0.0; let mut total_time = 0.0;
let mut total_direct = 0.0; let mut total_direct = 0.0;
for trip in dst_timing for trip in dst_timing.clone()
{ {
total_time += (trip.up + trip.down); total_time += (trip.up + trip.down);
if trip.up > trip.down { if trip.up > trip.down {
@ -83,6 +85,29 @@ fn main()
panic!("elevator back up is too common: {}", total_direct / total_time) panic!("elevator back up is too common: {}", total_direct / total_time)
} }
//trips should finish within 20% of theoretical limit
//trips should finish within 20% of theoretical limit
let MAX_JERK = 0.2;
let MAX_ACCELERATION = 2.0;
let MAX_VELOCITY = 5.0;
let mut trip_start_location = start_location;
let mut theoretical_time = 0.0;
let floor_height = esp.unwrap().floor_height;
for trip in dst_timing.clone()
{
let next_floor = (trip.dst as f64) * floor_height;
let d = (trip_start_location - next_floor).abs();
theoretical_time += (
2.0*(MAX_ACCELERATION / MAX_JERK) +
2.0*(MAX_JERK / MAX_ACCELERATION) +
d / MAX_VELOCITY
);
trip_start_location = next_floor;
}
if total_time > (theoretical_time * 1.2) {
panic!("elevator moves to slow {} {}", total_time, theoretical_time * 1.2)
}
println!("All simulation checks passing.");
} }