melvin_ob/scheduling/task/
image_task.rs

1use crate::imaging::CameraAngle;
2use crate::util::Vec2D;
3use fixed::types::I64F64;
4
5/// Represents the status of an image capture task.
6#[derive(Debug, Copy, Clone)]
7pub enum ImageTaskStatus {
8    /// The task is planned but has not yet been completed.
9    Planned,
10    /// The task has been completed, including metadata for the actual capture.
11    Done {
12        /// The actual position where the capture occurred.
13        actual_pos: Vec2D<u32>,
14        /// The relative number of pixels which deviate from the planned picture.
15        px_dev_rel: I64F64,
16    },
17}
18
19/// Represents a specific image capture task, including timing, planning,
20/// and lens configuration.
21#[derive(Debug, Copy, Clone)]
22pub struct ImageTask {
23    /// The current status of the task (e.g., `Planned` or `Done`).
24    pub(crate) image_status: ImageTaskStatus,
25    /// The target position for the image capture.
26    pub(crate) planned_pos: Vec2D<u32>,
27    /// The lens configuration for the capture.
28    pub(crate) lens: CameraAngle,
29}
30
31impl ImageTask {
32    /// Creates a new instance of an [`ImageTask`].
33    ///
34    /// # Arguments
35    /// - `dt`: The planned time delay before the task execution.
36    /// - `planned_pos`: The target position for the image capture.
37    /// - `lens`: The lens configuration for the capture.
38    ///
39    /// # Returns
40    /// - A new [`ImageTask`] instance with the given parameters.
41    pub fn new(planned_pos: Vec2D<u32>, lens: CameraAngle) -> Self {
42        Self { image_status: ImageTaskStatus::Planned, planned_pos, lens }
43    }
44
45    /// Marks the task as completed and records the actual capture position.
46    ///
47    /// # Arguments
48    /// - `actual_pos`: The position where the image was actually captured.
49    ///
50    /// # Side Effects
51    /// - Updates the task status to `Done`, including deviation from
52    ///   the planned position.
53    pub fn done(&mut self, actual_pos: Vec2D<u32>) {
54        let square_side = f64::from(self.lens.get_square_side_length());
55        let center_dev_x = (f64::from(self.planned_pos.x()) - f64::from(actual_pos.x())).abs();
56        let center_dev_y = (f64::from(self.planned_pos.y()) - f64::from(actual_pos.y())).abs();
57        let px_dev = square_side * center_dev_x + (square_side - center_dev_x) * center_dev_y;
58        let px_dev_rel = I64F64::from_num(px_dev / (square_side * square_side));
59        let new_status = ImageTaskStatus::Done { actual_pos, px_dev_rel };
60        self.image_status = new_status;
61    }
62}