Adjust scaling of parameters

This commit is contained in:
Max 2023-02-09 14:24:21 +01:00
parent f13ab9deb9
commit 33fdd0252f

View File

@ -71,7 +71,7 @@ fn try_main() -> Result<(), Box<dyn Error>> {
&sensor, &sensor,
&mut buttons, &mut buttons,
setpoint, setpoint,
(k_p / 10.0, k_i / 10000.0, k_d / 10000.0), (k_p / 5.0, k_i / 5000.0, k_d * 10.0),
v, v,
); );
left_motor.stop().and(right_motor.stop())?; left_motor.stop().and(right_motor.stop())?;
@ -95,10 +95,10 @@ fn select_values(
font: &Font, font: &Font,
) -> (f32, f32, f32, i32) { ) -> (f32, f32, f32, i32) {
use Parameter::{Kd, Ki, Kp, Speed}; use Parameter::{Kd, Ki, Kp, Speed};
let mut k_p = thread_rng().gen_range(0.01..=10.0); let mut k_p = 0.0; //thread_rng().gen_range(0.01..=10.0);
let mut k_i = thread_rng().gen_range(0.01..=10.0); let mut k_i = 0.0; //thread_rng().gen_range(0.01..=10.0);
let mut k_d = thread_rng().gen_range(0.01..=10.0); let mut k_d = 0.0; //thread_rng().gen_range(0.01..=10.0);
let mut v = thread_rng().gen_range(1..=100); let mut v = 0; //thread_rng().gen_range(1..=100);
let mut selected = Kp; let mut selected = Kp;
let mut times_pressed_up = 0; let mut times_pressed_up = 0;
let mut times_pressed_down = 0; let mut times_pressed_down = 0;
@ -156,18 +156,18 @@ fn select_values(
if buttons.is_up() { if buttons.is_up() {
*param = (*param *param = (*param
+ if times_pressed_up > 10 { + if times_pressed_up > 10 {
0.01f32
} else {
0.1f32 0.1f32
} else {
0.01f32
}) })
.min(99.99); .min(99.99);
} }
if buttons.is_down() { if buttons.is_down() {
*param = (*param *param = (*param
- if times_pressed_down > 10 { - if times_pressed_down > 10 {
0.01f32
} else {
0.1f32 0.1f32
} else {
0.01f32
}) })
.max(0.0); .max(0.0);
} }
@ -231,10 +231,7 @@ fn follow_line(
v: i32, v: i32,
) -> Result<Duration, ProgramError> { ) -> Result<Duration, ProgramError> {
let mut controller = Pid::new(setpoint, 200.0); let mut controller = Pid::new(setpoint, 200.0);
controller controller.p(k_p, 200.0).i(k_i, 200.0).d(k_d, 200.0);
.p(k_p, f32::INFINITY)
.i(k_i, f32::INFINITY)
.d(k_d, f32::INFINITY);
left.set_duty_cycle_sp(0)?; left.set_duty_cycle_sp(0)?;
right.set_duty_cycle_sp(0)?; right.set_duty_cycle_sp(0)?;
buttons.process(); buttons.process();
@ -253,7 +250,9 @@ fn follow_line(
let red = is_red(color); let red = is_red(color);
match state { match state {
LineFollowState::PreStart if red => state = LineFollowState::Start(Instant::now()), LineFollowState::PreStart if red => state = LineFollowState::Start(Instant::now()),
LineFollowState::Start(start) if !red => state = LineFollowState::Run(start), LineFollowState::Start(start) if !red && start.elapsed().as_secs() > 10 => {
state = LineFollowState::Run(start);
}
LineFollowState::Run(start) if red => state = LineFollowState::Finish(start.elapsed()), LineFollowState::Run(start) if red => state = LineFollowState::Finish(start.elapsed()),
_ => (), _ => (),
} }