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

Time to reach rework #1634

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4dee08c
Time to reach preparation
knoellle Jan 29, 2025
e913108
Remove team_ball from role assignment outputs
knoellle Jan 31, 2025
0e3bbc5
Add test to ensure that role state machine is idempotent for Event::None
knoellle Jan 31, 2025
c3f96ab
Make use of idempotence
knoellle Jan 31, 2025
342f6b6
Add testcase for LoserMessage byte size
knoellle Jan 31, 2025
989ed09
Divorce role state machine from logic if we want to send a striker me…
knoellle Feb 1, 2025
df56fc3
Clean up message sending logic
knoellle Feb 4, 2025
ff8aad8
Visualize role colors in behavior simulator panel
knoellle Feb 15, 2025
1aa696a
Correct striker counting in golden_goal_striker_penalized
knoellle Feb 15, 2025
d63025a
Use correct axis to determine corner kick side
knoellle Feb 15, 2025
9c73884
Decay velocity in simulated ball model
knoellle Feb 15, 2025
b556d98
Set the correct time in simulator interfake
knoellle Feb 15, 2025
cb88a5f
Add additional outputs for team ball data
knoellle Feb 15, 2025
10e2bd0
Implement sending loser messages
knoellle Feb 15, 2025
e4c9080
Clean up team ball receiver
knoellle Feb 15, 2025
114ef95
Clean up
knoellle Feb 15, 2025
5c0aa26
Don't send striker messages in penalty shootout
knoellle Feb 15, 2025
dbbc73c
Make sure team ball is kept longer than striker beacon interval + max…
knoellle Feb 16, 2025
895abb6
Render player number
knoellle Feb 16, 2025
49c03d9
Add range check to kicking ball
knoellle Feb 16, 2025
a28135a
Check if keeper becomes striker in reappearing_ball_in_front_of_keeper
knoellle Feb 16, 2025
59c3f0e
Clean up unused code
knoellle Feb 16, 2025
5a1e054
Fix replacement keeper switch time logic
knoellle Feb 16, 2025
107d970
Check if goal is scored in walk_around_ball scenario and tell robot w…
knoellle Feb 16, 2025
a26bb94
uSe oF UnStAbLe lIbRaRy fEaTuRe 'is_none_or'
knoellle Feb 16, 2025
3af4141
Replace test-case with proptest
knoellle Feb 16, 2025
97acb09
Fix stand_up_back motion
knoellle Mar 5, 2025
5a81840
Add regression test for keeper getting stuck in loser role
knoellle Mar 5, 2025
ad04fac
Make time to reach an Option
knoellle Mar 5, 2025
8a23bcc
Allow robots to become (replacement)keeper instead of loser/searcher
knoellle Mar 5, 2025
500c7b1
Only consider striker events for striker message timeout
knoellle Mar 5, 2025
beb75a1
Add test scenario to ensure robots can become striker from being sent…
knoellle Mar 5, 2025
e197cb4
Make time to reach not an Option in Striker Message
knoellle Mar 5, 2025
9e818fd
Clean up duration calculations
knoellle Mar 7, 2025
0a2e6b7
Process loser messages
knoellle Mar 7, 2025
58db637
Ignore team balls and network obstacles in penalty kick states
knoellle Mar 7, 2025
109d17e
Reimplement using network messages as obstacle percepts
knoellle Mar 7, 2025
0271399
Move obstacle extraction to separate node
knoellle Mar 9, 2025
cb71bb8
Avoid using Role::default()
knoellle Mar 9, 2025
b2743eb
Simplify unwrap_or(Striker)
knoellle Mar 9, 2025
1ad68a7
Clarify variable name
knoellle Mar 9, 2025
b4127db
Update last_time_player_was_penalized before using it this cycle
knoellle Mar 9, 2025
272c6af
Remove note about sending message from comment
knoellle Mar 9, 2025
d31c12b
Make staying (replacement) keeper easier to read
knoellle Mar 9, 2025
bd96ae8
Drop todo about striker edgecase
knoellle Mar 9, 2025
a7fb226
Don't use a default ground_to_field globally
knoellle Mar 9, 2025
58c42a0
Initialize role in new()
knoellle Mar 9, 2025
d2feffa
Extract gathering messages to function
knoellle Mar 9, 2025
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
67 changes: 65 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ prettyplease = "0.2.29"
proc-macro-error = "1.0.4"
proc-macro2 = { version = "1.0.93", features = ["span-locations"] }
projection = { path = "crates/projection" }
proptest = "1.6.0"
quote = "1.0.38"
rand = "0.9.0"
rand_chacha = { version = "0.9.0", features = ["serde"] }
Expand Down
6 changes: 4 additions & 2 deletions crates/bevyhavior_simulator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ fn main() -> Result<()> {
"control::active_vision",
"control::ball_state_composer",
"control::behavior::node",
"control::dribble_path_planner",
"control::filtered_game_controller_state_timer",
"control::game_controller_state_filter",
"control::kick_selector",
"control::filtered_game_controller_state_timer",
"control::primary_state_filter",
"control::motion::look_around",
"control::motion::motion_selector",
"control::penalty_shot_direction_estimation",
"control::primary_state_filter",
"control::referee_position_provider",
"control::role_assignment",
"control::rule_obstacle_composer",
"control::search_suggestor",
"control::team_ball_receiver",
"control::time_to_reach_kick_position",
"control::world_state_composer",
],
Expand Down
2 changes: 1 addition & 1 deletion crates/bevyhavior_simulator/src/autoref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn auto_assistant_referee(
GameControllerCommand::SetGamePhase(_) => {}
GameControllerCommand::SetSubState(Some(SubState::CornerKick), team) => {
let side = if let Some(ball) = ball.state.as_mut() {
if ball.position.x() >= 0.0 {
if ball.position.y() <= 0.0 {
Side::Left
} else {
Side::Right
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bevyhavior_simulator::{
robot::Robot,
time::{Ticks, TicksTime},
};
use types::roles::Role;
use types::{primary_state::PrimaryState, roles::Role};

#[scenario]
fn golden_goal(app: &mut App) {
Expand Down Expand Up @@ -59,14 +59,15 @@ fn update(

let striker_count = robots
.iter()
.filter(|robot| robot.database.main_outputs.primary_state != PrimaryState::Penalized)
.filter(|robot| robot.database.main_outputs.role == Role::Striker)
.count();
if game_controller.state.game_state == GameState::Set {
if striker_count == 1 {
println!("Striker is present");
println!("One striker is present");
exit.send(AppExit::Success);
} else {
println!("No striker");
println!("Error: Found {striker_count} strikers!");
exit.send(AppExit::from_code(1));
}
}
Expand Down
77 changes: 77 additions & 0 deletions crates/bevyhavior_simulator/src/bin/keeper_returns_after_loser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use bevy::prelude::*;

use bevyhavior_simulator::{
ball::BallResource,
game_controller::{GameController, GameControllerCommand},
robot::Robot,
time::{Ticks, TicksTime},
};
use linear_algebra::{point, Vector2};
use scenario::scenario;
use spl_network_messages::{GameState, PlayerNumber};
use types::roles::Role;

/// Regression test against an offensive keeper staying loser and never returning to the goal when losing the ball.
/// We lead the keeper away from the goal, then put the ball in front of the goal again.
/// If implemented correctly, the keeper should switch from loser to keeper after a short amount of
/// time.
#[scenario]
fn keeper_returns_after_loser(app: &mut App) {
app.add_systems(Startup, startup);
app.add_systems(Update, update);
}

fn startup(
mut commands: Commands,
mut game_controller_commands: EventWriter<GameControllerCommand>,
) {
for number in [PlayerNumber::One, PlayerNumber::Seven] {
commands.spawn(Robot::new(number));
}
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
}

fn update(
game_controller: ResMut<GameController>,
time: Res<Time<Ticks>>,
mut ball: ResMut<BallResource>,
robots: Query<&Robot>,
mut exit: EventWriter<AppExit>,
mut keeper_was_striker_again: Local<bool>,
) {
if time.ticks() == 2800 {
if let Some(ball) = ball.state.as_mut() {
ball.position = point![-3.8, 0.0];
ball.velocity = Vector2::zeros();
}
}
if time.ticks() == 6000 {
if let Some(ball) = ball.state.as_mut() {
ball.position = point![-3.8, 0.0];
ball.velocity = Vector2::zeros();
}
}

if time.ticks() > 6500 {
for robot in robots.iter() {
if robot.parameters.player_number == PlayerNumber::One
&& robot.database.main_outputs.role == Role::Striker
{
*keeper_was_striker_again = true;
}
}
}

if game_controller.state.hulks_team.score > 0 {
println!("Done");
exit.send(AppExit::Success);
}

if time.ticks() >= 15_000 {
if !*keeper_was_striker_again {
println!("Error: Keeper did not become striker again");
}
println!("No goal was scored :(");
exit.send(AppExit::from_code(1));
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use bevy::prelude::*;

use linear_algebra::point;
use scenario::scenario;
use spl_network_messages::{GameState, PlayerNumber};

use bevyhavior_simulator::{
ball::BallResource,
game_controller::{GameController, GameControllerCommand},
robot::Robot,
time::{Ticks, TicksTime},
};
use linear_algebra::point;
use scenario::scenario;
use spl_network_messages::{GameState, PlayerNumber};
use types::roles::Role;

#[scenario]
fn reappearing_ball_in_front_of_keeper(app: &mut App) {
Expand Down Expand Up @@ -39,14 +39,31 @@ fn update(
game_controller: ResMut<GameController>,
time: Res<Time<Ticks>>,
mut ball: ResMut<BallResource>,
robots: Query<&Robot>,
mut exit: EventWriter<AppExit>,
mut keeper_was_striker_once: Local<bool>,
) {
if time.ticks() == 2800 {
if let Some(ball) = ball.state.as_mut() {
ball.position = point![-3.8, 0.0];
}
}
if game_controller.state.game_state == GameState::Playing {
for robot in robots.iter() {
if robot.parameters.player_number == PlayerNumber::One
&& robot.database.main_outputs.role == Role::Striker
{
*keeper_was_striker_once = true;
}
}
}

if game_controller.state.hulks_team.score > 0 {
if !*keeper_was_striker_once {
println!("Error: Keeper never became striker");
exit.send(AppExit::from_code(2));
return;
}
println!("Done");
exit.send(AppExit::Success);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bevyhavior_simulator::{
use types::roles::Role;

#[scenario]
fn replacement_keeper_test(app: &mut App) {
fn replacement_keeper(app: &mut App) {
app.add_systems(Startup, startup);
app.add_systems(Update, update);
}
Expand Down
Loading