diff --git a/crates/parameters/src/directory.rs b/crates/parameters/src/directory.rs index 7ad9477e74..86568d9c74 100644 --- a/crates/parameters/src/directory.rs +++ b/crates/parameters/src/directory.rs @@ -163,6 +163,13 @@ pub struct Scope { } impl Scope { + pub fn default_location() -> Self { + Self { + location: Location::All, + id: Id::All, + } + } + pub fn default_head() -> Self { Self { location: Location::All, @@ -170,6 +177,13 @@ impl Scope { } } + pub fn current_location() -> Self { + Self { + location: Location::Current, + id: Id::All, + } + } + pub fn current_head() -> Self { Self { location: Location::Current, diff --git a/etc/parameters/rc24_indoor/default.json b/etc/parameters/rc24_indoor/default.json index 364db24e5f..97a223bce7 100644 --- a/etc/parameters/rc24_indoor/default.json +++ b/etc/parameters/rc24_indoor/default.json @@ -1,29 +1,9 @@ { - "image_segmenter": { - "vision_top": { - "vertical_edge_threshold": 10 - }, - "vision_bottom": { - "vertical_edge_threshold": 15, - "vertical_median_mode": "FivePixels" - } - }, - "line_detection": { - "vision_top": { - "allowed_projected_segment_length": { - "start": 0.02 - }, - "gradient_alignment": -0.8 - }, - "vision_bottom": { - "gradient_alignment": -0.8 - } - }, "field_color_detection": { "vision_bottom": { "saturation": { - "start": 95, - "end": 255 + "end": 255, + "start": 95 } }, "vision_top": { @@ -36,5 +16,25 @@ "start": 63 } } + }, + "image_segmenter": { + "vision_bottom": { + "vertical_edge_threshold": 15, + "vertical_median_mode": "FivePixels" + }, + "vision_top": { + "vertical_edge_threshold": 10 + } + }, + "line_detection": { + "vision_bottom": { + "gradient_alignment": -0.8 + }, + "vision_top": { + "allowed_projected_segment_length": { + "start": 0.02 + }, + "gradient_alignment": -0.8 + } } } diff --git a/tools/twix/src/panels/vision_tuner.rs b/tools/twix/src/panels/vision_tuner.rs index 6f813add6f..ede5aa22e6 100644 --- a/tools/twix/src/panels/vision_tuner.rs +++ b/tools/twix/src/panels/vision_tuner.rs @@ -1,18 +1,19 @@ use std::{ops::RangeInclusive, sync::Arc}; -use color_eyre::Result; +use color_eyre::{eyre::OptionExt, Result}; use communication::messages::TextOrBinary; use eframe::{ egui::{Grid, Response, Slider, Ui, Widget}, emath::Numeric, }; use log::error; +use parameters::directory::Scope; use serde::Serialize; use serde_json::{to_value, Value}; use types::{field_color::FieldColorParameters, image_segments::Direction}; -use crate::{nao::Nao, panel::Panel, value_buffer::BufferHandle}; +use crate::{log_error::LogError, nao::Nao, panel::Panel, value_buffer::BufferHandle}; use super::image::cycler_selector::{VisionCycler, VisionCyclerSelector}; @@ -75,6 +76,58 @@ impl VisionTunerPanel { } ui.end_row(); } + + fn save_field_color_parameters(&self, scope: Scope) -> Result<()> { + let cycler = self.cycler.as_snake_case_path(); + + let parameters = self + .field_color_detection + .get_last_value()? + .ok_or_eyre("unable to retrieve parameters, nothing was saved.")?; + + let value = to_value(parameters).unwrap(); + + self.nao + .store_parameters(&format!("field_color_detection.{cycler}"), value, scope)?; + + Ok(()) + } + + fn save_image_segmenter_parameters(&self, scope: Scope) -> Result<()> { + let cycler = self.cycler.as_snake_case_path(); + + let horizontal_edge_threshold = self + .horizontal_edge_threshold + .get_last_value()? + .ok_or_eyre("unable to retrieve horizontal_edge_threshold, nothing was saved.")?; + let vertical_edge_threshold = self + .vertical_edge_threshold + .get_last_value()? + .ok_or_eyre("unable to retrieve vertical_edge_threshold, nothing was saved.")?; + + let horizontal_edge_threshold_value = to_value(horizontal_edge_threshold).unwrap(); + let vertical_edge_threshold_value = to_value(vertical_edge_threshold).unwrap(); + + self.nao.store_parameters( + &format!("image_segmenter.{cycler}.horizontal_edge_threshold"), + horizontal_edge_threshold_value, + scope, + )?; + self.nao.store_parameters( + &format!("image_segmenter.{cycler}.vertical_edge_threshold"), + vertical_edge_threshold_value, + scope, + )?; + + Ok(()) + } + + fn save(&self, scope: Scope) -> Result<()> { + self.save_field_color_parameters(scope)?; + self.save_image_segmenter_parameters(scope)?; + + Ok(()) + } } impl Panel for VisionTunerPanel { @@ -112,6 +165,9 @@ impl Widget for &mut VisionTunerPanel { if cycler_selector.ui(ui).changed() { self.resubscribe(); } + if ui.button("Save to current location").clicked() { + self.save(Scope::current_location()).log_err(); + } }); ui.separator(); let cycler = self.cycler.as_snake_case_path();