|
|
|
@ -20,53 +20,53 @@ struct Trip {
|
|
|
|
|
down: f64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const MAX_JERK: f64 = 0.2;
|
|
|
|
|
const MAX_ACCELERATION: f64 = 2.0;
|
|
|
|
|
const MAX_VELOCITY: f64 = 5.0;
|
|
|
|
|
|
|
|
|
|
fn main()
|
|
|
|
|
{
|
|
|
|
|
let simlog = File::open("simulation.log").expect("read simulation log");
|
|
|
|
|
let mut simlog = BufReader::new(&simlog);
|
|
|
|
|
let mut esp = None;
|
|
|
|
|
let mut jerk = 0.0;
|
|
|
|
|
let mut prev_est: Option<ElevatorState> = None;
|
|
|
|
|
let mut dst_timing: Vec<Trip> = Vec::new();
|
|
|
|
|
let mut start_location = 0.0;
|
|
|
|
|
|
|
|
|
|
let mut first_line = String::new();
|
|
|
|
|
let len = simlog.read_line(&mut first_line).unwrap();
|
|
|
|
|
let esp: ElevatorSpecification = serde_json::from_str(&first_line).unwrap();
|
|
|
|
|
|
|
|
|
|
for line in simlog.lines() {
|
|
|
|
|
let l = line.unwrap();
|
|
|
|
|
match esp.clone() {
|
|
|
|
|
None => {
|
|
|
|
|
let spec: ElevatorSpecification = serde_json::from_str(&l).unwrap();
|
|
|
|
|
esp = Some(spec);
|
|
|
|
|
},
|
|
|
|
|
Some(esp) => {
|
|
|
|
|
let (est, dst): (ElevatorState,u64) = serde_json::from_str(&l).unwrap();
|
|
|
|
|
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 });
|
|
|
|
|
}
|
|
|
|
|
let (est, dst): (ElevatorState,u64) = serde_json::from_str(&l).unwrap();
|
|
|
|
|
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 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(prev_est) = prev_est {
|
|
|
|
|
let dt = est.timestamp - prev_est.timestamp;
|
|
|
|
|
if est.velocity > 0.0 {
|
|
|
|
|
dst_timing[dl-1].up += dt;
|
|
|
|
|
} else {
|
|
|
|
|
dst_timing[dl-1].down += dt;
|
|
|
|
|
}
|
|
|
|
|
let da = (est.acceleration - prev_est.acceleration).abs();
|
|
|
|
|
jerk = (jerk * (1.0 - dt)) + (da * dt);
|
|
|
|
|
if jerk.abs() > 0.22 {
|
|
|
|
|
panic!("jerk is outside of acceptable limits: {} {:?}", jerk, est)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
start_location = est.location;
|
|
|
|
|
}
|
|
|
|
|
if est.acceleration.abs() > 2.2 {
|
|
|
|
|
panic!("acceleration is outside of acceptable limits: {:?}", est)
|
|
|
|
|
}
|
|
|
|
|
if est.velocity.abs() > 5.5 {
|
|
|
|
|
panic!("velocity is outside of acceptable limits: {:?}", est)
|
|
|
|
|
}
|
|
|
|
|
prev_est = Some(est);
|
|
|
|
|
if let Some(prev_est) = prev_est {
|
|
|
|
|
let dt = est.timestamp - prev_est.timestamp;
|
|
|
|
|
if est.velocity > 0.0 {
|
|
|
|
|
dst_timing[dl-1].up += dt;
|
|
|
|
|
} else {
|
|
|
|
|
dst_timing[dl-1].down += dt;
|
|
|
|
|
}
|
|
|
|
|
let da = (est.acceleration - prev_est.acceleration).abs();
|
|
|
|
|
jerk = (jerk * (1.0 - dt)) + (da * dt);
|
|
|
|
|
if jerk.abs() > 0.22 {
|
|
|
|
|
panic!("jerk is outside of acceptable limits: {} {:?}", jerk, est)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
start_location = est.location;
|
|
|
|
|
}
|
|
|
|
|
if est.acceleration.abs() > 2.2 {
|
|
|
|
|
panic!("acceleration is outside of acceptable limits: {:?}", est)
|
|
|
|
|
}
|
|
|
|
|
if est.velocity.abs() > 5.5 {
|
|
|
|
|
panic!("velocity is outside of acceptable limits: {:?}", est)
|
|
|
|
|
}
|
|
|
|
|
prev_est = Some(est);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//elevator should not backup
|
|
|
|
@ -87,13 +87,9 @@ fn main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
let floor_height = esp.floor_height;
|
|
|
|
|
for trip in dst_timing.clone()
|
|
|
|
|
{
|
|
|
|
|
let next_floor = (trip.dst as f64) * floor_height;
|
|
|
|
|