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 2 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
17 changes: 15 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,16 @@ impl LedStatus {
} else {
None
};
let right_eye = match role {
Role::Loser => Eye::loser_eye(),
Role::Striker => Eye::striker_eye(),
Role::StrikerSupporter => Eye::striker_support_eye(),
Role::DefenderLeft | Role::DefenderRight => Eye::defender_eye(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe split this up, and split the colours in the eye based on the defender side? Might be useful!

Role::Keeper => Eye::keeper_eye(),
Role::ReplacementKeeper => Eye::keeper_replacement_eye(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Role::ReplacementKeeper => Eye::keeper_replacement_eye(),
Role::ReplacementKeeper => Eye::replacement_keeper_eye(),

Role::Searcher => Eye::searcher_eye(),
_ => Eye::default()
};
(
Eye {
color_at_0: ball_color_top
Expand All @@ -216,7 +229,7 @@ impl LedStatus {
color_at_315: ball_color_top
.unwrap_or_else(|| ball_background_color.unwrap_or(Rgb::BLACK)),
},
Eye::default(),
right_eye,
)
}
}
Expand Down
93 changes: 93 additions & 0 deletions crates/types/src/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,99 @@ pub struct Eye {
pub color_at_315: Rgb,
}

impl Eye {
pub 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),
}
}

pub fn striker_eye() -> Eye {
Eye {
color_at_0: Rgb::new(255, 0, 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User Rgb::Red

color_at_45: Rgb::new(255, 0, 0),
color_at_90: Rgb::new(255, 0, 0),
color_at_135: Rgb::new(255, 0, 0),
color_at_180: Rgb::new(255, 0, 0),
color_at_225: Rgb::new(255, 0, 0),
color_at_270: Rgb::new(255, 0, 0),
color_at_315: Rgb::new(255, 0, 0),
}
}

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

pub fn defender_eye() -> Eye {
Eye {
color_at_0: Rgb::new(255, 255, 255),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use rgb::white.

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(255, 255, 255),
color_at_225: Rgb::new(255, 255, 255),
color_at_270: Rgb::new(255, 255, 255),
color_at_315: Rgb::new(255, 255, 255),
}
}

pub fn keeper_eye() -> Eye {
Eye {
color_at_0: Rgb::new(0, 0, 255),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above

color_at_45: Rgb::new(0, 0, 255),
color_at_90: Rgb::new(0, 0, 255),
color_at_135: Rgb::new(0, 0, 255),
color_at_180: Rgb::new(0, 0, 255),
color_at_225: Rgb::new(0, 0, 255),
color_at_270: Rgb::new(0, 0, 255),
color_at_315: Rgb::new(0, 0, 255),
}
}

pub fn keeper_replacement_eye() -> Eye {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn keeper_replacement_eye() -> Eye {
pub 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),
}
}

pub 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),
}
}
}

impl From<Rgb> for Eye {
fn from(rgb: Rgb) -> Self {
Self {
Expand Down