Skip to content

Commit

Permalink
added SystemTime as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
phillip kammradt committed Apr 18, 2024
1 parent e26b637 commit 4311a0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
29 changes: 13 additions & 16 deletions crates/control/src/behavior/dribble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,21 @@ fn is_kick_pose_reached(
is_x_reached && is_y_reached && is_orientation_reached
}

pub fn precision_kick(game_controller_state: Option<FilteredGameControllerState>, precision_kick_timeout: u8) -> bool {
let game_controller_state = game_controller_state.unwrap_or(FilteredGameControllerState {
last_game_state_change: SystemTime::now(),
game_state: Default::default(),
opponent_game_state: Default::default(),
game_phase: Default::default(),
kicking_team: Default::default(),
penalties: Default::default(),
remaining_number_of_messages: Default::default(),
sub_state: Default::default(),
own_team_is_home_after_coin_toss: Default::default(),
});
pub fn precision_kick(
game_controller_state: Option<FilteredGameControllerState>,
precision_kick_timeout: u8,
) -> bool {
let game_controller_state = game_controller_state.unwrap_or_default();

let now = SystemTime::now();
let time_difference = game_controller_state
.last_game_state_change
.duration_since(now)
.expect("time ran backwords");
let time_difference = game_controller_state.last_game_state_change.map_or(
Duration::new(0, 0),
|last_game_state_change| {
last_game_state_change
.duration_since(now)
.expect("time ran backwords")
},
);

let penalty_shootout = matches!(
game_controller_state.game_phase,
Expand Down
3 changes: 1 addition & 2 deletions crates/control/src/game_controller_state_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ impl GameControllerStateFilter {
own_team_is_home_after_coin_toss: context
.game_controller_state
.hulks_team_is_home_after_coin_toss,
last_game_state_change: context.game_controller_state.last_game_state_change,

last_game_state_change: Some(context.game_controller_state.last_game_state_change),
};
Ok(MainOutputs {
filtered_game_controller_state: Some(filtered_game_controller_state).into(),
Expand Down
4 changes: 2 additions & 2 deletions crates/types/src/filtered_game_controller_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use spl_network_messages::{GamePhase, Penalty, SubState, Team};

use crate::{filtered_game_state::FilteredGameState, players::Players};

#[derive(Clone, Copy, Debug, Serialize, Deserialize, SerializeHierarchy)]
#[derive(Default, Clone, Copy, Debug, Serialize, Deserialize, SerializeHierarchy)]
pub struct FilteredGameControllerState {
pub game_state: FilteredGameState,
pub opponent_game_state: FilteredGameState,
Expand All @@ -16,5 +16,5 @@ pub struct FilteredGameControllerState {
pub remaining_number_of_messages: u16,
pub sub_state: Option<SubState>,
pub own_team_is_home_after_coin_toss: bool,
pub last_game_state_change: SystemTime,
pub last_game_state_change: Option<SystemTime>,
}
11 changes: 2 additions & 9 deletions tools/behavior_simulator/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
collections::{BTreeMap, HashMap},
f32::consts::FRAC_PI_4,
mem::take,
time::{Duration, SystemTime, UNIX_EPOCH},
time::{Duration, UNIX_EPOCH},
};

use color_eyre::Result;
Expand Down Expand Up @@ -241,14 +241,7 @@ impl State {
robot.database.main_outputs.filtered_game_controller_state =
Some(FilteredGameControllerState {
game_state: self.filtered_game_state,
last_game_state_change: SystemTime::now(),
opponent_game_state: Default::default(),
game_phase: Default::default(),
kicking_team: Default::default(),
penalties: Default::default(),
remaining_number_of_messages: Default::default(),
sub_state: Default::default(),
own_team_is_home_after_coin_toss: Default::default(),
..Default::default()
});
robot.database.main_outputs.game_controller_state = Some(self.game_controller_state);

Expand Down

0 comments on commit 4311a0c

Please sign in to comment.