fix pid.rs test, exclude dfu from test

pull/50/head
topquark12 2021-01-16 11:04:24 +08:00
parent cf3ace4d2d
commit c4e3be1d05
2 changed files with 3 additions and 1 deletions

View File

@ -14,6 +14,7 @@ pub unsafe fn set_dfu_trigger() {
/// Called by reset handler in lib.rs immediately after reset.
/// This function should not be called outside of reset handler as
/// bootloader expects MCU to be in reset state when called.
#[cfg(target_arch = "arm")]
#[pre_init]
unsafe fn __pre_init() {
if _dfu_msg == DFU_TRIG_MSG {

View File

@ -172,11 +172,12 @@ mod test {
let mut values = [DEFAULT; DELAY];
let mut t = 0;
let mut total_t = 0;
let mut output: f64 = 0.0;
let target = (TARGET - ERROR)..=(TARGET + ERROR);
while !values.iter().all(|value| target.contains(value)) && total_t < CYCLE_LIMIT {
let next_t = (t + 1) % DELAY;
// Feed the oldest temperature
let output = pid.update(values[next_t], Time::new::<second>(1.0), values[next_t]);
output = pid.update(values[next_t], Time::new::<second>(1.0), ElectricCurrent::new::<ampere>(output));
// Overwrite oldest with previous temperature - output
values[next_t] = values[t] + output - (values[t] - DEFAULT) * LOSS;
t = next_t;