Compare commits

..

No commits in common. "d574ccb5f4a66ac9f10106b6f4ff8780bef5f500" and "aee279b5790bf4ea05b97fcd1dca997fb659b550" have entirely different histories.

2 changed files with 7 additions and 9 deletions

View File

@ -373,10 +373,8 @@ fn main() -> ! {
SCB::sys_reset(); SCB::sys_reset();
} }
} }
Ok(SessionInput::Error(e)) => { Ok(SessionInput::Error(e)) =>
error!("session input: {:?}", e); error!("session input: {:?}", e),
send_line(&mut socket, b"{ \"error\": \"invalid input\" }");
}
Err(_) => Err(_) =>
socket.close(), socket.close(),
} }

View File

@ -47,7 +47,7 @@ impl Controller {
pub fn update(&mut self, input: f64) -> f64 { pub fn update(&mut self, input: f64) -> f64 {
// error // error
let error = input - self.target; let error = self.target - input;
// partial // partial
let p = f64::from(self.parameters.kp) * error; let p = f64::from(self.parameters.kp) * error;
@ -65,7 +65,7 @@ impl Controller {
// derivative // derivative
let d = match self.last_input { let d = match self.last_input {
None => 0.0, None => 0.0,
Some(last_input) => f64::from(self.parameters.kd) * (input - last_input), Some(last_input) => f64::from(self.parameters.kd) * (last_input - input),
}; };
self.last_input = Some(input); self.last_input = Some(input);
@ -129,7 +129,7 @@ mod test {
#[test] #[test]
fn test_controller() { fn test_controller() {
const DEFAULT: f64 = 0.0; const DEFAULT: f64 = 0.0;
const TARGET: f64 = -1234.56; const TARGET: f64 = 1234.56;
const ERROR: f64 = 0.01; const ERROR: f64 = 0.01;
const DELAY: usize = 10; const DELAY: usize = 10;
@ -144,8 +144,8 @@ mod test {
let next_t = (t + 1) % DELAY; let next_t = (t + 1) % DELAY;
// Feed the oldest temperature // Feed the oldest temperature
let output = pid.update(values[next_t]); let output = pid.update(values[next_t]);
// Overwrite oldest with previous temperature - output // Overwrite oldest with previous temperature + output
values[next_t] = values[t] - output; values[next_t] = values[t] + output;
t = next_t; t = next_t;
total_t += 1; total_t += 1;
} }