Loop
This commit is contained in:
parent
63534c7e05
commit
a5dc6f15af
43
src/main.rs
43
src/main.rs
@ -37,32 +37,31 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let white = calibrate_gray(&mut screen, &sensor, &mut buttons, "Weiß", &font)?;
|
||||
let setpoint = (black + white) / 2.0;
|
||||
|
||||
let (k_p, k_i, k_d, v) = select_values(&mut screen, &mut buttons, &font);
|
||||
loop {
|
||||
let (k_p, k_i, k_d, v) = select_values(&mut screen, &mut buttons, &font);
|
||||
|
||||
draw_driving(&mut screen, &font);
|
||||
draw_driving(&mut screen, &font);
|
||||
let result = follow_line(
|
||||
(&left_motor, &right_motor),
|
||||
&sensor,
|
||||
&mut buttons,
|
||||
setpoint,
|
||||
(k_p / 10.0, k_i / 100.0, k_d / 100.0),
|
||||
v,
|
||||
);
|
||||
left_motor.stop().and(right_motor.stop())?;
|
||||
let time = match result {
|
||||
Ok(time) => time,
|
||||
Err(ProgramError::UserAbort) => continue,
|
||||
e => e?,
|
||||
};
|
||||
|
||||
let result = follow_line(
|
||||
(&left_motor, &right_motor),
|
||||
&sensor,
|
||||
&mut buttons,
|
||||
setpoint,
|
||||
(k_p / 10.0, k_i, k_d),
|
||||
v,
|
||||
);
|
||||
left_motor.stop().and(right_motor.stop())?;
|
||||
let time = match result {
|
||||
Ok(time) => time,
|
||||
Err(ProgramError::UserAbort) => return Ok(()),
|
||||
e => e?,
|
||||
};
|
||||
|
||||
buttons.process();
|
||||
draw_finished(&mut screen, time, &font);
|
||||
while !buttons.is_enter_pressed() {
|
||||
draw_finished(&mut screen, time, &font);
|
||||
buttons.process();
|
||||
while !buttons.is_enter_pressed() {
|
||||
buttons.process();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn select_values(
|
||||
|
Loading…
Reference in New Issue
Block a user