builder pattern for configs
This commit is contained in:
parent
05c7904513
commit
21e269bc43
5 changed files with 67 additions and 11 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
[lib]
|
||||||
|
crate-type = ["dylib"]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "auto"
|
name = "auto"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -1,12 +1,29 @@
|
||||||
use std::{collections::VecDeque, ops::Sub};
|
use std::{collections::VecDeque, ops::Sub, pin::Pin};
|
||||||
|
|
||||||
use common::CamState;
|
use common::CamState;
|
||||||
use interface::auto::AutoInterface;
|
use interface::auto::{AutoInterface, Configurable};
|
||||||
|
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub fn entry(interface: AutoInterface) -> Pin<Box<dyn Future<Output = ()> + Send>> {
|
||||||
|
Box::pin(auto(interface))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub static NAME: &'static str = "scanseek v1";
|
||||||
|
|
||||||
const AUTO_GAP: i16 = 140; /// mm tofs must drop to count as a hit
|
const AUTO_GAP: i16 = 140; /// mm tofs must drop to count as a hit
|
||||||
const AUTO_SELF_OCCLUSION: u16 = 130; /// minimum
|
const AUTO_SELF_OCCLUSION: u16 = 130; /// minimum
|
||||||
|
|
||||||
async fn auto (interface: &AutoInterface) {
|
#[unsafe(no_mangle)]
|
||||||
|
pub static CONFIGS: &[Configurable] = &[
|
||||||
|
Configurable::new("auto minimum gap").range(0. .. 300.).default(140.)
|
||||||
|
.description("distance (mm) distance measurements must instantaneously drop to indicate a detection. This should line up with the size of the smallest robot you compete against"),
|
||||||
|
Configurable::new("auto self occlusion").range(0. .. 200.).default(143.)
|
||||||
|
.description("distance (mm) below which measurements are considered noise in the scan phase"),
|
||||||
|
];
|
||||||
|
|
||||||
|
async fn auto (interface: AutoInterface) {
|
||||||
let mut tof_l = Stats::new();
|
let mut tof_l = Stats::new();
|
||||||
let mut tof_r = Stats::new();
|
let mut tof_r = Stats::new();
|
||||||
loop {
|
loop {
|
||||||
|
|
22
interface/Cargo.lock
generated
22
interface/Cargo.lock
generated
|
@ -1060,9 +1060,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crunchy"
|
name = "crunchy"
|
||||||
version = "0.2.3"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929"
|
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
|
@ -1150,7 +1150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7d72e9c39f6e11a2e922d04a34ec5e7ef522ea3f5a1acfca7a19d16ad5fe50f5"
|
checksum = "7d72e9c39f6e11a2e922d04a34ec5e7ef522ea3f5a1acfca7a19d16ad5fe50f5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"emath",
|
"emath 0.30.0",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1201,7 +1201,7 @@ checksum = "252d52224d35be1535d7fd1d6139ce071fb42c9097773e79f7665604f5596b5e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"ahash",
|
"ahash",
|
||||||
"emath",
|
"emath 0.30.0",
|
||||||
"epaint",
|
"epaint",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
|
@ -1308,6 +1308,12 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "emath"
|
||||||
|
version = "0.31.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e4cadcff7a5353ba72b7fea76bf2122b5ebdbc68e8155aa56dfdea90083fe1b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embedded-io"
|
name = "embedded-io"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -1389,7 +1395,7 @@ dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"ecolor",
|
"ecolor",
|
||||||
"emath",
|
"emath 0.30.0",
|
||||||
"epaint_default_fonts",
|
"epaint_default_fonts",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
|
@ -1666,9 +1672,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glob"
|
name = "glob"
|
||||||
version = "0.3.2"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
|
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glow"
|
name = "glow"
|
||||||
|
@ -2124,9 +2130,11 @@ dependencies = [
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui-toast",
|
"egui-toast",
|
||||||
"egui_extras",
|
"egui_extras",
|
||||||
|
"emath 0.31.1",
|
||||||
"heapless",
|
"heapless",
|
||||||
"home",
|
"home",
|
||||||
"image",
|
"image",
|
||||||
|
"libloading",
|
||||||
"pitch-detection",
|
"pitch-detection",
|
||||||
"postcard",
|
"postcard",
|
||||||
"rust-music-theory",
|
"rust-music-theory",
|
||||||
|
|
|
@ -21,3 +21,5 @@ home = "0.5.11"
|
||||||
atomic_float = "1.1.0"
|
atomic_float = "1.1.0"
|
||||||
chrono = "0.4.40"
|
chrono = "0.4.40"
|
||||||
image = "0.25.5"
|
image = "0.25.5"
|
||||||
|
libloading = "0.8.6"
|
||||||
|
emath = "0.31.1"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::VecDeque, ops::{Div, Sub}};
|
use std::{collections::VecDeque, ops::{Div, Range, Sub}};
|
||||||
|
|
||||||
use common::{CamState, ControlPacket, SensorData};
|
use common::{CamState, ControlPacket, SensorData};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -28,11 +28,37 @@ impl AutoInterface {
|
||||||
|
|
||||||
pub struct Configurable {
|
pub struct Configurable {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
|
pub description: Option<&'static str>,
|
||||||
pub default: f32,
|
pub default: f32,
|
||||||
pub min: f32,
|
pub min: f32,
|
||||||
pub max: f32,
|
pub max: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Configurable {
|
||||||
|
pub const fn new(name: &'static str) -> Self {
|
||||||
|
Self { name, description: None, default: 0.0, min: 0.0, max: 1.0 }
|
||||||
|
}
|
||||||
|
pub const fn range(self, range: Range<f32>) -> Self {
|
||||||
|
Self { min: range.start, max: range.end, ..self }
|
||||||
|
}
|
||||||
|
pub const fn description(self, description: &'static str) -> Self {
|
||||||
|
Self { description: Some(description), ..self }
|
||||||
|
}
|
||||||
|
pub const fn default(self, default: f32) -> Self {
|
||||||
|
Self { default, ..self }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn name(&'static self) -> &'static str {
|
||||||
|
self.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Configurable {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { name: Default::default(), description: Default::default(), default: Default::default(), min: 0.0, max: 1.0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A fake trait in the sense that these methods are exposed as symbols, not trait methods
|
/// A fake trait in the sense that these methods are exposed as symbols, not trait methods
|
||||||
pub trait Auto {
|
pub trait Auto {
|
||||||
/// entrypoint
|
/// entrypoint
|
||||||
|
|
Loading…
Reference in a new issue