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

Reset detection time in referee_pose_detection_filter #1333

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions crates/control/src/referee_pose_detection_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use serde::{Deserialize, Serialize};
use context_attribute::context;
use framework::{AdditionalOutput, MainOutput, PerceptionInput};
use hardware::NetworkInterface;
use spl_network_messages::{HulkMessage, PlayerNumber, VisualRefereeMessage};
use spl_network_messages::{GameState, HulkMessage, PlayerNumber, VisualRefereeMessage};
use types::{
cycle_time::CycleTime,
game_controller_state::GameControllerState,
messages::{IncomingMessage, OutgoingMessage},
players::Players,
pose_detection::VisualRefereeState,
Expand Down Expand Up @@ -41,7 +42,7 @@ pub struct CycleContext {
network_message: PerceptionInput<Option<IncomingMessage>, "SplNetwork", "filtered_message?">,

cycle_time: Input<CycleTime, "cycle_time">,

game_controller_state: Input<Option<GameControllerState>, "game_controller_state?">,
initial_message_grace_period:
Parameter<Duration, "referee_pose_detection_filter.initial_message_grace_period">,
minimum_above_head_arms_detections:
Expand Down Expand Up @@ -85,6 +86,17 @@ impl RefereePoseDetectionFilter {
let (is_referee_ready_pose_detected, did_detect_any_referee_this_cycle) =
self.update(&context)?;

let is_standby = matches!(
context.game_controller_state,
Some(GameControllerState {
game_state: GameState::Standby,
..
})
);
if !is_standby {
self.detection_times = Default::default();
}

let majority_vote_is_referee_ready_pose_detected = decide(
self.detection_times,
cycle_start_time,
Expand Down
33 changes: 25 additions & 8 deletions crates/control/src/sacrificial_lamb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ use std::{
use context_attribute::context;
use framework::{AdditionalOutput, MainOutput, PerceptionInput};
use serde::{Deserialize, Serialize};
use spl_network_messages::{GameControllerStateMessage, Penalty, PlayerNumber};
use types::{cycle_time::CycleTime, messages::IncomingMessage, pose_detection::VisualRefereeState};
use spl_network_messages::{GameControllerStateMessage, GameState, Penalty, PlayerNumber};
use types::{
cycle_time::CycleTime, game_controller_state::GameControllerState, messages::IncomingMessage,
pose_detection::VisualRefereeState,
};

#[derive(Deserialize, Serialize)]
pub struct SacrificialLamb {
Expand All @@ -22,6 +25,8 @@ pub struct CreationContext {}

#[context]
pub struct CycleContext {
game_controller_state: Input<Option<GameControllerState>, "game_controller_state?">,

network_message: PerceptionInput<Option<IncomingMessage>, "SplNetwork", "filtered_message?">,

cycle_time: Input<CycleTime, "cycle_time">,
Expand Down Expand Up @@ -92,12 +97,21 @@ impl SacrificialLamb {
motion_in_standby
});

let is_standby = matches!(
context.game_controller_state,
Some(GameControllerState {
game_state: GameState::Standby,
..
})
);

self.visual_referee_state = match (
self.visual_referee_state,
current_majority_vote_verdict,
motion_in_standby,
is_standby,
) {
(VisualRefereeState::WaitingForDetections, true, motion_in_standby) => {
(VisualRefereeState::WaitingForDetections, true, motion_in_standby, _) => {
if motion_in_standby {
VisualRefereeState::WaitingForDetections
} else {
Expand All @@ -106,10 +120,10 @@ impl SacrificialLamb {
}
}
}
(VisualRefereeState::WaitingForOpponentPenalties { .. }, _, true) => {
(VisualRefereeState::WaitingForOpponentPenalties { .. }, _, true, _) => {
VisualRefereeState::WaitingForDetections
}
(VisualRefereeState::WaitingForOpponentPenalties { active_since }, _, false) => {
(VisualRefereeState::WaitingForOpponentPenalties { active_since }, _, false, _) => {
if cycle_start_time
.duration_since(active_since)
.expect("time ran backwards")
Expand All @@ -126,10 +140,10 @@ impl SacrificialLamb {
VisualRefereeState::WaitingForOpponentPenalties { active_since }
}
}
(VisualRefereeState::WaitingForOwnPenalties { .. }, _, true) => {
(VisualRefereeState::WaitingForOwnPenalties { .. }, _, true, _) => {
VisualRefereeState::WaitingForDetections
}
(VisualRefereeState::WaitingForOwnPenalties { active_since }, _, false) => {
(VisualRefereeState::WaitingForOwnPenalties { active_since }, _, false, _) => {
if cycle_start_time
.duration_since(active_since)
.expect("time ran backwards")
Expand All @@ -140,7 +154,10 @@ impl SacrificialLamb {
VisualRefereeState::WaitingForOwnPenalties { active_since }
}
}
(current_state, _, _) => current_state,
(VisualRefereeState::GoToReady, _, _, false) => {
VisualRefereeState::WaitingForDetections
}
(current_state, _, _, _) => current_state,
};

context
Expand Down
Loading