simple motor control and simulation back to Chapter 2 equivalent

This commit is contained in:
Andrew Johnson 2018-04-07 17:11:05 -06:00
parent 7d9159cd97
commit 2ab06f2f47

View File

@ -2,7 +2,7 @@ mod physics;
mod motor;
use physics::{ElevatorSpecification, ElevatorState, MotorInput, simulate_elevator, DataRecorder, MotorController, MotorVoltage};
use motor::{SmoothMotorController};
use motor::{SmoothMotorController, SimpleMotorController};
#[macro_use] extern crate serde_derive;
extern crate serde;
@ -76,6 +76,11 @@ impl<'a, W: Write> DataRecorder for SimpleDataRecorder<'a, W>
self.log.write_all(serde_json::to_string(&datum).unwrap().as_bytes()).expect("write state to log");
self.log.write_all(b"\r\n").expect("write state to log");
self.record_location.push(est.location);
self.record_velocity.push(est.velocity);
self.record_acceleration.push(est.acceleration);
self.record_voltage.push(est.motor_input.voltage());
//5.4. Print realtime statistics
print!("{}{}{}", clear::All, cursor::Goto(1, 1), cursor::Hide);
let carriage_floor = (est.location / self.esp.floor_height).floor();
@ -217,10 +222,15 @@ pub fn run_simulation()
record_acceleration: Vec::new(),
record_voltage: Vec::new()
};
let mut mc = SimpleMotorController {
esp: esp.clone()
};
/*
let mut mc = SmoothMotorController {
timestamp: 0.0,
esp: esp.clone()
};
*/
simulate_elevator(esp, est, floor_requests, &mut mc, &mut dr);
dr.summary();