Skip to content

Commit

Permalink
Filter kicking_team, including detections
Browse files Browse the repository at this point in the history
  • Loading branch information
ThagonDuarte committed Jan 11, 2025
1 parent 3de51fb commit 331812e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
4 changes: 4 additions & 0 deletions crates/control/src/ball_state_composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct CreationContext {}

#[context]
pub struct CycleContext {
last_ball_state: CyclerState<BallState, "last_ball_state">,

cycle_time: Input<CycleTime, "cycle_time">,
ball_position: Input<Option<BallPosition<Ground>>, "ball_position?">,
penalty_shot_direction: Input<Option<PenaltyShotDirection>, "penalty_shot_direction?">,
Expand Down Expand Up @@ -125,6 +127,8 @@ impl BallStateComposer {
_ => None,
};

*context.last_ball_state = ball.unwrap_or(BallState::default());

Ok(MainOutputs {
ball_state: ball.into(),
rule_ball_state: rule_ball.into(),
Expand Down
9 changes: 4 additions & 5 deletions crates/control/src/free_kick_signal_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use spl_network_messages::{HulkMessage, PlayerNumber, Team, VisualRefereeMessage
use types::{
cycle_time::CycleTime,
field_dimensions::GlobalFieldSide,
filtered_game_controller_state::FilteredGameControllerState,
game_controller_state::GameControllerState,
messages::{IncomingMessage, OutgoingMessage},
players::Players,
pose_detection::{FreeKickSignalDetectionResult, TimeTaggedKickingTeamDetections},
Expand All @@ -39,8 +39,7 @@ pub struct CycleContext {
referee_pose_kind:
PerceptionInput<Option<PoseKind>, "ObjectDetectionTop", "referee_pose_kind?">,
network_message: PerceptionInput<Option<IncomingMessage>, "SplNetwork", "filtered_message?">,
filtered_game_controller_state:
RequiredInput<Option<FilteredGameControllerState>, "filtered_game_controller_state?">,
game_controller_state: RequiredInput<Option<GameControllerState>, "game_controller_state?">,

cycle_time: Input<CycleTime, "cycle_time">,

Expand Down Expand Up @@ -126,8 +125,8 @@ impl FreeKickSignalFilter {
let detected_kicking_team = kicking_team_from_free_kick_signal_detection(
detection,
context
.filtered_game_controller_state
.own_team_is_home_after_coin_toss,
.game_controller_state
.hulks_team_is_home_after_coin_toss,
);
if let Some(detected_kicking_team) = detected_kicking_team {
self.detected_free_kick_detections_queue
Expand Down
3 changes: 2 additions & 1 deletion crates/control/src/game_controller_state_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct CycleContext {
cycle_time: Input<CycleTime, "cycle_time">,
filtered_whistle: Input<FilteredWhistle, "filtered_whistle">,
visual_referee_proceed_to_ready: Input<bool, "visual_referee_proceed_to_ready">,
filtered_kicking_team: Input<Option<Team>, "filtered_kicking_team?">,
game_controller_state: RequiredInput<Option<GameControllerState>, "game_controller_state?">,
config: Parameter<GameStateFilterParameters, "game_state_filter">,
field_dimensions: Parameter<FieldDimensions, "field_dimensions">,
Expand Down Expand Up @@ -97,7 +98,7 @@ impl GameControllerStateFilter {
game_state: game_states.own,
opponent_game_state: game_states.opponent,
game_phase: context.game_controller_state.game_phase,
kicking_team: context.game_controller_state.kicking_team,
kicking_team: context.filtered_kicking_team.copied(),
penalties: context.game_controller_state.penalties,
remaining_number_of_messages: context
.game_controller_state
Expand Down
70 changes: 70 additions & 0 deletions crates/control/src/kicking_team_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use color_eyre::Result;
use serde::{Deserialize, Serialize};

use context_attribute::context;
use framework::MainOutput;
use spl_network_messages::{SubState, Team};
use types::{game_controller_state::GameControllerState, world_state::BallState};

#[derive(Deserialize, Serialize)]
pub struct KickingTeamFilter {}

#[context]
pub struct CreationContext {}

#[context]
pub struct CycleContext {
last_ball_state: CyclerState<BallState, "last_ball_position">,
game_controller_state: RequiredInput<Option<GameControllerState>, "game_controller_state?">,
detected_free_kick_kicking_team: Input<Option<Team>, "detected_free_kick_kicking_team?">,
}

#[context]
pub struct MainOutputs {
pub filtered_kicking_team: MainOutput<Option<Team>>,
}

impl KickingTeamFilter {
pub fn new(_context: CreationContext) -> Result<Self> {
Ok(KickingTeamFilter {})
}

pub fn cycle(&mut self, context: CycleContext) -> Result<MainOutputs> {
let game_controller_state = context.game_controller_state;
let sub_state = context.game_controller_state.sub_state;
let last_ball_state = context.last_ball_state;

let filtered_kicking_team = if game_controller_state.kicking_team.is_some() {
game_controller_state.kicking_team
} else if context.detected_free_kick_kicking_team.is_some() {
context.detected_free_kick_kicking_team.copied()
} else {
match sub_state {
Some(SubState::CornerKick)
if last_ball_state.ball_in_field.x().is_sign_positive() =>
{
Some(Team::Hulks)
}
Some(SubState::CornerKick)
if last_ball_state.ball_in_field.x().is_sign_negative() =>
{
Some(Team::Opponent)
}
Some(SubState::GoalKick)
if last_ball_state.ball_in_field.x().is_sign_positive() =>
{
Some(Team::Opponent)
}
Some(SubState::GoalKick)
if last_ball_state.ball_in_field.x().is_sign_negative() =>
{
Some(Team::Hulks)
}
_ => None,
}
};
Ok(MainOutputs {
filtered_kicking_team: filtered_kicking_team.into(),
})
}
}
1 change: 1 addition & 0 deletions crates/control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod game_controller_state_filter;
pub mod ground_contact_detector;
pub mod ground_provider;
pub mod kick_selector;
pub mod kicking_team_filter;
pub mod kinematics_provider;
pub mod led_status;
pub mod localization;
Expand Down
1 change: 1 addition & 0 deletions crates/hulk_manifest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn collect_hulk_cyclers() -> Result<Cyclers, Error> {
"control::ground_contact_detector",
"control::ground_provider",
"control::kick_selector",
"control::kicking_team_filter",
"control::kinematics_provider",
"control::led_status",
"control::localization",
Expand Down

0 comments on commit 331812e

Please sign in to comment.