TR final changes

master
Andrew Johnson 6 years ago
parent 504971a163
commit 78bdbfe128

@ -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;

@ -67,7 +67,7 @@ impl<'a, W: Write> DataRecorder for SimpleDataRecorder<'a, W>
fn init(&mut self, esp: ElevatorSpecification, est: ElevatorState)
{
self.esp = esp.clone();
self.log.write_all(serde_json::to_string(&esp.clone()).unwrap().as_bytes()).expect("write spec to log");
self.log.write_all(serde_json::to_string(&esp).unwrap().as_bytes()).expect("write spec to log");
self.log.write_all(b"\r\n").expect("write spec to log");
}
fn poll(&mut self, est: ElevatorState, dst: u64)
@ -114,12 +114,6 @@ impl<'a, W: Write> DataRecorder for SimpleDataRecorder<'a, W>
write!(self.stdout, "{}", String::from_utf8(terminal_buffer).ok().unwrap());
self.stdout.flush().unwrap();
}
}
trait DataRecorderSummary {
fn summary(&mut self);
}
impl<'a, W: Write> DataRecorderSummary for SimpleDataRecorder<'a, W> {
fn summary(&mut self)
{
//6 Calculate and print summary statistics

@ -40,6 +40,7 @@ pub trait DataRecorder
{
fn init(&mut self, esp: ElevatorSpecification, est: ElevatorState);
fn poll(&mut self, est: ElevatorState, dst: u64);
fn summary(&mut self);
}
pub trait MotorForce {

Loading…
Cancel
Save