-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce ball communication #589
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
Open
marinaog
wants to merge
53
commits into
main
Choose a base branch
from
marinita/final_ball_communication
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
bb7b1f5
Added ball communication (global and local coordinates still need to …
marinaog 06d696c
Transformation local<->global coordinates added
marinaog 577b56c
Typo fixed
marinaog 89037d8
fromat
juliablbr 9bc628a
should be fine eh
juliablbr b32b8d4
shut up clippy
juliablbr 4720f6b
weeeee
juliablbr 0ae3e2a
save ball position
oxkitsune e8a337f
stuff
oxkitsune 3bff0f8
fixing clippy
marinaog 612106b
merging conflict
marinaog c0985d0
Merge branch 'main' into marinita/final_ball_communication
marinaog 460e64e
clippy me this one
marinaog cc7e7c4
Merge branch 'marinita/final_ball_communication' of https://github.co…
marinaog 089fcd6
Removed print check
marinaog 327454c
cargo fmt doesnt forgive
marinaog ea2f4d8
Merge branch 'main' into marinita/final_ball_communication
juellsprott 3840eb4
Merge branch 'main' into marinita/final_ball_communication
juellsprott 41e33b6
timeout team ball after constant amount of cycles without communicate…
juellsprott b529862
formatting
juellsprott 44a12b6
remove print statements
juellsprott 9531ff9
test balltracker crate addition
juellsprott 4e40ac8
remove balltracker import
juellsprott 0a2e8ad
change team ball to detected ball in striker.rs
juellsprott 305eb26
Merge branch 'main' into marinita/final_ball_communication
juellsprott 0ca9331
fix striker.rs not being merged with main
juellsprott 51712e6
remove cycle time thresholding on communicated ball message age
juellsprott 7adc8a7
merge with main
juellsprott 0cf29bc
fix imports
juellsprott aabf91f
rebase
juellsprott 4af0a6b
Transformation local<->global coordinates added
marinaog 28d86fe
Typo fixed
marinaog 78e71bb
fromat
juliablbr 305890e
rebase
juellsprott f95a6a8
shut up clippy
juliablbr 00f00a7
weeeee
juliablbr 8dc9874
rebase
juellsprott af83206
stuff
oxkitsune be600c8
fixing clippy
marinaog 49de75e
merging conflict
marinaog f83d0bc
clippy me this one
marinaog b1be802
Removed print check
marinaog 1354800
cargo fmt doesnt forgive
marinaog 05a4c42
timeout team ball after constant amount of cycles without communicate…
juellsprott c7cc8e8
formatting
juellsprott e994c17
remove print statements
juellsprott a3a1110
test balltracker crate addition
juellsprott 9ac7140
change team ball to detected ball in striker.rs
juellsprott b401e97
fix striker.rs not being merged with main
juellsprott 130a91f
remove cycle time thresholding on communicated ball message age
juellsprott f380c44
fix imports
juellsprott eb3bcc9
rebase
juellsprott 6d13614
rebase
juellsprott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| use bevy::prelude::*; | ||
| use nalgebra::{self as na, Point2}; | ||
|
|
||
| use crate::{ | ||
| communication::{TeamCommunication, TeamMessage}, | ||
| core::debug::DebugContext, | ||
| localization::RobotPose, | ||
| nao::Cycle, | ||
| }; | ||
|
|
||
| // Import camera proposals | ||
| use super::ball_tracker::BallTracker; | ||
|
|
||
| // Constant for the minimum acceptable change | ||
| const MIN_CHANGE: f32 = 0.1; | ||
|
|
||
| pub struct CommunicatedBallsPlugin; | ||
|
|
||
| impl Plugin for CommunicatedBallsPlugin { | ||
| fn build(&self, app: &mut App) { | ||
| app.init_resource::<TeamBallPosition>() | ||
| .init_resource::<CommunicatedBalls>() | ||
| .add_systems(Update, communicate_balls_system); | ||
| } | ||
| } | ||
|
|
||
| #[derive(Resource, Default, Debug)] | ||
| pub struct TeamBallPosition(pub Option<Point2<f32>>); | ||
|
|
||
| #[derive(Resource, Debug, Default)] | ||
| pub struct CommunicatedBalls { | ||
| /// For keeping track what position we've sent out. | ||
| sent: Option<na::Point2<f32>>, | ||
| } | ||
|
|
||
| impl CommunicatedBalls { | ||
| /// Check it the position has changed enough from last frame. | ||
| fn change_enough(&mut self, ball: Option<&na::Point2<f32>>) -> bool { | ||
| match (ball, &self.sent) { | ||
| (None, None) => false, | ||
| (None, Some(_)) => true, | ||
| (Some(_), None) => true, | ||
| (Some(old), Some(new)) => na::distance(old, new) > MIN_CHANGE, | ||
| } | ||
| } | ||
|
|
||
| /// Send your ball position (even if it's None) as a message. | ||
| fn send_message(&mut self, ball_position: Option<na::Point2<f32>>, tc: &mut TeamCommunication) { | ||
| tc.outbound_mut() | ||
| .update_or_push(TeamMessage::DetectedBall(ball_position)) | ||
| .expect("Unable to encode detected ball"); | ||
| self.sent = ball_position; | ||
| } | ||
|
|
||
| /// Receive messages. | ||
| // 2.A.a. If no other robot are detecting a ball, we return the same None we had | ||
| // 2.A.b. If there are other robots detecting a ball, we take one from theirs as our own. | ||
| fn receive_messages( | ||
| comms: &mut TeamCommunication, | ||
| pose: &RobotPose, | ||
| ) -> Option<na::Point2<f32>> { | ||
| let mut received_ball = None; | ||
|
|
||
| while let Some((_, _, ball)) = comms.inbound_mut().take_map(|_, _, what| match what { | ||
| TeamMessage::DetectedBall(ball) => Some(*ball), | ||
| _ => None, | ||
| }) { | ||
| received_ball = received_ball.or(ball); | ||
| } | ||
| // If we received a ball, transform it from world coordinates to robot coordinates | ||
| received_ball.map(|ball| pose.world_to_robot(&ball)) | ||
| } | ||
| } | ||
|
|
||
| #[allow(clippy::too_many_arguments)] | ||
| fn communicate_balls_system( | ||
| mut communicated_balls: ResMut<CommunicatedBalls>, | ||
| mut tc: ResMut<TeamCommunication>, | ||
| ball_tracker: Res<BallTracker>, | ||
| mut team_ball_position: ResMut<TeamBallPosition>, | ||
| pose: Res<RobotPose>, | ||
| mut last_received: Local<Option<Point2<f32>>>, | ||
| ctx: DebugContext, | ||
| cycle: Res<Cycle>, | ||
| ) { | ||
| let optional_ball_position = ball_tracker.stationary_ball(); | ||
|
|
||
| // 1. Check if it has changed enough and if so, we send a message. | ||
| // let optional_ball_position = ball_position.map(|ball_position| ball_position.0); | ||
| if communicated_balls.change_enough(optional_ball_position.as_ref()) { | ||
| let transformed_position = optional_ball_position.map(|pos| pose.robot_to_world(&pos)); | ||
| communicated_balls.send_message(transformed_position, &mut tc); | ||
| } | ||
|
|
||
| if let Some(new_pos) = CommunicatedBalls::receive_messages(&mut tc, &pose) { | ||
| *last_received = Some(new_pos); | ||
| } | ||
|
|
||
| team_ball_position.0 = optional_ball_position.or_else(|| *last_received); | ||
|
|
||
| if let Some(pos) = team_ball_position.0 { | ||
| let global = pose.robot_to_world(&pos); | ||
| ctx.log_with_cycle( | ||
| "/team_ball", | ||
| *cycle, | ||
| &rerun::Points3D::new([(global.x, global.y, 0.01)]) | ||
| .with_radii([0.1]) | ||
| .with_labels(["team_ball"]), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.