Compare commits
2 Commits
a5dcd818b4
...
f13ab9deb9
Author | SHA1 | Date | |
---|---|---|---|
|
f13ab9deb9 | ||
|
1ad9e64340 |
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -205,6 +205,7 @@ name = "ev3dev-pid-linefollow"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ev3dev-lang-rust",
|
||||
"exec",
|
||||
"image",
|
||||
"imageproc",
|
||||
"itertools",
|
||||
@ -215,6 +216,16 @@ dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "exec"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "886b70328cba8871bfc025858e1de4be16b1d5088f2ba50b57816f4210672615"
|
||||
dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "exr"
|
||||
version = "1.5.2"
|
||||
|
@ -13,6 +13,7 @@ pid = "4.0"
|
||||
thiserror = "1.0"
|
||||
rand = "0.8"
|
||||
itertools = "0.10"
|
||||
exec = "0.3"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
33
src/main.rs
33
src/main.rs
@ -8,19 +8,30 @@ use display::{
|
||||
use ev3dev_lang_rust::{
|
||||
motors::LargeMotor, sensors::ColorSensor, Device, Ev3Error, Ev3Result, Screen,
|
||||
};
|
||||
use exec::execvp;
|
||||
use itertools::Itertools;
|
||||
use pid::Pid;
|
||||
use rand::{thread_rng, Rng};
|
||||
use rusttype::Font;
|
||||
use std::{
|
||||
env,
|
||||
error::Error,
|
||||
iter,
|
||||
iter, panic,
|
||||
thread::sleep,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
fn main() {
|
||||
while try_main().is_err() {
|
||||
// This loop just restarts the program in case of an error.
|
||||
// Such error may occur when a motor or sensor got disconnected.
|
||||
let args = env::args().collect_vec();
|
||||
panic::set_hook(Box::new(move |_| {
|
||||
let err = execvp(&args[0], &args[1..]);
|
||||
println!("Couldn't restart the program: {err}");
|
||||
}));
|
||||
while let Err(e) = try_main() {
|
||||
println!("Error: {e:?}");
|
||||
sleep(Duration::from_millis(10));
|
||||
}
|
||||
}
|
||||
@ -89,10 +100,24 @@ fn select_values(
|
||||
let mut k_d = thread_rng().gen_range(0.01..=10.0);
|
||||
let mut v = thread_rng().gen_range(1..=100);
|
||||
let mut selected = Kp;
|
||||
let mut times_pressed_up = 0;
|
||||
let mut times_pressed_down = 0;
|
||||
draw_settings(screen, k_p, k_i, k_d, v, selected, font);
|
||||
|
||||
loop {
|
||||
buttons.process();
|
||||
if buttons.is_up_pressed() {
|
||||
times_pressed_up = 0;
|
||||
}
|
||||
if buttons.is_down_pressed() {
|
||||
times_pressed_down = 0;
|
||||
}
|
||||
if buttons.is_up() {
|
||||
times_pressed_up += 1;
|
||||
}
|
||||
if buttons.is_down() {
|
||||
times_pressed_down += 1;
|
||||
}
|
||||
if buttons.is_enter_pressed() {
|
||||
break;
|
||||
}
|
||||
@ -130,7 +155,7 @@ fn select_values(
|
||||
};
|
||||
if buttons.is_up() {
|
||||
*param = (*param
|
||||
+ if buttons.is_up_pressed() {
|
||||
+ if times_pressed_up > 10 {
|
||||
0.01f32
|
||||
} else {
|
||||
0.1f32
|
||||
@ -139,7 +164,7 @@ fn select_values(
|
||||
}
|
||||
if buttons.is_down() {
|
||||
*param = (*param
|
||||
- if buttons.is_down_pressed() {
|
||||
- if times_pressed_down > 10 {
|
||||
0.01f32
|
||||
} else {
|
||||
0.1f32
|
||||
|
Loading…
Reference in New Issue
Block a user