Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicate role using LED eye colors #119

Merged
merged 3 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 81 additions & 2 deletions crates/control/src/led_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
use color_eyre::Result;
use context_attribute::context;
use framework::{MainOutput, PerceptionInput};
use types::{Ball, CycleTime, Eye, FilteredWhistle, Leds, PrimaryState, Rgb};
use types::{Ball, CycleTime, Eye, FilteredWhistle, Leds, PrimaryState, Rgb, Role};

pub struct LedStatus {
blink_state: bool,
Expand All @@ -20,6 +20,7 @@ pub struct CycleContext {
pub primary_state: Input<PrimaryState, "primary_state">,
pub cycle_time: Input<CycleTime, "cycle_time">,
pub filtered_whistle: Input<FilteredWhistle, "filtered_whistle">,
pub role: Input<Role, "role">,

pub balls_bottom: PerceptionInput<Option<Vec<Ball>>, "VisionBottom", "balls?">,
pub balls_top: PerceptionInput<Option<Vec<Ball>>, "VisionTop", "balls?">,
Expand Down Expand Up @@ -147,6 +148,7 @@ impl LedStatus {
at_least_one_ball_data_bottom,
last_ball_data_top_too_old,
last_ball_data_bottom_too_old,
*context.role,
);

let ears = if context.filtered_whistle.is_detected {
Expand Down Expand Up @@ -176,6 +178,7 @@ impl LedStatus {
at_least_one_ball_data_bottom: bool,
last_ball_data_top_too_old: bool,
last_ball_data_bottom_too_old: bool,
role: Role,
) -> (Eye, Eye) {
match primary_state {
PrimaryState::Unstiff => {
Expand All @@ -199,6 +202,17 @@ impl LedStatus {
} else {
None
};
let right_eye = match role {
Role::Loser => Self::loser_eye(),
Role::Striker => Eye::from(Rgb::RED),
Role::StrikerSupporter => Eye::from(Rgb::ORANGE),
Role::DefenderLeft => Self::defender_eye_left(),
Role::DefenderRight => Self::defender_eye_right(),
Role::Keeper => Eye::from(Rgb::BLUE),
Role::ReplacementKeeper => Self::replacement_keeper_eye(),
Role::Searcher => Self::searcher_eye(),
_ => Eye::default(),
};
(
Eye {
color_at_0: ball_color_top
Expand All @@ -216,12 +230,77 @@ impl LedStatus {
color_at_315: ball_color_top
.unwrap_or_else(|| ball_background_color.unwrap_or(Rgb::BLACK)),
},
Eye::default(),
right_eye,
)
}
}
}

fn loser_eye() -> Eye {
Eye {
color_at_0: Rgb::new(255, 150, 255),
color_at_45: Rgb::new(25, 0, 25),
color_at_90: Rgb::new(255, 200, 25),
color_at_135: Rgb::new(55, 0, 255),
color_at_180: Rgb::new(255, 0, 25),
color_at_225: Rgb::new(25, 30, 255),
color_at_270: Rgb::new(255, 0, 255),
color_at_315: Rgb::new(255, 10, 5),
}
}

fn defender_eye_right() -> Eye {
Eye {
color_at_0: Rgb::new(0, 0, 0),
color_at_45: Rgb::new(0, 0, 0),
color_at_90: Rgb::new(0, 0, 0),
color_at_135: Rgb::new(0, 0, 0),
color_at_180: Rgb::new(0, 0, 0),
color_at_225: Rgb::new(255, 255, 255),
color_at_270: Rgb::new(255, 255, 255),
color_at_315: Rgb::new(255, 255, 255),
}
}

fn defender_eye_left() -> Eye {
Eye {
color_at_0: Rgb::new(0, 0, 0),
color_at_45: Rgb::new(255, 255, 255),
color_at_90: Rgb::new(255, 255, 255),
color_at_135: Rgb::new(255, 255, 255),
color_at_180: Rgb::new(0, 0, 0),
color_at_225: Rgb::new(0, 0, 0),
color_at_270: Rgb::new(0, 0, 0),
color_at_315: Rgb::new(0, 0, 0),
}
}

fn replacement_keeper_eye() -> Eye {
Eye {
color_at_0: Rgb::new(0, 220, 255),
color_at_45: Rgb::new(0, 220, 255),
color_at_90: Rgb::new(0, 220, 255),
color_at_135: Rgb::new(0, 220, 255),
color_at_180: Rgb::new(0, 220, 255),
color_at_225: Rgb::new(0, 220, 255),
color_at_270: Rgb::new(0, 220, 255),
color_at_315: Rgb::new(0, 220, 255),
}
}

fn searcher_eye() -> Eye {
Eye {
color_at_0: Rgb::new(255, 255, 0),
color_at_45: Rgb::new(0, 0, 255),
color_at_90: Rgb::new(255, 255, 0),
color_at_135: Rgb::new(0, 0, 255),
color_at_180: Rgb::new(255, 255, 0),
color_at_225: Rgb::new(0, 0, 255),
color_at_270: Rgb::new(255, 255, 0),
color_at_315: Rgb::new(0, 0, 255),
}
}

fn get_dnt_eye_dynamic(cycle_start_time: SystemTime) -> Eye {
let seconds = cycle_start_time
.duration_since(UNIX_EPOCH)
Expand Down
1 change: 1 addition & 0 deletions crates/types/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub struct Rgb {
impl Rgb {
pub const BLACK: Rgb = Rgb::new(0, 0, 0);
pub const RED: Rgb = Rgb::new(255, 0, 0);
pub const ORANGE: Rgb = Rgb::new(255, 120, 0);
pub const GREEN: Rgb = Rgb::new(0, 255, 0);
pub const BLUE: Rgb = Rgb::new(0, 0, 255);
pub const YELLOW: Rgb = Rgb::new(255, 220, 0);
Expand Down