-
Notifications
You must be signed in to change notification settings - Fork 22
team_com disallowed robots to send messages if not intended, and reduces the rate if we get close to the budget end #805
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
Draft
cleWu03
wants to merge
4
commits into
main
Choose a base branch
from
team_com-message_budget-"emergency-stop"
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.
The head ref may contain hidden characters: "team_com-message_budget-\"emergency-stop\""
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
66 changes: 66 additions & 0 deletions
66
...ts_body_behavior/bitbots_body_behavior/behavior_dsd/decisions/number_penalized_players.py
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,66 @@ | ||
| from bitbots_blackboard.body_blackboard import BodyBlackboard | ||
| from dynamic_stack_decider.abstract_decision_element import AbstractDecisionElement | ||
| from game_controller_hsl_interfaces.msg import GameState | ||
|
|
||
|
|
||
| class NumberPenalizedTeamMates(AbstractDecisionElement): | ||
| blackboard: BodyBlackboard | ||
|
|
||
| def __init__(self, blackboard, dsd, parameters): | ||
| super().__init__(blackboard, dsd, parameters) | ||
|
|
||
| def perform(self, reevaluate=False): | ||
| """ | ||
| Return number of penalized team mates | ||
| :param reevaluate: | ||
| :return: | ||
| """ | ||
| game_state_penalized_team_mates = self.blackboard.gamestate.get_penalized_team_mates() | ||
|
|
||
| if game_state_penalized_team_mates == 4: | ||
| return "FOUR" | ||
| elif game_state_penalized_team_mates == 3: | ||
| return "THREE" | ||
| elif game_state_penalized_team_mates == 2: | ||
| return "TWO" | ||
| elif game_state_penalized_team_mates == 1: | ||
| return "ONE" | ||
| else: | ||
| return "ZERO" | ||
|
|
||
| def get_reevaluate(self): | ||
| """ | ||
| Game state can change during the game | ||
| """ | ||
| return True | ||
|
|
||
| class NumberPenalizedRivals(AbstractDecisionElement): | ||
| blackboard: BodyBlackboard | ||
|
|
||
| def __init__(self, blackboard, dsd, parameters): | ||
| super().__init__(blackboard, dsd, parameters) | ||
|
|
||
| def perform(self, reevaluate=False): | ||
| """ | ||
| Return number of penalized rivals | ||
| :param reevaluate: | ||
| :return: | ||
| """ | ||
| game_state_penalized_rivals = self.blackboard.gamestate.get_penalized_rivals() | ||
|
|
||
| if game_state_penalized_rivals == 4: | ||
| return "FOUR" | ||
| elif game_state_penalized_rivals == 3: | ||
| return "THREE" | ||
| elif game_state_penalized_rivals == 2: | ||
| return "TWO" | ||
| elif game_state_penalized_rivals == 1: | ||
| return "ONE" | ||
| else: | ||
| return "ZERO" | ||
|
|
||
| def get_reevaluate(self): | ||
| """ | ||
| Game state can change during the game | ||
| """ | ||
| return True |
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 |
|---|---|---|
|
|
@@ -50,8 +50,10 @@ def __init__(self): | |
| self.socket_communication = SocketCommunication(self.node, self.logger, self.team_id, self.player_id) | ||
|
|
||
| self.rate: int = self.node.get_parameter("rate").value | ||
| self.reduced_rate: int = self.node.get_parameter("reduced_rate").value | ||
| self.lifetime: int = self.node.get_parameter("lifetime").value | ||
| self.avg_walking_speed: float = self.node.get_parameter("avg_walking_speed").value | ||
| self.rate_is_reduced: bool = False | ||
|
|
||
| self.topics = get_parameter_dict(self.node, "topics") | ||
| self.map_frame: str = self.node.get_parameter("map_frame").value | ||
|
|
@@ -66,7 +68,7 @@ def __init__(self): | |
| self.run_spin_in_thread() | ||
| self.try_to_establish_connection() | ||
|
|
||
| self.node.create_timer(1 / self.rate, self.send_message, callback_group=MutuallyExclusiveCallbackGroup()) | ||
| self.create_timer(self.rate) | ||
| self.receive_forever() | ||
|
|
||
| def spin(self): | ||
|
|
@@ -263,6 +265,11 @@ def handle_message(self, string_message: bytes): | |
| self.team_data_publisher.publish(team_data) | ||
|
|
||
| def send_message(self): | ||
|
|
||
| if not self.rate_is_reduced: | ||
| if self.gamestate is not None and self.gamestate.secs_remaining > 180 and (self.gamestate.message_budget / self.gamestate.secs_remaining) < 11.2: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this logic to a method Please add some reasoning for the magic values. |
||
| self.reduce_rate() | ||
|
|
||
| if not self.is_robot_allowed_to_send_message(): | ||
| self.logger.debug("Robot is not allowed to send message") | ||
| return | ||
|
|
@@ -301,7 +308,15 @@ def should_message_be_discarded(self, message: Proto.Message) -> bool: | |
| return is_own_message or is_message_from_oposite_team | ||
|
|
||
| def is_robot_allowed_to_send_message(self) -> bool: | ||
| return self.gamestate is not None and not self.gamestate.penalized | ||
| #a penalized robot doesn't need to publish | ||
| if self.gamestate is not None and not self.gamestate.penalized: | ||
| return False | ||
| #if we are close to our message budget, we dont want to continue publishing | ||
| #the budget smaller 40 as stop definition makes sure we have 10 msg per robot left in case of some delay in the communication with the game controller | ||
| if self.gamestate is not None and (self.gamestate.message_budget < 40): | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| def get_current_time(self) -> Time: | ||
| return self.node.get_clock().now() | ||
|
|
@@ -313,7 +328,29 @@ def extract_orientation_yaw_angle(self, quaternion: Quaternion): | |
|
|
||
| def convert_to_euler(self, quaternion: Quaternion): | ||
| return transforms3d.euler.quat2euler([quaternion.w, quaternion.x, quaternion.y, quaternion.z]) | ||
|
|
||
|
|
||
| def reduce_rate(self): | ||
| self.timer.cancel() | ||
| self.create_timer(self.reduced_rate) | ||
| self.rate_is_reduced = True | ||
| self.logger.warning("Team communication: message sending rate is reduced now") | ||
|
|
||
| def create_timer(self, rate: int): | ||
| self.timer = self.node.create_timer(1 / rate, self.send_message, callback_group=MutuallyExclusiveCallbackGroup()) | ||
|
|
||
| def should_reduce_rate(self): | ||
| # we are allowed to send 2.5 msg per second on average with each robot (12000 with 4 robots in a 1200 sekonds game) | ||
| # the msg_left_linear_rate is the amount of messages we would send if we send exactly with this 2.5 msg per sec per robot rate | ||
| # once our actual msg budget is below this linear rate we tend to send more msg then allowed and should reduce our sending rate | ||
| if self.game_started_recently(): | ||
| return False | ||
|
|
||
| msg_left_linear_rate = (self.gamestate.first_half * 600 + self.gamestate.secs_remaining) * 4 * 2.5 | ||
| return msg_left_linear_rate > self.gamestate.message_budget | ||
|
|
||
| def game_started_recently(self): | ||
| #true in the first 60 seconds of the game | ||
| return self.gamestate.first_half and self.gamestate.secs_remaining > 540 | ||
|
|
||
| def main(): | ||
| rclpy.init(args=None) | ||
|
|
||
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
Oops, something went wrong.
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.
Please add a parameter
reduced_rateand use that instead of hardcoded 1