-
Notifications
You must be signed in to change notification settings - Fork 0
Visual referee messages sending with RNG handsignal #116
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
L-Bolt
wants to merge
16
commits into
robocup-23
Choose a base branch
from
lbolt/rng_visref_from_robocop-23
base: robocup-23
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 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
52218ba
rng with robocup-23
b0c7072
rng with robocup-23
b361e20
rng with robocup-23
56ed8e3
rng with robocup-23
26d51d4
messages with bifrost
583e7c5
Merge remote-tracking branch 'origin/robocup-23' into lbolt/rng_visre…
3000c93
log print
83e2acd
ugly fix
ef3f6d9
removed unused code
a99cfb5
cargo fmt
e8a95ca
removed double code
25f9be0
removed unused dependencies
34544d6
fixed duration
f948268
removed unused import
728039a
use context start time
88ed7bc
removed bool
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,83 @@ | ||
| use color_eyre::{eyre::WrapErr, Result}; | ||
| use context_attribute::context; | ||
| use nalgebra::Isometry2; | ||
| use rand::Rng; | ||
| use spl_network_messages::{PlayerNumber, RefereeMessage}; | ||
| use std::time::{SystemTime}; | ||
| use types::{hardware::Interface, messages::OutgoingMessage, CycleTime, FilteredWhistle}; | ||
|
|
||
| pub struct Referee { | ||
| last_heard_timestamp: Option<SystemTime>, | ||
| first: bool, | ||
| } | ||
|
|
||
| #[context] | ||
| pub struct CreationContext { | ||
| pub player_number: Parameter<PlayerNumber, "player_number">, | ||
| } | ||
|
|
||
| #[context] | ||
| pub struct CycleContext { | ||
| pub filtered_whistle: Input<FilteredWhistle, "filtered_whistle">, | ||
| pub hardware: HardwareInterface, | ||
| pub cycle_time: Input<CycleTime, "cycle_time">, | ||
| pub player_number: Parameter<PlayerNumber, "player_number">, | ||
| pub robot_to_field: Input<Option<Isometry2<f32>>, "robot_to_field?">, | ||
| } | ||
|
|
||
| impl Referee { | ||
| pub fn new(_context: CreationContext) -> Result<Self> { | ||
| Ok(Self { | ||
| last_heard_timestamp: None, | ||
| first: true, | ||
| }) | ||
| } | ||
|
|
||
| pub fn cycle(&mut self, context: CycleContext<impl Interface>) -> Result<()> { | ||
| if context.filtered_whistle.started_this_cycle { | ||
| if self.first { | ||
| self.send_referee_message(&context, 0.0)?; | ||
| self.first = false; | ||
| } else if let Some(cycle_time) = self.last_heard_timestamp { | ||
| match context.cycle_time.start_time.duration_since(cycle_time) { | ||
| Ok(duration) => { | ||
| if duration.as_secs() > 20 { | ||
| self.send_referee_message(&context, duration.as_secs_f32())?; | ||
| } | ||
| } | ||
| Err(_err) => {} | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn send_referee_message( | ||
| &mut self, | ||
| context: &CycleContext<impl Interface>, | ||
| duration: f32, | ||
| ) -> Result<()> { | ||
| let mut rng_gen = rand::thread_rng(); | ||
| self.last_heard_timestamp = Some(SystemTime::now()); | ||
| let handsignal: u8 = rng_gen.gen_range(1..=16); | ||
|
|
||
| context | ||
| .hardware | ||
| .write_to_network(OutgoingMessage::RefereeReturnData(RefereeMessage { | ||
| header: [82, 71, 114, 116], | ||
| version: 255, | ||
| player_num: *context.player_number as u8, | ||
| team_num: 8, | ||
| fallen: handsignal, | ||
| pose: [0.0, 0.0, 0.0], | ||
| ball_age: duration, | ||
| ball: [0.0, 0.0], | ||
| })) | ||
| .wrap_err("failed to write RefereeMessage to hardware")?; | ||
|
|
||
| println!("sent referee handsignal message"); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
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,65 @@ | ||
| use bifrost::serialization::Encode; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Encode, Debug, Clone, Deserialize, Serialize)] | ||
| pub struct RefereeMessage { | ||
| /// "RGrt" | ||
| pub header: [u8; 4], | ||
|
|
||
| /// Has to be set to GAMECONTROLLER_RETURN_STRUCT_VERSION | ||
| pub version: u8, | ||
|
|
||
| /// Player number starts with 1 | ||
| pub player_num: u8, | ||
|
|
||
| /// Team number | ||
| pub team_num: u8, | ||
|
|
||
| /// 1 means that the robot is fallen, 0 means that the robot can play | ||
| pub fallen: u8, | ||
|
|
||
| /// Position and orientation of the robot | ||
| /// | ||
| /// coordinates in millimeters | ||
| /// 0,0 is in center of field | ||
| /// +ve x-axis points towards the goal we are attempting to score on | ||
| /// +ve y-axis is 90 degrees counter clockwise from the +ve x-axis | ||
| /// angle in radians, 0 along the +x axis, increasing counter clockwise | ||
| pub pose: [f32; 3], // x,y,theta | ||
|
|
||
| /// ball information | ||
| pub ball_age: f32, // seconds since this robot last saw the ball. -1.f if we haven't seen it | ||
|
|
||
| /// Position of ball relative to the robot | ||
| /// | ||
| /// coordinates in millimeters | ||
| /// 0,0 is in center of the robot | ||
| /// +ve x-axis points forward from the robot | ||
| /// +ve y-axis is 90 degrees counter clockwise from the +ve x-axis | ||
| pub ball: [f32; 2], | ||
| } | ||
|
|
||
| impl RefereeMessage { | ||
| /// Construct a new [`RoboCupGameControlReturnData`] using the specified arguments. | ||
| pub fn new( | ||
| header: [u8; 4], | ||
| version: u8, | ||
| player_num: u8, | ||
| team_num: u8, | ||
| fallen: u8, | ||
| pose: [f32; 3], | ||
| ball_age: f32, | ||
| ball: [f32; 2], | ||
| ) -> Self { | ||
| Self { | ||
| header, | ||
| version, | ||
| player_num, | ||
| team_num, | ||
| fallen, | ||
| pose, | ||
| ball_age, | ||
| 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
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 |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| { | ||
| "walking_engine": { | ||
| "base_foot_lift": 0.012500000186264517, | ||
| "walk_hip_height": 0.16500000655651093 | ||
| }, | ||
| "camera_matrix_parameters": { | ||
| "vision_top": { | ||
| "extrinsic_rotations": [ | ||
| 1.2699999809265137, -3.359999895095825, 0.2199999988079071 | ||
| 1.2699999809265137, | ||
| -3.359999895095825, | ||
| 0.2199999988079071 | ||
| ] | ||
| } | ||
| }, | ||
| "disable_communication_acceptor": true, | ||
| "player_number": "Three", | ||
| "walking_engine": { | ||
| "base_foot_lift": 0.012500000186264517, | ||
| "walk_hip_height": 0.16500000655651093 | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -7,5 +7,6 @@ | |
| 1.3600000143051147 | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "player_number": "Two" | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bool is probably not necessary.